Ejemplo n.º 1
0
        public ActionResult NewCustomer(CustomerViewModel customerModel)
        {
            if (ModelState.IsValid)
            {
                Customer customer = new Customer()
                {
                    FirstName = customerModel.FirstName,
                    LastName = customerModel.LastName,
                    ContactDetails = new ContactDetails()
                    {
                        EmailAddress = customerModel.EmailAddress,
                        HomePhoneNumber = customerModel.HomePhoneNumber
                    }
                };

                m_repository.AddCustomer(customer);
                m_repository.Save();

                return Redirect("~/Home/Customers");
            }
            else
            {
                return View(customerModel);
            }
        }
Ejemplo n.º 2
0
        public ActionResult EditCustomer(int id, CustomerViewModel customerModel)
        {
            if (ModelState.IsValid)
            {
                Customer customer = m_repository.GetCustomer(id);

                if (customer != null)
                {
                    customer.FirstName = customerModel.FirstName;
                    customer.LastName = customerModel.LastName;
                    customer.ContactDetails.EmailAddress = customerModel.EmailAddress;
                    customer.ContactDetails.HomePhoneNumber = customerModel.HomePhoneNumber;

                    m_repository.Save();

                    logMessage("Edited user " + customer.FullName, "EditUser");

                    return Redirect("~/Home/Customers");
                }
                else
                {
                    ModelState.AddModelError("NoCustomer", "Could not find the customer being edited.");
                }
            }

            return View(customerModel);
        }