コード例 #1
0
 public CustomerViewModel(Customer customer)
 {
     Id = customer.Id;
     FirstName = customer.FirstName;
     LastName = customer.LastName;
     EmailAddress = customer.ContactDetails.EmailAddress;
     HomePhoneNumber = customer.ContactDetails.HomePhoneNumber;
 }
コード例 #2
0
        public bool AddCustomer(Customer customer)
        {
            try
            {
                m_context.Customers.Add(customer);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #3
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);
            }
        }