public ActionResult Create(CreateUserViewModel createUserViewModel) { try { if (ModelState.IsValid) { var isUser = _iUserMaster.CheckUsernameExists(createUserViewModel.UserName); if (isUser) { ModelState.AddModelError("", "Username already exists"); } AesAlgorithm aesAlgorithm = new AesAlgorithm(); var usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel); usermaster.Status = true; usermaster.CreateDate = DateTime.Now; usermaster.UserId = 0; usermaster.CreatedBy = Convert.ToInt32(Session["UserID"]); var userId = _iUserMaster.AddUser(usermaster); if (userId != -1) { var passwordMaster = new PasswordMaster { CreateDate = DateTime.Now, UserId = userId, PasswordId = 0, Password = aesAlgorithm.EncryptString(createUserViewModel.Password) }; var passwordId = _iPassword.SavePassword(passwordMaster); if (passwordId != -1) { var savedAssignedRoles = new SavedAssignedRoles() { RoleId = createUserViewModel.RoleId, UserId = userId, AssignedRoleId = 0, Status = true, CreateDate = DateTime.Now }; _savedAssignedRoles.AddAssignedRoles(savedAssignedRoles); TempData["MessageCreateUsers"] = "User Created Successfully"; } } return(RedirectToAction("Create", "CreateUsers")); } else { return(View("Create", createUserViewModel)); } } catch { throw; } }
public ActionResult Create(CreateUserViewModel createUserViewModel) { try { if (ModelState.IsValid) { if (_iUserMaster.CheckEmailIdExists(createUserViewModel.EmailId)) { TempData["MessageCreateUsersErrors"] = "EmailId Already Exists"; } else if (_iUserMaster.CheckMobileNoExists(createUserViewModel.MobileNo)) { TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists"; } else if (_iUserMaster.CheckUsernameExists(createUserViewModel.UserName)) { ModelState.AddModelError("", "Username already exists"); } else { createUserViewModel.FirstName = UppercaseFirst(createUserViewModel.FirstName); createUserViewModel.LastName = UppercaseFirst(createUserViewModel.LastName); var usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel); usermaster.Status = true; usermaster.CreateDate = DateTime.Now; usermaster.UserId = 0; usermaster.CreatedBy = Convert.ToInt32(_sessionHandler.UserId); var salt = GenerateRandomNumbers.RandomNumbers(20); var saltedpassword = GenerateHashSha512.Sha512(createUserViewModel.Password, salt); var userId = _iUserMaster.AddUser(usermaster, saltedpassword, salt, createUserViewModel.RoleId); if (userId != -1) { TempData["MessageCreateUsers"] = "User Created Successfully"; } return(RedirectToAction("Create", "CreateUsers")); } createUserViewModel.ListRole = _iRole.GetAllActiveRolesNotAgent(); return(View("Create", createUserViewModel)); } else { createUserViewModel.ListRole = _iRole.GetAllActiveRolesNotAgent(); return(View("Create", createUserViewModel)); } } catch { throw; } }
public ActionResult Create(CreateNewUserViewModel createUserViewModel) { try { if (ModelState.IsValid) { if (_iUserMaster.CheckEmailIdExists(createUserViewModel.EmailId)) { TempData["MessageCreateUsersErrors"] = "EmailId Already Exists"; } else if (_iUserMaster.CheckMobileNoExists(createUserViewModel.MobileNo)) { TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists"; } else { string username = GenerateUserName(createUserViewModel); Usermaster usermaster = new Usermaster(); usermaster.Status = true; usermaster.CreateDate = DateTime.Now; usermaster.UserId = 0; usermaster.FirstName = createUserViewModel.FirstName; usermaster.LastName = createUserViewModel.LastName; usermaster.EmailId = createUserViewModel.EmailId; usermaster.MobileNo = createUserViewModel.MobileNo; usermaster.UserName = username; usermaster.CreatedBy = Convert.ToInt32(_sessionHandler.UserId); usermaster.Gender = createUserViewModel.Gender; var salt = GenerateRandomNumbers.RandomNumbers(20); var password = GeneratePassword(createUserViewModel, salt); var userId = _iUserMaster.AddUser(usermaster, password, salt, Convert.ToInt16(StatusMain.Roles.User)); if (userId != -1) { TempData["MessageCreateUsers"] = $"User Created Successfully Username :- {usermaster.UserName}"; } return(RedirectToAction("Create", "CreateNewUser")); } return(View("Create", createUserViewModel)); } else { return(View("Create", createUserViewModel)); } } catch { throw; } }
public ActionResult Register(UsermasterView usermaster) { try { if (ModelState.IsValid) { var autoUsermaster = AutoMapper.Mapper.Map <Usermaster>(usermaster); var isUser = _iUserMaster.CheckUsernameExists(usermaster.UserName); if (isUser) { ModelState.AddModelError("", "Username already exists"); } AesAlgorithm aesAlgorithm = new AesAlgorithm(); var userId = _iUserMaster.AddUser(autoUsermaster); if (userId != -1) { PasswordMaster passwordMaster = new PasswordMaster { CreateDate = DateTime.Now, UserId = userId, PasswordId = 0, Password = aesAlgorithm.EncryptString(usermaster.Password) }; var passwordId = _iPassword.SavePassword(passwordMaster); if (passwordId != -1) { TempData["MessageRegistration"] = "Registration Successful"; } } return(RedirectToAction("Register", "Registration")); } else { return(View("Register", usermaster)); } } catch { throw; } }
public async Task <ActionResult> Register(UsermasterView usermaster) { try { if (ModelState.IsValid) { if (!this.IsCaptchaValid("Captcha is not valid")) { ModelState.AddModelError("", "Error: captcha is not valid."); return(View(usermaster)); } if (_iUserMaster.CheckUsernameExists(usermaster.UserName)) { ModelState.AddModelError("", "UserName already exists"); return(View(usermaster)); } if (_iUserMaster.CheckEmailIdExists(usermaster.EmailId)) { ModelState.AddModelError("", "EmailId already exists"); return(View(usermaster)); } if (_iUserMaster.CheckMobileNoExists(usermaster.MobileNo)) { TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists"; } var autoUsermaster = AutoMapper.Mapper.Map <Usermaster>(usermaster); var salt = GenerateRandomNumbers.RandomNumbers(20); var saltedpassword = GenerateHashSha512.Sha512(usermaster.Password, salt); var userId = _iUserMaster.AddUser(autoUsermaster, saltedpassword, salt, Convert.ToInt16(StatusMain.Roles.User)); if (userId != -1) { var emailVerficationToken = GenerateHashSha256.ComputeSha256Hash((GenerateRandomNumbers.RandomNumbers(6))); _verification.SendRegistrationVerificationToken(userId, emailVerficationToken); SendingEmailhelper sendingEmailhelper = new SendingEmailhelper(); var name = string.Concat(usermaster.FirstName, usermaster.LastName); await sendingEmailhelper.SendVerificationEmailasync(usermaster.EmailId, name, emailVerficationToken, "Registration", Convert.ToString(userId)); TempData["MessageRegistration"] = "Thank you. Your Registration has been completed successfully."; } else { TempData["ErrorRegistration"] = "Something Went Wrong While you are registering.Please try after sometime."; } return(RedirectToAction("Register", "Registration")); } else { return(View("Register", usermaster)); } } catch { throw; } }
public ActionResult Create(CreateUserViewModel createUserViewModel, HttpPostedFileBase fileUpload) { try { if (createUserViewModel.UserId > 0) { ModelState.Remove("UserName"); ModelState.Remove("Password"); ModelState.Remove("ConfirmPassword"); ModelState.Remove("RoleId"); } if (ModelState.IsValid) { if (createUserViewModel.UserId == 0) { var isUser = _iUserMaster.CheckUsernameExists(createUserViewModel.UserName); if (isUser) { ModelState.AddModelError("", "Username already exists"); } AesAlgorithm aesAlgorithm = new AesAlgorithm(); var usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel); string path = Server.MapPath("~/Content/UserImage/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (fileUpload != null && fileUpload.ContentLength > 0) { string extension = Path.GetExtension(fileUpload.FileName); string newFileName = "u_" + DateTime.Now.Ticks + extension; usermaster.ImageName = newFileName; fileUpload.SaveAs(path + newFileName); } usermaster.Status = true; usermaster.CreateDate = DateTime.Now; usermaster.UserId = 0; usermaster.CreatedBy = Convert.ToInt32(Session["UserID"]); var userId = _iUserMaster.AddUser(usermaster); if (userId != -1) { var passwordMaster = new PasswordMaster { CreateDate = DateTime.Now, UserId = userId, PasswordId = 0, Password = aesAlgorithm.EncryptString(createUserViewModel.Password) }; var passwordId = _iPassword.SavePassword(passwordMaster); if (passwordId != -1) { var savedAssignedRoles = new SavedAssignedRoles() { RoleId = createUserViewModel.RoleId, UserId = userId, AssignedRoleId = 0, Status = true, CreateDate = DateTime.Now }; _savedAssignedRoles.AddAssignedRoles(savedAssignedRoles); TempData["MessageCreateUsers"] = "User Created Successfully"; } } } else { var usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel); string path = Server.MapPath("~/Content/UserImage/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (fileUpload != null && fileUpload.ContentLength > 0) { string extension = Path.GetExtension(fileUpload.FileName); string newFileName = "u_" + DateTime.Now.Ticks + extension; usermaster.ImageName = newFileName; fileUpload.SaveAs(path + newFileName); } usermaster.Status = true; usermaster.CreateDate = DateTime.Now; usermaster.UserId = createUserViewModel.UserId; usermaster.CreatedBy = Convert.ToInt32(Session["UserID"]); var userId = _iUserMaster.UpdateUser(usermaster); } return(RedirectToAction("Create", "CreateUsers")); } else { return(View("Create", createUserViewModel)); } } catch { throw; } }