Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public GetTablesDto TableToTableDto(Table table)
{
Id = table.Id,
RestaurantId = table.RestaurantId,
NumberOfSeats = table.NumberOfSeats
NumberOfSeats = table.NumberOfSeats,
Bookings = table.Bookings
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public BookingRepository(TableBookingContext context) : base(context)

public async Task<IEnumerable<Booking>> GetAllBookingsForSpecificUserAsync(Guid userId)
{
return await _objectSet.Where(x => x.Id.Equals(userId)).ToListAsync();
return await _objectSet.Where(x => x.AppUserId.Equals(userId)).ToListAsync();
}

public async Task<Booking?> GetBookingByIdForSpecificUserAsync(Guid bookingId, Guid userId)
{
return await _objectSet.FirstOrDefaultAsync(x => x.Id.Equals(bookingId) && x.Id.Equals(userId));
return await _objectSet.FirstOrDefaultAsync(x => x.Id.Equals(bookingId) && x.AppUserId.Equals(userId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ public async Task Delete(object id)
_objectSet.Remove(objectToDelete);
}

public async virtual Task Update(T entity)
public async Task Update(T entity)
{
await Update(entity);
}
var existingEntity = await _objectSet.FindAsync(GetKeyValues(entity));

if (existingEntity != null)
{
_context.Entry(existingEntity).State = EntityState.Detached;
}

_objectSet.Update(entity);
}

private object[] GetKeyValues(T entity)
{
var keyProperties = _context.Model.FindEntityType(typeof(T)).FindPrimaryKey().Properties;
return keyProperties.Select(prop => prop.PropertyInfo.GetValue(entity)).ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public TableRepository(TableBookingContext context) : base(context)
public async Task<IEnumerable<Table>> GetTablesByRestaurantIdAsync(Guid restaurantId)
{
return await _objectSet
.Include(x => x.RestaurantId)
.Include(x => x.Restaurant)
.Where(x => x.RestaurantId.Equals(restaurantId))
.ToListAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class BookingDto
public Guid Id { get; set; }
public DateTime Date { get; set; }
public int DurationInMinutes { get; set; }
public TableDto TableDto { get; set; }
public Guid UserId { get; set; }
public int AmountOfPeople { get; set; }
public Guid AppUserId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace TableBooking.Model.Dtos.BookingDtos
using TableBooking.Model.Models;

namespace TableBooking.Model.Dtos.BookingDtos
{
public class CreateBookingDto
{
public DateTime Date { get; set; }
public int DurationInMinutes { get; set; }
public Guid TableId { get; set; }
public int AmountOfPeople { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class UpdateBookingDto
{
public DateTime Date { get; set; }
public int DurationInMinutes { get; set; }
public Guid TableId { get; set; }
public int AmountOfPeople { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class RestaurantShortInfoDto
public string Name { get; set; }
public string Type { get; set; }
public string Description { get; set; }
public string Phone { get; set; }
public string Location { get; set; }
public string ImageURL { get; set; }
public int Rating { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace TableBooking.Model.Dtos.TableDtos
using TableBooking.Model.Models;

namespace TableBooking.Model.Dtos.TableDtos
{
public class GetTablesDto
{
public Guid Id { get; set; }
public int NumberOfSeats { get; set; }
public Guid RestaurantId { get; set; }
public IEnumerable<Booking>? Bookings { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TableBooking.Model.Dtos.TableDtos
{
public class TableDto : Entity
public class TableDto
{
public int NumberOfSeats { get; set; }
public Guid RestaurantId { get; set; }
Expand Down
Loading