private CustomerBase CreateModel(CustomerBaseBindingModel model, CustomerBase custBase) { custBase.Surname = model.Surname; custBase.Name = model.Name; custBase.Lastname = model.Lastname; custBase.DateOfBirthday = model.DateOfBirthday; return(custBase); }
public void Insert(CustomerBaseBindingModel model) { using (var context = new ComputerRepairDatabase()) { context.CustomerBase.Add(CreateModel(model, new CustomerBase())); context.SaveChanges(); } }
public List <CustomerBaseViewModel> Read(CustomerBaseBindingModel model) { if (model.Id.HasValue) { return(new List <CustomerBaseViewModel> { _customerBaseStorage.GetElement(model) }); } return(_customerBaseStorage.GetFullList()); }
public void CreateOrUpdate(CustomerBaseBindingModel model) { if (model.Id.HasValue) { _customerBaseStorage.Update(model); } else { _customerBaseStorage.Insert(model); } }
public void Delete(CustomerBaseBindingModel model) { var element = _customerBaseStorage.GetElement(new CustomerBaseBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Элемент не найден"); } _customerBaseStorage.Delete(model); }
public void Update(CustomerBaseBindingModel model) { using (var context = new ComputerRepairDatabase()) { var element = context.CustomerBase.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } CreateModel(model, element); context.SaveChanges(); } }
public CustomerBaseViewModel GetElement(CustomerBaseBindingModel model) { if (model == null) { return(null); } using (var context = new ComputerRepairDatabase()) { var custBase = context.CustomerBase.FirstOrDefault(rec => rec.Id == model.Id); return(custBase != null ? new CustomerBaseViewModel { Id = custBase.Id, Surname = custBase.Surname, Name = custBase.Name, Lastname = custBase.Lastname, DateOfBirthday = custBase.DateOfBirthday } : null); } }