69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
|
using HotelContracts.BindingModels;
|
|||
|
using HotelContracts.SearchModels;
|
|||
|
using HotelContracts.StoragesContracts;
|
|||
|
using HotelContracts.ViewModels;
|
|||
|
using HotelDatabaseImplement.Models;
|
|||
|
|
|||
|
namespace HotelDatabaseImplement.Implements;
|
|||
|
|
|||
|
public class CleaningStorage : ICleaningStorage
|
|||
|
{
|
|||
|
public List<CleaningViewModel> GetFullList()
|
|||
|
{
|
|||
|
using var context = new HotelDataBase();
|
|||
|
return context.Cleanings
|
|||
|
.Select(x => x.GetView)
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
|
|||
|
public List<CleaningViewModel> GetFilteredList(CleaningSearchModel model)
|
|||
|
{
|
|||
|
if (!model.To.HasValue || !model.From.HasValue)
|
|||
|
return new List<CleaningViewModel>();
|
|||
|
|
|||
|
using var context = new HotelDataBase();
|
|||
|
return context.Cleanings
|
|||
|
.Where(x => x.Date >= model.From && x.Date <= model.To)
|
|||
|
.Select(x => x.GetView)
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
|
|||
|
public CleaningViewModel? GetElement(CleaningSearchModel model)
|
|||
|
{
|
|||
|
if (!model.Id.HasValue) return null;
|
|||
|
using var context = new HotelDataBase();
|
|||
|
return context.Cleanings.FirstOrDefault(x => x.Id == model.Id)?.GetView;
|
|||
|
}
|
|||
|
|
|||
|
public CleaningViewModel? Insert(CleaningBindingModel model)
|
|||
|
{
|
|||
|
using var context = new HotelDataBase();
|
|||
|
var item = Cleaning.Create(context, model);
|
|||
|
|
|||
|
context.Cleanings.Add(item);
|
|||
|
context.SaveChanges();
|
|||
|
|
|||
|
return item.GetView;
|
|||
|
}
|
|||
|
|
|||
|
public CleaningViewModel? Update(CleaningBindingModel model)
|
|||
|
{
|
|||
|
using var context = new HotelDataBase();
|
|||
|
var item = context.Cleanings.FirstOrDefault(x => x.Id == model.Id);
|
|||
|
if (item == null) return null;
|
|||
|
|
|||
|
item.Update(model);
|
|||
|
context.SaveChanges();
|
|||
|
return item.GetView;
|
|||
|
}
|
|||
|
|
|||
|
public CleaningViewModel? Delete(CleaningBindingModel model)
|
|||
|
{
|
|||
|
using var context = new HotelDataBase();
|
|||
|
var item = context.Cleanings.FirstOrDefault(x => x.Id == model.Id);
|
|||
|
if (item == null) return null;
|
|||
|
context.Cleanings.Remove(item);
|
|||
|
context.SaveChanges();
|
|||
|
return item.GetView;
|
|||
|
}
|
|||
|
}
|