Пример #1
0
        public ActionResult Save(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                NewCustomerViewModel viewModel = new NewCustomerViewModel()
                {
                    Customer        = customer,
                    MembershipTypes = _repo.GetMembershipTypes()
                };

                return(View("CustomerForm", viewModel));
            }


            if (customer.Id == 0)
            {
                _repo.CreateCustomer(customer);
            }
            else
            {
                _repo.UpdateCustomer(customer);
            }

            return(RedirectToAction("Index", "Customer"));
        }
Пример #2
0
        public void UpdateCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            Customer customerInDb = _repo.GetCustomerById(id);

            if (customerInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            _repo.UpdateCustomer(customerInDb);
        }