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 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 static FullUserEntity ToBllUser(this FullUserViewModel userEntity) { return(new FullUserEntity { Id = userEntity.Id, Name = userEntity.Name, Surname = userEntity.Surname, NickName = userEntity.NickName, Email = userEntity.Email, Password = userEntity.Password, JoinTime = userEntity.JoinTime, Roles = userEntity.Roles.Select(x => x.ToBllRole()) }); }
public static FullUserEntity ToFullBllUser(this FullUserViewModel fullModel) { return new FullUserEntity { Id = fullModel.Id, Name = fullModel.Name, Surname = fullModel.Surname, NickName = fullModel.NickName, Password = fullModel.Password, Email = fullModel.Email, JoinTime = fullModel.JoinTime, AvatarPath = fullModel.AvatarPath, Roles = fullModel.Roles.Select(role => role.ToBllSimpleRole()) }; }
public IActionResult CreateAdminUser([FromBody] FullUserViewModel model) { // map dto to entity var user = GenericMapper.MapObject <User>(model); try { // save _userService.CreateAdminUser(user, model.Password); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
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)); }
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)); }