private void EditProfileSave(EditProfileDto model, AdminUser adminUser) { adminUser.Name = model.Name; adminUser.Email = model.Email; _adminUserRepository.Update(adminUser); _unitOfWork.Commit(); }
private void SetLastLoginAt(AdminUser adminUser) { adminUser.LastLoginAt = DateTime.Now; _adminUserRepository.Update(adminUser); _unitOfWork.Commit(); }
private void SetNewPassword(AdminUser adminUser, string newPassword) { adminUser.Salt = SecurityHelper.GenerateSalt(); adminUser.Password = SecurityHelper.GenerateHash(newPassword, adminUser.Salt); adminUser.ForgotPasswordToken = null; _adminUserRepository.Update(adminUser); _unitOfWork.Commit(); }
private string GenerateAndSaveForgotPasswordToken(AdminUser adminUser) { var passwordResetToken = StringHelper.RandomString(12); adminUser.ForgotPasswordToken = passwordResetToken; _adminUserRepository.Update(adminUser); _unitOfWork.Commit(); return(passwordResetToken); }
public bool Update(AdminUserDto entity) { try { return(rep.Update(entity.MapTo <AdminUser>())); } catch (Exception) { throw; } }
public Result ExecuteAction(List <int> ids) { var query = _adminUserRepository.AsNoTracking.Where(q => ids.Contains(q.Id)); var result = new Result().SetSuccess(string.Format(Messages.RecordActivate, query.Count())); foreach (var entity in query) { entity.IsActive = true; _adminUserRepository.Update(entity); } _unitOfWork.Commit(); AdminUserCacheManager.ClearCache(); return(result); }
public Result Edit(int id, AdminUserDto dto) { dto.Id = id; var validator = new AdminUserValidator(_adminUserRepository); var result = validator.ValidateResult(dto); if (!result.Success) { return(result); } var entity = _adminUserRepository.AsNoTracking.Include(i => i.Roles) .FirstOrDefault(s => s.Id == dto.Id); if (entity == null) { return(new Result().SetBlankRedirect()); } Mapper.Map <AdminUser>(dto, entity); if (!string.IsNullOrEmpty(dto.Password)) { entity.Salt = SecurityHelper.GenerateSalt(); entity.Password = SecurityHelper.GenerateHash(dto.Password, entity.Salt); } _adminUserRepository.Update(entity); ChildRoleUpdate(entity, dto); _unitOfWork.Commit(); AdminUserCacheManager.ClearCache(); return(result.SetSuccess(Messages.RecordSaved)); }
public Result ExecuteAction(List <int> ids, int loggedInUserId) { var result = Validation(ids, loggedInUserId); if (!result.Success) { return(result); } var query = _adminUserRepository.AsNoTracking.Where(q => ids.Contains(q.Id)); result = new Result().SetSuccess($"Total {query.Count()} record(s) has been deactivate."); foreach (var entity in query) { entity.IsActive = false; _adminUserRepository.Update(entity); } _unitOfWork.Commit(); AdminUserCacheManager.ClearCache(); return(result); }
public Entity.ActionStatus Manage(Entity.AddAdminUserRequest request) { Entity.ActionStatus actionStatus = new ActionStatus(true); try { if (request.Id == null || request.Id == Guid.Empty) { var checkExisting = _adminUserRepository.FindBy(x => x.Email.Equals(request.Email) && x.IsActive && !x.IsDeleted).FirstOrDefault(); if (checkExisting == null) { var adminUser = Mapper.Configuration.Mapper.Map <Entity.AddAdminUserRequest, Model.AdminUser>(request); adminUser.CreatedBy = component.helper.SolutionConfiguration.CurrentUserId; adminUser.CreatedDate = DateTime.Now; adminUser.IsActive = true; adminUser.IsDeleted = false; adminUser.Guid = Guid.NewGuid(); adminUser.CompanyGuid = component.helper.SolutionConfiguration.CompanyId; actionStatus = _adminUserRepository.Insert(adminUser); actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.UserResponse>(actionStatus.Data); if (!actionStatus.Success) { _logger.Error($"Admin User is not added in solution database, Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } else { // _logger.Error($"AdminUser is not updated in solution database, Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Email Id Already Registered."; } } else { var oldAdminUser = _adminUserRepository.FindBy(x => x.Guid.Equals(request.Id)).FirstOrDefault(); if (oldAdminUser == null) { throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : AdminUser"); } else { var checkExisting = _adminUserRepository.FindBy(x => x.Email.Equals(request.Email) && x.IsActive && !x.IsDeleted && x.Guid != oldAdminUser.Guid).FirstOrDefault(); if (checkExisting == null) { var existingPassword = oldAdminUser.Password; var dbAdminUser = Mapper.Configuration.Mapper.Map(request, oldAdminUser); dbAdminUser.CreatedBy = oldAdminUser.CreatedBy; dbAdminUser.CreatedDate = oldAdminUser.CreatedDate; dbAdminUser.UpdatedDate = DateTime.Now; dbAdminUser.UpdatedBy = component.helper.SolutionConfiguration.CurrentUserId; dbAdminUser.CompanyGuid = component.helper.SolutionConfiguration.CompanyId; if (string.IsNullOrEmpty(dbAdminUser.Password)) { dbAdminUser.Password = existingPassword; } actionStatus = _adminUserRepository.Update(dbAdminUser); actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.UserResponse>(actionStatus.Data); if (!actionStatus.Success) { _logger.Error($"AdminUser is not updated in solution database, Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } else { actionStatus.Success = false; actionStatus.Message = "Email Id Already Registered With Another User."; } } } } catch (Exception ex) { _logger.Error(Constants.ACTION_EXCEPTION, "AdminUserManager.Manage " + ex); actionStatus.Success = false; actionStatus.Message = ex.Message; } return(actionStatus); }
public Entity.ActionStatus Manage(Entity.AddAdminUserRequest request) { Entity.ActionStatus actionStatus = new ActionStatus(true); try { if (request.Id == null || request.Id == Guid.Empty) { var checkExisting = _adminUserRepository.FindBy(x => x.Email.Equals(request.Email) && x.IsActive && !x.IsDeleted).FirstOrDefault(); if (checkExisting == null) { var adminUser = Mapper.Configuration.Mapper.Map <Entity.AddAdminUserRequest, Model.AdminUser>(request); adminUser.CreatedBy = SolutionConfiguration.CurrentUserId; adminUser.CreatedDate = DateTime.Now; adminUser.IsActive = true; adminUser.IsDeleted = false; adminUser.Guid = Guid.NewGuid(); adminUser.CompanyGuid = SolutionConfiguration.CompanyId; actionStatus = _adminUserRepository.Insert(adminUser); actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.UserResponse>(actionStatus.Data); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"Admin User is not added in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } else { // _logger.Error($"AdminUser is not updated in solution database, Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Email Id Already Registered."; } } else { var oldAdminUser = _adminUserRepository.FindBy(x => x.Guid.Equals(request.Id)).FirstOrDefault(); if (oldAdminUser == null) { throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : AdminUser"); } else { var dbAdminUser = Mapper.Configuration.Mapper.Map(request, oldAdminUser); dbAdminUser.CreatedBy = oldAdminUser.CreatedBy; dbAdminUser.CreatedDate = oldAdminUser.CreatedDate; dbAdminUser.UpdatedDate = DateTime.Now; dbAdminUser.UpdatedBy = SolutionConfiguration.CurrentUserId; dbAdminUser.CompanyGuid = SolutionConfiguration.CompanyId; actionStatus = _adminUserRepository.Update(dbAdminUser); actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.UserResponse>(actionStatus.Data); if (!actionStatus.Success) { _logger.ErrorLog(new Exception($"AdminUser is not updated in solution database, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = "Something Went Wrong!"; } } } } catch (Exception ex) { _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name); actionStatus.Success = false; actionStatus.Message = ex.Message; } return(actionStatus); }