ЛАйк э босс
директор сторэдж
This commit is contained in:
parent
eca2a3a9a5
commit
18c17156f1
@ -7,7 +7,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
38
CarCenterDatabaseImplement/Implements/DirectorStorage.cs
Normal file
38
CarCenterDatabaseImplement/Implements/DirectorStorage.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
|
||||
namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
public class DirectorStorage : IDirectorStorage
|
||||
{
|
||||
private void CheckSearchModel(DirectorSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException("Передаваемая модель для поиска равна нулю", nameof(model));
|
||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password))
|
||||
throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null");
|
||||
}
|
||||
public DirectorViewModel? GetElement(DirectorSearchModel model)
|
||||
{
|
||||
CheckSearchModel(model);
|
||||
using var context = new CarCenterDb();
|
||||
return context.Directors
|
||||
.FirstOrDefault(x => x.Login.Equals(model.Login) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)));
|
||||
}
|
||||
public DirectorViewModel? Insert(DirectorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var newDirector = Director.Create(model);
|
||||
using var context = new CarCenterDb();
|
||||
context.Directors.Add(newDirector);
|
||||
context.SaveChanges();
|
||||
return newDirector;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user