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.")); }
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.")); }
public override async Task <ResultDto <BookDto> > DeleteCallbackAsync(Book entity) { await Task.Delay(0); return(ResultDto <BookDto> .Failed("delete failed")); }
public override async Task <ResultDto <BookDto> > UpdateCallbackAsync(BookCreateUpdateDto dto, Book entity) { await Task.Delay(0); return(ResultDto <BookDto> .Failed("update failed")); }