гаджишка делаешь
This commit is contained in:
parent
c90a62cdda
commit
f0d1ca8b08
38
CarCenterDatabaseImplement/Implements/ImplementerStorage.cs
Normal file
38
CarCenterDatabaseImplement/Implements/ImplementerStorage.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 ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private void CheckSearchModel(ImplementerSearchModel 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 ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
CheckSearchModel(model);
|
||||
using var context = new CarCenterDb();
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => x.Login.Equals(model.Login) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password)));
|
||||
}
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var newClient = Implementer.Create(model);
|
||||
using var context = new CarCenterDb();
|
||||
context.Implementers.Add(newClient);
|
||||
context.SaveChanges();
|
||||
return newClient;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user