public void InsirtCustomer(CustomerView newCustomer) { Validator <CustomerView> .ValidateNull(newCustomer, Convertors.FirstLetterToUpper(nameof(newCustomer))); var customer = ConvertToCustomer(newCustomer); this.context.Customers.Add(customer); this.context.SaveChanges(); }
public void ModifyCustomer(CustomerView modifiedCustomer) { Validator <CustomerView> .ValidateNull(modifiedCustomer, Convertors.FirstLetterToUpper(nameof(modifiedCustomer))); var customer = this.GetCustomerById(modifiedCustomer.CustomerID); var values = context.Entry(customer).CurrentValues; values.SetValues(modifiedCustomer); context.SaveChanges(); }
private Customer GetCustomerById(string customerId) { Validator <string> .ValidateId(customerId); var customer = this.context.Customers.SingleOrDefault(c => c.CustomerID == customerId); if (customer == null) { throw new ArgumentNullException( Convertors.FirstLetterToUpper(nameof(customer)), $"{Convertors.FirstLetterToUpper(nameof(customer))} with id {customerId} doesn't exist."); } return(customer); }