public CustomerViewModel CreateCustomer(RegisterViewModel viewModel) { Customer customer = Mapper.Map<Customer>(viewModel); context.Customers.Add(customer); context.SaveChanges(); return Mapper.Map<CustomerViewModel>(customer); }
private ICollection<Address> AddressResolver(RegisterViewModel registerViewModel) { return new Collection<Address>() { new Address() { AddressLine1 = registerViewModel.Address.AddressLine1, AddressLine2 = registerViewModel.Address.AddressLine2, City = registerViewModel.Address.City, County = registerViewModel.Address.County, PostCode = registerViewModel.Address.PostCode } }; }
public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { if (WebSecurity.IsAuthenticated) { WebSecurity.Logout(); } try { var customer = userService.CreateCustomer(model); WebSecurity.CreateAccount(customer.Email, model.Password); WebSecurity.Login(customer.Email, model.Password); Roles.AddUserToRole(customer.Email, "Customer"); Attention(string.Format("Welcome {0}, you have logged in.", customer.Forename)); return RedirectToAction("Index", "Products", new { area = "Store" }); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } return View(model); }