Add storage
This commit is contained in:
parent
8b20de0f78
commit
bc264ce150
@ -6,10 +6,6 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Implements" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.2.23128.3" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.2.23128.3" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.2.23128.3" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.2.23128.3" />
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
69
Hotel/HotelDatabaseImplement/Implements/CleaningStorage.cs
Normal file
69
Hotel/HotelDatabaseImplement/Implements/CleaningStorage.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
72
Hotel/HotelDatabaseImplement/Implements/GuestStorage.cs
Normal file
72
Hotel/HotelDatabaseImplement/Implements/GuestStorage.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.SearchModels;
|
||||||
|
using HotelContracts.StoragesContracts;
|
||||||
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace HotelDatabaseImplement.Implements;
|
||||||
|
|
||||||
|
public class GuestStorage : IGuestStorage
|
||||||
|
{
|
||||||
|
public List<GuestViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Guests
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GuestViewModel> GetFilteredList(GuestSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
|
{
|
||||||
|
return new List<GuestViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Guests
|
||||||
|
.Where(x => x.Name == model.Name)
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuestViewModel? GetElement(GuestSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue) return null;
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Guests.FirstOrDefault(x => x.Id == model.Id)?.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuestViewModel? Insert(GuestBindingModel model)
|
||||||
|
{
|
||||||
|
var item = Guest.Create(model);
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
context.Guests.Add(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuestViewModel? Update(GuestBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = context.Guests.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
item.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuestViewModel? Delete(GuestBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = context.Guests.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null) return null;
|
||||||
|
context.Guests.Remove(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
}
|
71
Hotel/HotelDatabaseImplement/Implements/MaitreStorage.cs
Normal file
71
Hotel/HotelDatabaseImplement/Implements/MaitreStorage.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.SearchModels;
|
||||||
|
using HotelContracts.StoragesContracts;
|
||||||
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace HotelDatabaseImplement.Implements;
|
||||||
|
|
||||||
|
public class MaitreStorage : IMaitreStorage
|
||||||
|
{
|
||||||
|
public List<MaitreViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Maitres
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MaitreViewModel> GetFilteredList(MaitreSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Login))
|
||||||
|
{
|
||||||
|
return new List<MaitreViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Maitres
|
||||||
|
.Where(x => x.Login == model.Login)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaitreViewModel? GetElement(MaitreSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue) return null;
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Maitres.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaitreViewModel? Insert(MaitreBindingModel model)
|
||||||
|
{
|
||||||
|
var item = Maitre.Create(model);
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
context.Maitres.Add(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return item.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaitreViewModel? Update(MaitreBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = context.Maitres.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
item.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaitreViewModel? Delete(MaitreBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = context.Maitres.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null) return null;
|
||||||
|
context.Maitres.Remove(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.SearchModels;
|
||||||
|
using HotelContracts.StoragesContracts;
|
||||||
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace HotelDatabaseImplement.Implements;
|
||||||
|
|
||||||
|
public class ReservationStorage : IReservationStorage
|
||||||
|
{
|
||||||
|
public List<ReservationViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
return context.Reservations
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReservationViewModel> GetFilteredList(ReservationSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.From.HasValue || !model.To.HasValue)
|
||||||
|
return new List<ReservationViewModel>();
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Reservations
|
||||||
|
.Where(x => x.StartDate >= model.From && x.StartDate <= model.To)
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReservationViewModel? GetElement(ReservationSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue) return null;
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Reservations.FirstOrDefault(x => x.Id == model.Id)?.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReservationViewModel? Insert(ReservationBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = Reservation.Create(context, model);
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
context.Reservations.Add(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReservationViewModel? Update(ReservationBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = context.Reservations.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
item.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReservationViewModel? Delete(ReservationBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = context.Reservations.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null) return null;
|
||||||
|
context.Reservations.Remove(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
}
|
80
Hotel/HotelDatabaseImplement/Implements/RoomStorage.cs
Normal file
80
Hotel/HotelDatabaseImplement/Implements/RoomStorage.cs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.SearchModels;
|
||||||
|
using HotelContracts.StoragesContracts;
|
||||||
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace HotelDatabaseImplement.Implements;
|
||||||
|
|
||||||
|
public class RoomStorage : IRoomStorage
|
||||||
|
{
|
||||||
|
public List<RoomViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Rooms
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RoomViewModel> GetFilteredList(RoomSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Type))
|
||||||
|
{
|
||||||
|
return new List<RoomViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
if (model.Cost.HasValue)
|
||||||
|
{
|
||||||
|
return context.Rooms
|
||||||
|
.Where(x => x.Cost <= model.Cost)
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return context.Rooms
|
||||||
|
.Where(x => x.Type == model.Type)
|
||||||
|
.Select(x => x.GetView)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoomViewModel? GetElement(RoomSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue) return null;
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
return context.Rooms.FirstOrDefault(x => x.Id == model.Id)?.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoomViewModel? Insert(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
var item = Room.Create(model);
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
context.Rooms.Add(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoomViewModel? Update(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = context.Rooms.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
item.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoomViewModel? Delete(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
var item = context.Rooms.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null) return null;
|
||||||
|
context.Rooms.Remove(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetView;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user