Пример #1
0
        public ActionResult CreateCustomer(NewCustomerModel model)
        {
            if (!ModelState.IsValid)
            {
                return View("New", model);
            }

            var foundCustomer = CustomerService.GetCustomer(model.Name);
            if (foundCustomer != null)
            {
                ModelState.AddModelError("Name", "A customer with this company name is already registered.");
                return View("New", model);
            }

            try
            {
                var customer = new Customer
                {
                    Name = model.Name,
                    BillingContact = model.BillingContact,
                    BillingContactEmail = model.BillingContactEmail,
                    TechnicalContact = model.TechnicalContact,
                    TechnicalContactEmail = model.TechnicalContactEmail,
                    IsHosted = model.IsHosted
                };

                CustomerService.CreateCustomer(customer);
            }
            catch (Exception ex)
            {
                QuietLog.LogHandledException(ex);
            }

            return SafeRedirect(Url.AdminCustomers());
        }