public static void UpdateUser(UserProfile user) { using (UnitOfWork uow = new UnitOfWork()) { uow.UserProfileRepository.Update(user); uow.Save(); } }
public PartialViewResult _Notification() { UnitOfWork unitOfWork = new UnitOfWork(); User user = unitOfWork.UserRepository.GetUserByUserID((Guid)Membership.GetUser(WebSecurity.User.Identity.Name).ProviderUserKey); List<Notification> notificationList = unitOfWork.NotificationRepository.UserUnreadNotification(user); //ViewBag.Notifications = notificationList; return PartialView(notificationList); }
public static void CreateUser(UserProfile user) { UserProfile dbUser = GetUser(user.UserName); if (dbUser != null) throw new Exception("User with that username already exists."); UnitOfWork uow = new UnitOfWork(); uow.UserProfileRepository.Insert(user); uow.Save(); }
public ActionResult EditProfile(User user) { UnitOfWork unitofWork = new UnitOfWork(); //User userNew = unitofWork.UserRepository.GetUserByEmail(User.Identity.Name); //userNew.FirstName = user.FirstName; //userNew.LastName = user.LastName; unitofWork.UserRepository.Update(user); unitofWork.Save(); return View(); }
public PartialViewResult _NotificationReadAll(List<Notification> notifications) { UnitOfWork unitOfWork = new UnitOfWork(); UserProfile user = unitOfWork.UserRepository.GetUserByUserID((int)Membership.GetUser(WebSecurity.CurrentUserName).ProviderUserKey); List<Notification> notificationList = unitOfWork.NotificationRepository.UserUnreadNotification(user); List<Notification> notificationListNew = new List<Notification>(); foreach (Notification item in notificationList) { item.IsNoticed = true; unitOfWork.NotificationRepository.InsertOrUpdate(item); } unitOfWork.Save(); return PartialView("_Notification", notificationListNew); }
public static string CreateAccount(string userName, string email,string password, string FirstName,string LastName ,bool requireConfirmationToken = false) { string status=""; using (UnitOfWork reopo = new UnitOfWork()) { User existingUser = reopo.UserRepository.GetUserByEmail(email); string HashedPassword = Crypto.HashPassword(password); if (HashedPassword.Length > 128) { status = "InvalidPassword"; return null; } if (existingUser != null) { status = "DuplicateEmail"; return null; } User NewUser = new User { UserId = Guid.NewGuid(), Username = email, Password = HashedPassword, IsApproved = true, Email = email, CreateDate = DateTime.UtcNow, LastPasswordChangedDate = DateTime.UtcNow, PasswordFailuresSinceLastSuccess = 0, LastLoginDate = DateTime.UtcNow, LastActivityDate = DateTime.UtcNow, LastLockoutDate = DateTime.UtcNow, IsLockedOut = false, LastPasswordFailureDate = DateTime.UtcNow, FirstName = FirstName, LastName = LastName }; reopo.UserRepository.Insert(NewUser); reopo.Save(); } return status; }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { if (string.IsNullOrEmpty(username)) { status = MembershipCreateStatus.InvalidUserName; return null; } if (string.IsNullOrEmpty(password)) { status = MembershipCreateStatus.InvalidPassword; return null; } if (string.IsNullOrEmpty(email)) { status = MembershipCreateStatus.InvalidEmail; return null; } string HashedPassword = Crypto.HashPassword(password); if (HashedPassword.Length > 128) { status = MembershipCreateStatus.InvalidPassword; return null; } using (UnitOfWork reopo = new UnitOfWork()) { UserProfile existingUser = reopo.UserRepository.GetUserByEmail(email); if (existingUser!=null) { status = MembershipCreateStatus.DuplicateEmail; return null; } UserProfile NewUser = new UserProfile { // UserId = Guid.NewGuid(), Email = email, }; reopo.UserRepository.Insert(NewUser); reopo.Save(); status = MembershipCreateStatus.Success; return null;// new MembershipUser(Membership.Provider.Name, NewUser.UserName, NewUser.UserId, NewUser.Email, null, null, NewUser.IsApproved, NewUser.IsLockedOut, NewUser.CreateDate.Value, NewUser.LastLoginDate.Value, NewUser.LastActivityDate.Value, NewUser.LastPasswordChangedDate.Value, NewUser.LastLockoutDate.Value); } }
public ActionResult EditProfile() { UnitOfWork unitofWork = new UnitOfWork(); User user =unitofWork.UserRepository.GetUserByUserName(User.Identity.Name); return View(user); }
public ActionResult Manage(LocalPasswordModel model) { bool hasLocalAccount; UnitOfWork unitofwork = new UnitOfWork(); User user = unitofwork.UserRepository.GetUserByUserName(User.Identity.Name); if (user != null) hasLocalAccount = true; else hasLocalAccount = false; //= OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name)); ViewBag.HasLocalPassword = hasLocalAccount; ViewBag.ReturnUrl = Url.Action("Manage"); if (hasLocalAccount) { if (ModelState.IsValid) { // ChangePassword will throw an exception rather than return false in certain failure scenarios. bool changePasswordSucceeded; try { changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword); } catch (Exception) { changePasswordSucceeded = false; } if (changePasswordSucceeded) { return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }); } else { ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } } } else { // User does not have a local password so remove any validation errors caused by a missing // OldPassword field ModelState state = ModelState["OldPassword"]; if (state != null) { state.Errors.Clear(); } if (ModelState.IsValid) { try { WebSecurity.CreateAccount(User.Identity.Name, model.NewPassword); return RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess }); } catch (Exception e) { ModelState.AddModelError("", e); } } } // If we got this far, something failed, redisplay form return View(model); }
// // GET: /Account/Manage public ActionResult Manage(ManageMessageId? message) { UnitOfWork unitofwork = new UnitOfWork(); ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." : message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed." : ""; User user = unitofwork.UserRepository.GetUserByUserName(User.Identity.Name); if (user != null) ViewBag.HasLocalPassword = true; else ViewBag.HasLocalPassword = false; //OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name)); ViewBag.ReturnUrl = Url.Action("Manage"); return View(); }
public static bool FoundUser(string username) { UnitOfWork uow = new UnitOfWork(); UserProfile user = GetUser(username);// uow.UserProfileRepository.Get(u => u.UserName == username).FirstOrDefault(); return user != null; }
public static string GetConfirmationToken(string userName) { UnitOfWork uow = new UnitOfWork(); long userId = uow.UserProfileRepository.Get(u => u.UserName == userName).Select(x => x.UserId).SingleOrDefault(); string token = uow.MembershipRepository.GetConfirmationToken(userId); return token; }
public static UserProfile GetUser(string username) { UnitOfWork uow = new UnitOfWork(); return uow.UserRepository.GetUserByUserName(username); }