72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
using System.ComponentModel.DataAnnotations.Schema;
|
|
using HotelContracts.BindingModels;
|
|
using HotelContracts.ViewModels;
|
|
using HotelDataModels.Models;
|
|
|
|
namespace HotelDatabaseImplement.Models;
|
|
|
|
public class Room : IRoomModel
|
|
{
|
|
public int Id { get; set; }
|
|
public string Type { get; set; } = string.Empty;
|
|
public double Cost { get; set; }
|
|
public bool IsReserved { get; set; }
|
|
|
|
[ForeignKey("RoomId")]
|
|
public virtual List<ReservationRoom> Reservation { get; set; } = new();
|
|
|
|
private Dictionary<int, IReservationModel>? _reservationsRooms = null;
|
|
public Dictionary<int, IReservationModel> ReservationsRooms
|
|
{
|
|
get
|
|
{
|
|
_reservationsRooms ??= Reservation
|
|
.ToDictionary(record => record.ReservationId,
|
|
room => room.Reservation as IReservationModel);
|
|
return _reservationsRooms;
|
|
}
|
|
}
|
|
|
|
public static Room? Create(RoomBindingModel? model)
|
|
{
|
|
if (model == null) return null;
|
|
return new Room
|
|
{
|
|
Id = model.Id,
|
|
Type = model.Type,
|
|
Cost = model.Cost
|
|
};
|
|
}
|
|
|
|
public static Room Create(RoomViewModel model)
|
|
{
|
|
return new Room
|
|
{
|
|
Id = model.Id,
|
|
Type = model.Type,
|
|
Cost = model.Cost
|
|
};
|
|
}
|
|
|
|
public void Update(RoomBindingModel? model)
|
|
{
|
|
if (model == null) return;
|
|
Type = model.Type;
|
|
Cost = model.Cost;
|
|
IsReserved = model.IsReserved;
|
|
}
|
|
|
|
public void CheckReservations()
|
|
{
|
|
IsReserved = ReservationsRooms.Any(x => x.Value.EndDate > DateTime.Now);
|
|
}
|
|
|
|
public RoomViewModel GetView => new RoomViewModel
|
|
{
|
|
Id = Id,
|
|
Type = Type,
|
|
Cost = Cost,
|
|
Reservation = ReservationsRooms,
|
|
IsReserved = IsReserved
|
|
};
|
|
} |