public ActionResult Save(Customer customer)
        {
            if (customer.Id == 0)
            {
                CustomerDb.Add(customer);
            }
            else
            {
                var customerInDb = CustomerDb.GetById(customer.Id);
                // update properties
                customerInDb.Name = customer.Name;

                CustomerDb.Update(customerInDb);
            }
            return(RedirectToAction("Index", "Customers"));
        }
        public async Task <bool> NewCustomer(CustomerRepoModel newCustomer)
        {
            if (newCustomer != null)
            {
                try
                {
                    var customer = _mapper.Map <Data.Customer>(newCustomer);
                    _context.Add(customer);
                    await _context.SaveChangesAsync();

                    return(true);
                }
                catch (DbUpdateConcurrencyException)
                {
                }
            }
            return(false);
        }
Пример #3
0
 public void Add(Customer customer)
 {
     CustomerDb.Add(customer);
 }