Пример #1
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."));
        }
Пример #2
0
        public async Task <ResultDto <ShowT> > GetAsync(int id)
        {
            var entity = await Repo.FindAsync(id);

            if (entity == null)
            {
                return(ResultDto <ShowT> .NotFound());
            }
            return(ResultDto <ShowT> .Succeed(EntityDto(entity)));
        }
Пример #3
0
        public async Task <ResultDto <ShowT> > DeleteAsync(int id)
        {
            var entity = await Repo.FindAsync(id);

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

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

            await Repo.DeleteAndSaveAsync(entity);

            return(ResultDto <ShowT> .Succeed(EntityDto(entity), $"{typeof(E).Name} #{entity.Id} deleted."));
        }