2023-04-06 00:38:46 +04:00
|
|
|
|
using HotelContracts.BindingModels;
|
|
|
|
|
using HotelContracts.SearchModels;
|
|
|
|
|
using HotelContracts.StoragesContracts;
|
|
|
|
|
using HotelContracts.ViewModels;
|
|
|
|
|
using HotelDataBaseImplement.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace HotelDataBaseImplement.Implemets
|
|
|
|
|
{
|
|
|
|
|
public class RoomStorage : IRoomStorage
|
|
|
|
|
{
|
|
|
|
|
public RoomViewModel? Delete(RoomBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
var element = context.Rooms
|
|
|
|
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
|
|
|
|
|
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
|
|
|
|
context.Rooms.Remove(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RoomViewModel? GetElement(RoomSearchModel model)
|
|
|
|
|
{
|
2023-05-16 01:11:49 +04:00
|
|
|
|
if (!model.Id.HasValue && !model.HeadwaiterId.HasValue)
|
2023-04-06 00:38:46 +04:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
2023-05-16 01:11:49 +04:00
|
|
|
|
if (model.HeadwaiterId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return context.Rooms
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
2023-05-16 18:11:10 +04:00
|
|
|
|
.ThenInclude(x => x.ConferenceBookingDinner)
|
2023-05-16 01:11:49 +04:00
|
|
|
|
.ThenInclude(x => x.ConferenceBooking)
|
|
|
|
|
.Include(x => x.MealPlan)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
|
|
|
|
|
.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-06 00:38:46 +04:00
|
|
|
|
return context.Rooms
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
2023-05-16 18:11:10 +04:00
|
|
|
|
.ThenInclude(x => x.ConferenceBookingDinner)
|
2023-04-06 00:38:46 +04:00
|
|
|
|
.ThenInclude(x => x.ConferenceBooking)
|
|
|
|
|
.Include(x => x.MealPlan)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
|
|
|
|
|
.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<RoomViewModel> GetFilteredList(RoomSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(model.RoomName))
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
return context.Rooms
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
2023-05-16 18:11:10 +04:00
|
|
|
|
.ThenInclude(x => x.ConferenceBookingDinner)
|
2023-04-06 00:38:46 +04:00
|
|
|
|
.ThenInclude(x => x.ConferenceBooking)
|
|
|
|
|
.Include(x => x.MealPlan)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.Where(x => x.RoomName.Contains(model.RoomName))
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<RoomViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
return context.Rooms
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
2023-05-16 18:11:10 +04:00
|
|
|
|
.ThenInclude(x => x.ConferenceBookingDinner)
|
2023-04-06 00:38:46 +04:00
|
|
|
|
.ThenInclude(x => x.ConferenceBooking)
|
|
|
|
|
.Include(x => x.MealPlan)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RoomViewModel? Insert(RoomBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
var newRoom = Room.Create(context, model);
|
|
|
|
|
|
|
|
|
|
if (newRoom == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Rooms.Add(newRoom);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return newRoom.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RoomViewModel? Update(RoomBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
var room = context.Rooms.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
if (room == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
room.Update(model);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return room.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|