コード例 #1
0
ファイル: UserService.cs プロジェクト: pjmagee/CI3540
 public CustomerViewModel CreateCustomer(RegisterViewModel viewModel)
 {
     Customer customer = Mapper.Map<Customer>(viewModel);
     context.Customers.Add(customer);
     context.SaveChanges();
     return Mapper.Map<CustomerViewModel>(customer);
 }
コード例 #2
0
ファイル: CustomerProfile.cs プロジェクト: pjmagee/CI3540
        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
                        }
                };
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: pjmagee/CI3540
        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);
        }