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 ConferenceBookingStorage : IConferenceBookingStorage
|
|
|
|
|
{
|
|
|
|
|
public ConferenceBookingViewModel? Delete(ConferenceBookingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
var element = context.ConferenceBookings
|
|
|
|
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
|
|
|
|
|
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
|
|
|
|
context.ConferenceBookings.Remove(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ConferenceBookingViewModel? GetElement(ConferenceBookingSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (!model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
return context.ConferenceBookings
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
|
|
|
|
.ThenInclude(x => x.RoomDinners)
|
|
|
|
|
.ThenInclude(x => x.Room)
|
|
|
|
|
.Include(x => x.Conference)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
|
|
|
|
|
.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ConferenceBookingViewModel> GetFilteredList(ConferenceBookingSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.HeadwaiterId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
if (model.DateFrom.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return context.ConferenceBookings
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
|
|
|
|
.ThenInclude(x => x.RoomDinners)
|
|
|
|
|
.ThenInclude(x => x.Room)
|
|
|
|
|
.Include(x => x.Conference)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
2023-04-06 00:43:29 +04:00
|
|
|
|
.Where(x => x.Conference.StartDate >= model.DateFrom && x.Conference.StartDate <= model.DateTo)
|
2023-04-06 00:38:46 +04:00
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
else if (model.HeadwaiterId.HasValue)
|
|
|
|
|
return context.ConferenceBookings
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
|
|
|
|
.ThenInclude(x => x.RoomDinners)
|
|
|
|
|
.ThenInclude(x => x.Room)
|
|
|
|
|
.Include(x => x.Conference)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.Where(x => x.HeadwaiterId == model.HeadwaiterId)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
return context.ConferenceBookings
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
|
|
|
|
.ThenInclude(x => x.RoomDinners)
|
|
|
|
|
.ThenInclude(x => x.Room)
|
|
|
|
|
.Include(x => x.Conference)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.Where(x => x.Id == model.Id)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ConferenceBookingViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
return context.ConferenceBookings
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
|
|
|
|
.ThenInclude(x => x.RoomDinners)
|
|
|
|
|
.ThenInclude(x => x.Room)
|
|
|
|
|
.Include(x => x.Conference)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ConferenceBookingViewModel? Insert(ConferenceBookingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
var newConferenceBooking = ConferenceBooking.Create(context, model);
|
|
|
|
|
|
|
|
|
|
if (newConferenceBooking == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.ConferenceBookings.Add(newConferenceBooking);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return context.ConferenceBookings
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
|
|
|
|
.ThenInclude(x => x.RoomDinners)
|
|
|
|
|
.ThenInclude(x => x.Room)
|
|
|
|
|
.Include(x => x.Conference)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.FirstOrDefault(x => x.Id == newConferenceBooking.Id)
|
|
|
|
|
?.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ConferenceBookingViewModel? Update(ConferenceBookingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
2023-04-06 00:43:29 +04:00
|
|
|
|
var conferenceBooking = context.ConferenceBookings
|
2023-04-06 00:38:46 +04:00
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.ThenInclude(x => x.Dinner)
|
|
|
|
|
.ThenInclude(x => x.RoomDinners)
|
|
|
|
|
.ThenInclude(x => x.Room)
|
|
|
|
|
.Include(x => x.Conference)
|
|
|
|
|
.Include(x => x.Headwaiter)
|
|
|
|
|
.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
|
2023-04-06 00:43:29 +04:00
|
|
|
|
if (conferenceBooking == null)
|
2023-04-06 00:38:46 +04:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-06 00:43:29 +04:00
|
|
|
|
conferenceBooking.Update(model);
|
2023-04-06 00:38:46 +04:00
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
2023-04-06 00:43:29 +04:00
|
|
|
|
return conferenceBooking.GetViewModel;
|
2023-04-06 00:38:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|