예제 #1
0
        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();
        }
예제 #2
0
        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();
        }
예제 #3
0
        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);
        }