2023-04-02 14:32:57 +04:00
|
|
|
|
using HotelContracts.BindingModels;
|
|
|
|
|
using HotelContracts.SearchModels;
|
|
|
|
|
using HotelContracts.StoragesContracts;
|
|
|
|
|
using HotelContracts.ViewModels;
|
2023-04-05 23:31:18 +04:00
|
|
|
|
using HotelDataBaseImplement.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-04-02 14:32:57 +04:00
|
|
|
|
|
|
|
|
|
namespace HotelDataBaseImplement.Implemets
|
|
|
|
|
{
|
|
|
|
|
public class MealPlanStorage : IMealPlanStorage
|
|
|
|
|
{
|
|
|
|
|
public MealPlanViewModel? Delete(MealPlanBindingModel model)
|
|
|
|
|
{
|
2023-04-05 23:31:18 +04:00
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
var element = context.MealPlans
|
|
|
|
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
|
|
|
|
|
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
|
|
|
|
context.MealPlans.Remove(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2023-04-02 14:32:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MealPlanViewModel? GetElement(MealPlanSearchModel model)
|
|
|
|
|
{
|
2023-04-05 23:31:18 +04:00
|
|
|
|
if (!model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
return context.MealPlans
|
|
|
|
|
.Include(x => x.Members)
|
|
|
|
|
.ThenInclude(x => x.Member)
|
|
|
|
|
.ThenInclude(x => x.ConferenceMember)
|
|
|
|
|
.ThenInclude(x => x.Conference)
|
|
|
|
|
.Include(x => x.Rooms)
|
|
|
|
|
.Include(x => x.Organiser)
|
|
|
|
|
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
|
|
|
|
|
.GetViewModel;
|
2023-04-02 14:32:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MealPlanViewModel> GetFilteredList(MealPlanSearchModel model)
|
|
|
|
|
{
|
2023-04-05 23:31:18 +04:00
|
|
|
|
if (string.IsNullOrEmpty(model.MealPlanName))
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
|
|
|
|
|
return context.MealPlans
|
|
|
|
|
.Include(x => x.Members)
|
|
|
|
|
.ThenInclude(x => x.Member)
|
|
|
|
|
.ThenInclude(x => x.ConferenceMember)
|
|
|
|
|
.ThenInclude(x => x.Conference)
|
|
|
|
|
.Include(x => x.Rooms)
|
|
|
|
|
.Include(x => x.Organiser)
|
|
|
|
|
.Where(x => x.MealPlanName.Contains(model.MealPlanName))
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
2023-04-02 14:32:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MealPlanViewModel> GetFullList()
|
|
|
|
|
{
|
2023-04-05 23:31:18 +04:00
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
return context.MealPlans
|
|
|
|
|
.Include(x => x.Members)
|
|
|
|
|
.ThenInclude(x => x.Member)
|
|
|
|
|
.ThenInclude(x => x.ConferenceMember)
|
|
|
|
|
.ThenInclude(x => x.Conference)
|
|
|
|
|
.Include(x => x.Rooms)
|
|
|
|
|
.Include(x => x.Organiser)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
2023-04-02 14:32:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MealPlanViewModel? Insert(MealPlanBindingModel model)
|
|
|
|
|
{
|
2023-04-05 23:31:18 +04:00
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
var newMealPlan = MealPlan.Create(context,model);
|
|
|
|
|
|
|
|
|
|
if (newMealPlan == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.MealPlans.Add(newMealPlan);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return newMealPlan.GetViewModel;
|
2023-04-02 14:32:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MealPlanViewModel? Update(MealPlanBindingModel model)
|
|
|
|
|
{
|
2023-04-05 23:31:18 +04:00
|
|
|
|
using var context = new HotelDataBase();
|
|
|
|
|
var mealPlan = context.MealPlans.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
if (mealPlan == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
mealPlan.Update(model);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return mealPlan.GetViewModel;
|
2023-04-02 14:32:57 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|