public JsonResult IsUserNameExists(Users userObj) { var users = UnitOfWork.UserRepository.Get(); bool has = users.ToList().Any(x => x.UserName.ToLower() == (userObj.UserName == null?"":userObj.UserName.ToLower())); if (has) { return(Json(new { value = true, responseText = "User name exists" })); } else { return(Json(new { value = false, responseText = "User name is not exists" })); } }
//[ValidateAntiForgeryToken] public JsonResult UpdateUser(Users users) { try { if (users.UserId != 0) { var fetchedUser = objUnitOfWorkFetch.UserRepository.Get(x => x.UserId == users.UserId).ToList(); string img = fetchedUser[0].UserImage; string pwd = fetchedUser[0].Password; DateTime createdDate = Convert.ToDateTime(fetchedUser[0].CreatedDate); int createdBy = Convert.ToInt32(fetchedUser[0].CreatedBy); var user = new Aris.Data.Entities.Users { UserId = users.UserId, UserName = users.UserName, FullName = users.FullName, UserTypeID = users.UserTypeID, MailAddress = users.MailAddress, IsActive = users.IsActive, CreatedBy = createdBy, CreatedDate = createdDate, ModifiedBy = Convert.ToInt32(TempData.Peek("UserId")), ModifiedDate = DateTime.Now, UserImage = users.ProfileImage == null?img: users.ProfileImage, Password = pwd }; UnitOfWork.UserRepository.Update(user); UnitOfWork.Save(); return(Json(new { success = true, responseText = "User updated successfully." })); } else { return(Json(new { success = false, responseText = "Something went wrong." })); } } catch (Exception ex) { _logger.LogError(ex.ToString()); return(Json(new { success = false, responseText = "Something went wrong." })); } }
//[ValidateAntiForgeryToken] public JsonResult SubmitRequest(Users userObj) { try { var randomPwd = GetRandomPassword(); var user = new Aris.Data.Entities.Users() { UserName = new GenericMethods().ConvertToTitleCase(userObj.UserName), MailAddress = userObj.MailAddress, UserTypeID = userObj.UserTypeID, IsActive = userObj.IsActive, CreatedDate = DateTime.Now, CreatedBy = Convert.ToInt32(TempData.Peek("UserId")), FullName = new GenericMethods().ConvertToTitleCase(userObj.FullName), Password = new AuthHelper().HashPassword(randomPwd), UserImage = userObj.ProfileImage }; UnitOfWork.UserRepository.Insert(user); UnitOfWork.Save(); #region send mail var userData = UnitOfWork.UserRepository.Get(u => u.IsActive == 1); var loggedInUser = (from users in userData where users.UserId == Convert.ToInt32(TempData.Peek("UserId")) select users).FirstOrDefault(); string strBody = EmailTemplateHelper.createAccount; strBody = strBody.Replace("[USER]", new GenericMethods().ConvertToTitleCase(userObj.FullName)).Replace("[USERNAME]", new GenericMethods().ConvertToTitleCase(userObj.UserName)).Replace("[APPLICATIONLINK]", "https://aris-amt.com/").Replace("[PASSWORD]", randomPwd); EmailService emailService = new EmailService(_appSettings); emailService.Send(userObj.MailAddress, loggedInUser.MailAddress, "AMT User Account Created", strBody); #endregion return(Json(new { success = true, responseText = "User Added Successfully." })); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(Json(new { success = true, responseText = "Something Went Wrong!" })); } }