Пример #1
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.UserName, Email = model.Email};
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    //var userProfileRepo = new UserProfileRepository();
                    //userProfileRepo.Create(new Data.Model.UserProfile
                    //{
                    //    Username = model.UserName,
                    //    Password = model.Password,
                    //    Email = model.Email,
                    //    isFacebookUser = false,
                    //    FirstName = model.FirstName,
                    //    LastName = model.LastName,
                    //    Address = model.Address,
                    //    AllowAddressVerfication = model.AllowAddressVerfication,
                    //    City = model.City,
                    //    Country = model.Country,
                    //    HomePhone = model.HomePhone,
                    //    MobilePhone = model.MobilePhone,
                    //    AllowPhoneVerfication = model.AllowPhoneVerfication,
                    //    DriversLicense = model.DriversLicense,
                    //    AllowDriverLicenseVerfication = model.AllowDriverLicenseVerfication,
                    //    DateRegistered = DateTime.UtcNow
                    //});

                    var userProfile = new Data.Model.UserProfile
                    {
                        Username = model.UserName,
                        Password = model.Password,
                        Email = model.Email,
                        isFacebookUser = false,
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        Address = model.Address,
                        AllowAddressVerfication = model.AllowAddressVerfication,
                        City = model.City,
                        Country = model.Country,
                        HomePhone = model.HomePhone,
                        MobilePhone = model.MobilePhone,
                        AllowPhoneVerfication = model.AllowPhoneVerfication,
                        DriversLicense = model.DriversLicense,
                        AllowDriverLicenseVerfication = model.AllowDriverLicenseVerfication,
                        DateRegistered = DateTime.UtcNow
                    };
                    var accountService = new AccountService();
                    await accountService.Register(userProfile);

                    if (!string.IsNullOrEmpty(model.SearchAddress))
                    {
                        var searchRepo = new SearchRepository();
                        searchRepo.AssociateAddress(model.SearchAddress, model.UserName);
                    }

                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    var mail = new MailService();
                    mail.Send(model.Email, Server.MapPath("~/EmailTemplate/Registration.html"), model.UserName);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #2
0
 public ActionResult Register()
 {
     var search = Request.QueryString["search"] != null ? Request.QueryString["search"].ToString() : string.Empty;
     var register = new RegisterViewModel { SearchAddress = search};
     return View(register);
 }