コード例 #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 Customer CreateCustomer(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            _repo.CreateCustomer(customer);

            return(customer);
        }