public void Insert(ServicesBindingModel model) { using (var context = new ComputerRepairDatabase()) { context.Services.Add(CreateModel(model, new Services())); context.SaveChanges(); } }
public List <ServicesViewModel> Read(ServicesBindingModel model) { if (model.Id.HasValue) { return(new List <ServicesViewModel> { _servicesStorage.GetElement(model) }); } return(_servicesStorage.GetFullList()); }
public void Update(ServicesBindingModel model) { using (var context = new ComputerRepairDatabase()) { var element = context.Services.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } CreateModel(model, element); context.SaveChanges(); } }
public void Delete(ServicesBindingModel model) { var element = _servicesStorage.GetElement(new ServicesBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Элемент не найден"); } _servicesStorage.Delete(model); }
public ServicesViewModel GetElement(ServicesBindingModel model) { if (model == null) { return(null); } using (var context = new ComputerRepairDatabase()) { var service = context.Materials.FirstOrDefault(rec => rec.Id == model.Id); return(service != null ? new ServicesViewModel { Id = service.Id, Name = service.Name, Price = service.Price } : null); } }
public void CreateOrUpdate(ServicesBindingModel model) { var element = _servicesStorage.GetElement(new ServicesBindingModel { Name = model.Name }); if (element != null && element.Id != model.Id) { throw new Exception("Уже есть услуга с таким названием"); } if (model.Id.HasValue) { _servicesStorage.Update(model); } else { _servicesStorage.Insert(model); } }
private Services CreateModel(ServicesBindingModel model, Services service) { service.Name = model.Name; service.Price = model.Price; return(service); }