コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }