示例#1
0
        public async Task <ResultDto <ShowT> > CreateAsync(CreateT dto, Action <ValidationResult>?func = null)
        {
            var entity = Mapper.Map <E>(dto);
            var result = await CreateCallbackAsync(dto, entity);

            if (result != null)
            {
                return(result);
            }

            var validationResult = Validator.Validate(entity);

            if (!validationResult.IsValid)
            {
                if (func != null)
                {
                    func(validationResult);
                }
                return(ResultDto <ShowT> .Failed(validationResult.ToString()));
            }

            Repo.Insert(entity);
            await Uow.SaveChangesAsync();

            return(ResultDto <ShowT> .Succeed(EntityDto(entity), $"{typeof(E).Name} #{entity.Id} created."));
        }
示例#2
0
        public async Task <ResultDto <ShowT> > UpdateAsync(int id, UpdateT dto, Action <ValidationResult>?func = null)
        {
            var entity = await Repo.FindAsync(id);

            if (entity == null)
            {
                return(ResultDto <ShowT> .NotFound());
            }

            Mapper.Map(dto, entity);
            var result = await UpdateCallbackAsync(dto, entity);

            if (result != null)
            {
                return(result);
            }

            var validationResult = Validator.Validate(entity);

            if (!validationResult.IsValid)
            {
                if (func != null)
                {
                    func(validationResult);
                }
                return(ResultDto <ShowT> .Failed(validationResult.ToString()));
            }

            await Repo.UpdateAndSaveAsync(entity);

            return(ResultDto <ShowT> .Succeed(EntityDto(entity), $"{typeof(E).Name} #{entity.Id} updated."));
        }
示例#3
0
        public override async Task <ResultDto <BookDto> > DeleteCallbackAsync(Book entity)
        {
            await Task.Delay(0);

            return(ResultDto <BookDto> .Failed("delete failed"));
        }
示例#4
0
        public override async Task <ResultDto <BookDto> > UpdateCallbackAsync(BookCreateUpdateDto dto, Book entity)
        {
            await Task.Delay(0);

            return(ResultDto <BookDto> .Failed("update failed"));
        }