コード例 #1
0
        public ActionResult Save(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                var customerViewModel = new CustomerMshipViewModel()
                {
                    Customer        = customer,
                    MembershipTypes = _context.MembershipTypes.ToList()
                };
                return(View("CustomerForm", customerViewModel));
            }
            if (customer.Id == 0)
            {
                _context.Customers.Add(customer);
            }
            else
            {
                var customerInDb = _context.Customers.Single(x => x.Id == customer.Id);

                customerInDb.Name             = customer.Name;
                customerInDb.MembershipTypeId = customer.MembershipTypeId;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Customer"));
        }
コード例 #2
0
        public ActionResult Edit(int?id)
        {
            var customer  = _context.Customers.SingleOrDefault(x => x.Id == id);
            var viewModel = new CustomerMshipViewModel()
            {
                Customer        = customer,
                MembershipTypes = _context.MembershipTypes.ToList()
            };

            return(View("CustomerForm", viewModel));
        }
コード例 #3
0
        public ActionResult New()
        {
            var membershipType = _context.MembershipTypes.ToList();
            var viewModel      = new CustomerMshipViewModel()
            {
                Customer        = new Customer(),
                MembershipTypes = membershipType
            };

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