public Result Edit(int id, MemberDto dto) { dto.Id = id; var validator = new MemberValidator(_memberRepository); var result = validator.ValidateResult(dto); if (!result.Success) { return(result); } var entity = _memberRepository.AsNoTracking .FirstOrDefault(s => s.Id == dto.Id); if (entity == null) { return(new Result().SetBlankRedirect()); } Mapper.Map <Member>(dto, entity); if (!string.IsNullOrEmpty(dto.Password)) { entity.Salt = SecurityHelper.GenerateSalt(); entity.Password = SecurityHelper.GenerateHash(dto.Password, entity.Salt); } _memberRepository.Update(entity); _unitOfWork.Commit(); MemberCacheManager.ClearCache(); return(result.SetSuccess(Messages.RecordSaved)); }
public Result Create(MemberDto dto) { var validator = new MemberValidator(_memberRepository); var result = validator.ValidateResult(dto); if (!result.Success) { return(result); } dto.CreatedSource = (int)MemberCreatedSource.Admin; var entity = Mapper.Map <Member>(dto); entity.Salt = SecurityHelper.GenerateSalt(); entity.Password = SecurityHelper.GenerateHash(dto.Password, entity.Salt); entity.IsActive = true; entity.LastLoginAt = DateTime.Now; _memberRepository.Insert(entity); _unitOfWork.Commit(); MemberCacheManager.ClearCache(); result.Id = entity.Id; return(result.SetSuccess(Messages.RecordSaved)); }