StorekeeperStorage implement
This commit is contained in:
parent
93835aae7a
commit
a61d49a15a
@ -6,10 +6,6 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.29" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.29">
|
||||
|
@ -0,0 +1,99 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
public class StorekeeperStorage : IStorekeeperStorage
|
||||
{
|
||||
public List<StorekeeperViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
return context.Storekeepers
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<StorekeeperViewModel> GetFilteredList(StorekeeperSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var res = GetElement(model);
|
||||
|
||||
return res != null ? new() { res } : new();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public StorekeeperViewModel? GetElement(StorekeeperSearchModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
if (model.Id.HasValue)
|
||||
return context.Storekeepers
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public StorekeeperViewModel? Delete(StorekeeperBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
var res = context.Storekeepers
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
context.Storekeepers.Remove(res);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public StorekeeperViewModel? Insert(StorekeeperBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
var res = Storekeeper.Create(model);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
context.Storekeepers.Add(res);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public StorekeeperViewModel? Update(StorekeeperBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
var res = context.Storekeepers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
res.Update(model);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user