public ActionResult Edit(FullUserViewModel user, int[] Role) { if (Role != null && Role.Length > 0) { user.Roles = Role.Select(x => roleService.GetRole(x).ToMvcRole()); userService.UpdateUser(user.ToBllUser()); } return(RedirectToAction("Index")); }
public ActionResult Registration(FullUserViewModel userViewModel) { if (userViewModel.Captcha != (string)Session["code"]) { ModelState.AddModelError("Captcha", "Incorrect captcha input"); return(View(userViewModel)); } if (ModelState.IsValid) { if (userService.GetUserByNickname(userViewModel.NickName) != null) { ModelState.AddModelError("Nickname", "User with this Nickname already exists"); } else if (userService.GetUserByEmail(userViewModel.Email) != null) { ModelState.AddModelError("E-mail", "User with this e-mail already exists"); } else { var currentUser = ((CustomMembershipProvider)Membership.Provider).GetUser(userViewModel.NickName, false); if (currentUser == null) { var role = new List <RoleViewModel>(); role.Add(roleService.GetRole(DefaultRole)?.ToMvcRole()); userViewModel.Roles = role; userViewModel.JoinTime = DateTime.Now; userViewModel.Password = HashForPassword.GenerateHash(userViewModel.Password); userService.CreateUser(userViewModel.ToBllUser()); FormsAuthentication.SetAuthCookie(userViewModel.NickName, false); return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "This user already exist"); } } return(View(userViewModel)); }