Example #1
0
        public ActionResult Detail(int?id)
        {
            Customer customer;

            if (id.HasValue)
            {
                customer = _context.Customers.FirstOrDefault(c => c.ID == id.Value);
                if (customer == null)
                {
                    return(HttpNotFound("Invalid Customer ID"));
                }
            }
            else
            {
                customer = new Customer();
            }

            var allMembershipTypes = _context.MembershipTypes.ToList();

            var vm = new DetailCustomerVM()
            {
                Customer        = customer,
                MembershipTypes = allMembershipTypes
            };

            return(View("Detail", vm));
        }
Example #2
0
        public IActionResult DetailCustomer(string id)
        {
            DetailCustomerVM detailCustomerVM = new DetailCustomerVM
            {
                Customer     = _customerService.GetById(id),
                ShoppingBags = _ShoppingBagService.GetAllShoppingBagsByCustomerId(id)
            };

            detailCustomerVM.recalculateBags();
            return(View(detailCustomerVM));
        }
Example #3
0
        public ActionResult Detail(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                var vm = new DetailCustomerVM()
                {
                    Customer        = customer,
                    MembershipTypes = _context.MembershipTypes.ToList()
                };

                return(View("Detail", vm));
            }

            if (customer.ID == 0)
            {
                _context.Customers.Add(customer);
            }
            else
            {
                var objToSave = _context.Customers.FirstOrDefault(c => c.ID == customer.ID);

                if (objToSave == null)
                {
                    return(HttpNotFound("Invalid Customer ID"));
                }

                //ryUpdateModel(objToSave,"",new string[] {"Name","Birthdate"});

                objToSave.Name              = customer.Name;
                objToSave.BirthDate         = customer.BirthDate;
                objToSave.MobileNo          = customer.MobileNo;
                objToSave.Gender            = customer.Gender;
                objToSave.MembershipTypeID  = customer.MembershipTypeID;
                objToSave.IsSubscribeToMail = customer.IsSubscribeToMail;
            }
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }