public ActionResult Edit(FullUserViewModel userViewModel, int[] Role) { if (Role != null && Role.Length > 0) { userViewModel.Roles = Role.Select(x => _roleService.GetRoleEntity(x).ToMvcSimpleRole()); _userService.UpdateUserRoles(userViewModel.ToFullBllUser()); } return(RedirectToAction("Index")); }
public ActionResult Registration(FullUserViewModel userViewModel, HttpPostedFileBase PictureInput) { if (userViewModel.Captcha != (string)Session[Infrastructure.Captcha.CaptchaValueKey]) { ModelState.AddModelError("Captcha", "Incorrect captcha input"); return(View(userViewModel)); } if (ModelState.IsValid) { if (_userService.GetUserByEmail(userViewModel.Email) != null) { ModelState.AddModelError("Email", "User with this Email already exists"); } else if (_userService.GetUserByNickname(userViewModel.NickName) != null) { ModelState.AddModelError("NickName", "User with this NickName already exists"); } else { var membershipUser = ((CustomMembershipProvider)Membership.Provider).GetUser( userViewModel.NickName, false); if (membershipUser == null) { var t = new List <SimpleRoleViewModel>(); t.Add(_roleService.GetRoleEntity(DefaultRole)?.ToMvcSimpleRole()); //adding visitor role userViewModel.Roles = t; userViewModel.JoinTime = DateTime.Now; userViewModel.Password = HashForPassword.GenerateHash(userViewModel.Password); var str = new StringBuilder(); if (PictureInput != null) { str.Append(ImageHelper.SaveFileToDisk(PictureInput, Server.MapPath("~/"))); } userViewModel.AvatarPath = "/UserContent/" + str; _userService.CreateFullUser(userViewModel.ToFullBllUser()); FormsAuthentication.SetAuthCookie(userViewModel.NickName, false); return(RedirectToAction("Index", "Article")); } ModelState.AddModelError("", "This user already exist"); } } return(View(userViewModel)); }