public void addElement(BoundCustomerModel model) { Customer element = context.Customers.FirstOrDefault(rec => rec.CustomerFullName == model.CustomerFullName); if (element != null) { throw new Exception("Уже есть клиент с таким ФИО"); } context.Customers.Add(new Customer { CustomerFullName = model.CustomerFullName, Mail = model.Mail }); context.SaveChanges(); }
public void addElement(BoundCustomerModel model) { Customer element = source.Customers.FirstOrDefault(rec => rec.CustomerFullName == model.CustomerFullName); if (element != null) { throw new Exception("Уже есть клиент с таким ФИО"); } int maxId = source.Customers.Count > 0 ? source.Customers.Max(rec => rec.ID) : 0; source.Customers.Add(new Customer { ID = maxId + 1, CustomerFullName = model.CustomerFullName }); }
public void updateElement(BoundCustomerModel model) { Customer element = context.Customers.FirstOrDefault(rec => rec.CustomerFullName == model.CustomerFullName && rec.ID != model.ID); if (element != null) { throw new Exception("Уже есть клиент с таким ФИО"); } element = context.Customers.FirstOrDefault(rec => rec.ID == model.ID); if (element == null) { throw new Exception("Элемент не найден"); } element.CustomerFullName = model.CustomerFullName; element.Mail = model.Mail; context.SaveChanges(); }
public void DelElement(BoundCustomerModel model) { _service.deleteElement(model.ID); }
public void UpdElement(BoundCustomerModel model) { _service.updateElement(model); }
public void AddElement(BoundCustomerModel model) { _service.addElement(model); }