public ActionResult Register(Customer customer) { _logger.InfoFormat("Registration of user. Name : [{0}], surname : [{1}], email : [{2}].", customer.Name, customer.Surname, customer.Email); if (ModelState.IsValid) { try { _customerAccountService.CreateCustomer(customer); _logger.InfoFormat("Registration of user was successful. Name : [{0}], surname : [{1}], email : [{2}].", customer.Name, customer.Surname, customer.Email); return(RedirectToAction("Login")); } catch (Exception ex) //TODO: create separate exception to handle "Email already exists" { string exMessage = ex.Message; _logger.Info(exMessage); Debug.WriteLine(exMessage); ModelState.AddModelError("", exMessage); } } return(View(customer)); }
public ActionResult Register(RegisterCustomerViewModel model) { var viewModel = new RegisterCustomerViewModel(); var customer = mapper.Map <RegisterCustomerViewModel, Customer>(model); var returnStatus = customerAccountService.CreateCustomer(customer); if (returnStatus == MembershipCreateStatus.Success) { var customerData = mapper.Map <RegisterCustomerViewModel, Customer>(model); mailer.NewCustomer(customer).Send(); authentication.Signin(customer.Email, customerData); return(RedirectToAction("ThankYouForJoining")); } viewModel.HasError = true; viewModel.CreateStatus = new CustomerCreationError(returnStatus); return(View(viewModel)); }