void IUsersService.Save(UserProfile userProfile)
 {
     if (userProfile.UserId == 0)
     {
         this.db.Add(userProfile);
     }
     this.db.SaveChanges();
 }
        public ActionResult Confirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                var userName = provider + "_" + providerUserId;
                var userProfile = this.usersService.GetUserProfile(userName);
                if (userProfile == null)
                {
                    userProfile = new UserProfile { UserName = provider + "_" + providerUserId, DisplayName = model.UserName };
                    this.usersService.Save(userProfile);
                }

                OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, userProfile.UserName);

                OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                return RedirectToLocal(returnUrl);
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public override string CreateUserAndAccount(string userName/*email*/, string password, bool requireConfirmation, IDictionary<string, object> values)
        {
            userName = userName.Trim().ToLower();

            var userProfile = this.usersService.GetUserProfile(userName);
            if (userProfile != null)
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateEmail);
            }

            var newUserProfile = new UserProfile { UserName = userName, DisplayName = userName };
            this.usersService.Save(newUserProfile);

            var membership = new App.Core.Data.Membership
            {
                UserId = newUserProfile.UserId,
                CreateDate = DateTime.Now,
                PasswordSalt = this.usersService.GetHash(password),
                IsConfirmed = false,
                ConfirmationToken = Guid.NewGuid().ToString().ToLower()
            };
            this.usersService.Save(membership, add: true);

            return membership.ConfirmationToken;
        }
 void IDatabaseContext.Add(UserProfile userProfile)
 {
     this.Set<UserProfile>().Add(userProfile);
 }