72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using HotelContracts.BindingModels;
|
|
using HotelContracts.SearchModels;
|
|
using HotelContracts.StoragesContracts;
|
|
using HotelContracts.ViewModels;
|
|
using HotelDatabaseImplement.Models;
|
|
|
|
namespace HotelDatabaseImplement.Implements;
|
|
|
|
public class CleaningInstrumentsStorage : ICleaningInstrumentsStorage
|
|
{
|
|
public List<CleaningInstrumentsViewModel> GetFullList()
|
|
{
|
|
using var context = new HotelDataBase();
|
|
return context.CleaningInstruments
|
|
.Select(x => x.GetView)
|
|
.ToList();
|
|
}
|
|
|
|
public List<CleaningInstrumentsViewModel> GetFilteredList(CleaningInstrumentsSearchModel model)
|
|
{
|
|
if (string.IsNullOrEmpty(model.Type))
|
|
{
|
|
return new List<CleaningInstrumentsViewModel>();
|
|
}
|
|
using var context = new HotelDataBase();
|
|
return context.CleaningInstruments
|
|
.Where(x => x.Type == model.Type)
|
|
.Select(x => x.GetView)
|
|
.ToList();
|
|
}
|
|
|
|
public CleaningInstrumentsViewModel? GetElement(CleaningInstrumentsSearchModel model)
|
|
{
|
|
if (!model.Id.HasValue) return null;
|
|
using var context = new HotelDataBase();
|
|
return context.CleaningInstruments.FirstOrDefault(x => x.Id == model.Id)?.GetView;
|
|
}
|
|
|
|
public CleaningInstrumentsViewModel? Insert(CleaningInstrumentsBindingModel model)
|
|
{
|
|
var item = CleaningInstruments.Create(model);
|
|
|
|
using var context = new HotelDataBase();
|
|
context.CleaningInstruments.Add(item);
|
|
context.SaveChanges();
|
|
|
|
return item.GetView;
|
|
}
|
|
|
|
public CleaningInstrumentsViewModel? Update(CleaningInstrumentsBindingModel model)
|
|
{
|
|
using var context = new HotelDataBase();
|
|
var item = context.CleaningInstruments
|
|
.FirstOrDefault(x => x.Id == model.Id);
|
|
if (item == null) return null;
|
|
|
|
item.Update(model);
|
|
context.SaveChanges();
|
|
return item.GetView;
|
|
}
|
|
|
|
public CleaningInstrumentsViewModel? Delete(CleaningInstrumentsBindingModel model)
|
|
{
|
|
using var context = new HotelDataBase();
|
|
var item = context.CleaningInstruments
|
|
.FirstOrDefault(x => x.Id == model.Id);
|
|
if (item == null) return null;
|
|
context.CleaningInstruments.Remove(item);
|
|
context.SaveChanges();
|
|
return item.GetView;
|
|
}
|
|
} |