public ActionResult AddMember(MemberManagerViewModel memberManagerViewModel) { var jsonResult = new JsonResult(); try { var user = _userLogic.GetByUserName(memberManagerViewModel.UserName); if (user == null) { user=new User { UserName = memberManagerViewModel.UserName, Password = UserConfig.InitialPassword, Email = memberManagerViewModel.UserName+UserConfig.InitialEmailExt }; _userLogic.Register(user); user = _userLogic.GetByUserName(user.UserName); } if (_userProjectRoleRelationLogic.GetByUserIdAndProjectId(user.UserId, memberManagerViewModel.ProjectId)==null) { var userProjectRoleRelation = new UserProjectRoleRelation { UserId = user.UserId, ProjectId = memberManagerViewModel.ProjectId, RoleId = memberManagerViewModel.RoleId }; _userProjectRoleRelationLogic.Add(userProjectRoleRelation); } jsonResult.Data = new { IsSuccess = true }; } catch (Exception) { jsonResult.Data = new { IsSuccess = false, ErrorMessage = "Add failed" }; } return jsonResult; }
public ActionResult Login(LoginViewModel loginViewModel) { try { var user = new User { Email = loginViewModel.UserNameOrEmail, Password = loginViewModel.Password, UserName= loginViewModel.UserNameOrEmail }; var result = _userLogic.AuthenticateUser(user); if (result) { user = _userLogic.GetByEmailAndPassword(user.Email, user.Password) ?? _userLogic.GetByUserNameAndPassword(user.UserName, user.Password); _cookieHelper.SetAuthCookie(Convert.ToString(user.UserId), false); return new RedirectResult(Url.Action("Index", "Project")); } loginViewModel.PromptInfo = "Incorrect username or password."; return View(loginViewModel); } catch (Exception) { return View("Error"); } }
public void Update(User user) { var single = Get(user.UserId); single.UserName = user.UserName; single.Password = user.Password; single.Gender = user.Gender; single.Introduction = user.Introduction; _bugTrackDbContext.SaveChanges(); }
public ProfileViewModel ToProfileViewModelFromUser(User user) { var profileViewModel = new ProfileViewModel { UserName = user.UserName, Email = user.Email, Password = user.Password, Gender = user.Gender, ImageName = string.IsNullOrEmpty(user.ImageUrl) ? string.Empty : user.ImageUrl, Introduction = user.Introduction }; return profileViewModel; }
public User ToUserFromProfileViewModel(ProfileViewModel profileViewModel) { var user = new User() { UserName = profileViewModel.UserName, Password = profileViewModel.Password, Email = profileViewModel.Email, Gender = profileViewModel.Gender, ImageUrl = profileViewModel.ImageName, Introduction = profileViewModel.Introduction }; return user; }
public ActionResult Register(RegisterViewModel registerViewModel) { try { if (_userLogic.GetByUserName(registerViewModel.UserName) != null || _userLogic.GetByEmail(registerViewModel.Email)!=null) { registerViewModel.PromptInfo = "username or email is already used"; return View(registerViewModel); } var user = new User { UserName = registerViewModel.UserName, Password = registerViewModel.Password, Email = registerViewModel.Email }; if (_userLogic.Register(user)) { user = _userLogic.GetByEmailAndPassword(user.Email,user.Password); _cookieHelper.SetAuthCookie(Convert.ToString(user.UserId), false); return new RedirectResult(Url.Action("Index", "Project")); } registerViewModel.PromptInfo = "Registration failed"; return View(registerViewModel); } catch { return View("Error"); } }
public ActionResult Profiles(ProfileViewModel profileViewModel) { try { var user = new User { UserName = profileViewModel.UserName, Email = profileViewModel.Email, Password = profileViewModel.Password, Gender = profileViewModel.Gender, Introduction = profileViewModel.Introduction, UserId = _cookieHelper.GetUserId(Request), }; _userLogic.Update(user); if (profileViewModel.IsUpdateUserImage) { var ioPath = Server.MapPath(UserConfig.UserImageUrl); var imgPath = ioPath + user.UserId + ".jpg"; var tempImgPath = ioPath + user.UserId + "_temp.jpg"; System.IO.File.Delete(imgPath); System.IO.File.Move(tempImgPath, imgPath); } return new RedirectResult(Url.Action("Index", "Project")); } catch (Exception) { return View("Error"); } }
public bool Add(User user) { _bugTrackDbContext.Users.Add(user); return _bugTrackDbContext.SaveChanges()>0; }
public void Update(User user) { _userRepository.Update(user); }
public bool Register(User user) { return _userRepository.Add(user); }
public bool AuthenticateUser(User user) { return (_userRepository.GetByEmailAndPassword(user.Email, user.Password) != null || _userRepository.GetByUserNameAndPassword(user.UserName,user.Password) != null); }