Пример #1
0
        public Result Edit(int Id, PageEditAdminDto dto)
        {
            dto.Id = Id;
            var result = _validatorEdit.ValidateResult(dto);

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

            var entity = _pageRepository.AsNoTracking.FirstOrDefault(w => w.Id == dto.Id);

            if (entity == null)
            {
                return(result.SetError("There are error for update record. Please try again with refresh."));
            }

            Mapper.Map <Page>(dto, entity);
            _pageRepository.Update(entity);
            _unitOfWork.Commit();

            result.Id = entity.Id;

            PageCacheManager.ClearCache();

            return(result.SetSuccess(Messages.RecordSaved));
        }
Пример #2
0
        public Result Create(PageCreateAdminDto dto)
        {
            var result = _validatorCreate.ValidateResult(dto);

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


            var entity = Mapper.Map <Page>(dto);

            _pageRepository.Insert(entity);
            _unitOfWork.Commit();

            result.Id = entity.Id;
            PageCacheManager.ClearCache();

            return(result.SetSuccess(Messages.RecordSaved));
        }