예제 #1
0
        public Result UpdateProfile(MemberFrontDto dto, int memberId)
        {
            var result = _memberUpdateValidator.ValidateResult(dto);

            if (!result.Success)
            {
                return(result);
            }

            var query = _memberRepository.AsNoTracking.Where(x => x.Id == memberId);

            query.Update(u => new Member
            {
                Name         = dto.Name,
                Phone        = dto.Phone,
                AddressLine1 = dto.AddressLine1,
                AddressLine2 = dto.AddressLine2,
                City         = dto.City,
                State        = dto.State,
                Degree       = dto.Degree,
                College      = dto.College,
                LastSemMark  = dto.LastSemMark,
                Experience   = dto.Experience
            });

            MemberCacheManager.ClearCache();
            result.SetSuccess("Your account updated successfully.");

            return(result);
        }
예제 #2
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));
        }
예제 #3
0
        public Result GuestUpdatePassword(MemberGuestDto dto, int memberId)
        {
            var validator = new MemberGuestValidator();
            var result    = validator.ValidateResult(dto);

            if (!result.Success)
            {
                return(result);
            }

            var strSalt     = SecurityHelper.GenerateSalt();
            var strPassword = SecurityHelper.GenerateHash(dto.Password, strSalt);

            var query = _memberRepository.AsNoTracking.Where(x => x.Id == memberId);

            query.Update(u => new Member {
                Password = strPassword, Salt = strSalt, IsActive = true
            });

            MemberCacheManager.ClearCache();
            result.Id = memberId;

            return(result.SetSuccess(Messages.RecordSaved));
        }
예제 #4
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));
        }