2023-04-05 22:06:49 +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 HeadwaiterStorage : IHeadwaiterStorage
|
|
|
|
|
{
|
|
|
|
|
public HeadwaiterViewModel? Delete(HeadwaiterBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
var element = context.Headwaiters.FirstOrDefault(rec => rec.Id == model.Id);
|
|
|
|
|
|
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
|
|
|
|
context.Headwaiters.Remove(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HeadwaiterViewModel? GetElement(HeadwaiterSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
if (model.Id.HasValue)
|
|
|
|
|
return context.Headwaiters
|
|
|
|
|
.Include(x => x.ConferenceBookings)
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.Include(x => x.Rooms)
|
|
|
|
|
.FirstOrDefault(x => x.Id == model.Id)?
|
|
|
|
|
.GetViewModel;
|
|
|
|
|
|
2023-05-16 01:11:49 +04:00
|
|
|
|
if (!string.IsNullOrEmpty(model.HeadwaiterEmail) && !string.IsNullOrEmpty(model.HeadwaiterPassword))
|
2023-04-05 22:06:49 +04:00
|
|
|
|
return context.Headwaiters
|
|
|
|
|
.Include(x => x.ConferenceBookings)
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.Include(x => x.Rooms)
|
2023-05-16 01:11:49 +04:00
|
|
|
|
.FirstOrDefault(x => x.HeadwaiterEmail.Equals(model.HeadwaiterEmail) && x.HeadwaiterPassword.Equals(model.HeadwaiterPassword))?
|
2023-04-05 22:06:49 +04:00
|
|
|
|
.GetViewModel;
|
|
|
|
|
|
2023-05-16 01:11:49 +04:00
|
|
|
|
if (!string.IsNullOrEmpty(model.HeadwaiterEmail))
|
2023-04-05 22:06:49 +04:00
|
|
|
|
return context.Headwaiters
|
|
|
|
|
.Include(x => x.ConferenceBookings)
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.Include(x => x.Rooms)
|
2023-05-16 01:11:49 +04:00
|
|
|
|
.FirstOrDefault(x => x.HeadwaiterEmail.Equals(model.HeadwaiterEmail))?
|
2023-04-05 22:06:49 +04:00
|
|
|
|
.GetViewModel;
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<HeadwaiterViewModel> GetFilteredList(HeadwaiterSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(model.HeadwaiterFIO))
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
return context.Headwaiters
|
|
|
|
|
.Include(x => x.ConferenceBookings)
|
|
|
|
|
.Include(x => x.Dinners)
|
|
|
|
|
.Include(x => x.Rooms)
|
|
|
|
|
.Where(x => x.HeadwaiterLogin.Contains(model.HeadwaiterLogin) && x.HeadwaiterPassword == model.HeadwaiterPassword)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<HeadwaiterViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
return context.Headwaiters
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HeadwaiterViewModel? Insert(HeadwaiterBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var newHeadwaiter = Headwaiter.Create(model);
|
|
|
|
|
|
|
|
|
|
if (newHeadwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
context.Headwaiters.Add(newHeadwaiter);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return newHeadwaiter.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HeadwaiterViewModel? Update(HeadwaiterBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
var headwaiter = context.Headwaiters
|
|
|
|
|
.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
|
|
|
|
|
if (headwaiter == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
headwaiter.Update(model);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return headwaiter.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|