Пример #1
0
        public async Task <BaseResponse <Food> > Handle(DeleteFoodCommand request, CancellationToken cancellationToken)
        {
            var response = new BaseResponse <Food> ()
            {
                ReponseName = nameof(DeleteFoodCommand), Content = new List <Food> ()
                {
                }
            };
            var entity = await _foodRepository.GetOneAsync(p => p.Id == request.Id);

            if (entity == null)
            {
                response.Status  = ResponseType.Error;
                response.Message = $"{nameof(Food)} not found.";
                response.Content = null;
            }
            else
            {
                await _foodRepository.DeleteAsync(entity);

                response.Status  = ResponseType.Success;
                response.Message = $"{nameof(Food)} deleted successfully.";
                response.Content.Add(entity);
            }
            return(response);
        }
        public async Task <IResult> DeleteAsync(long id)
        {
            await _foodRepository.DeleteAsync(id);

            await _unitOfWork.SaveChangesAsync();

            return(Result.Success());
        }
Пример #3
0
        public async Task <IActionResult> Delete([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var food = _foodRepository.DeleteAsync(id);

            return(Ok(food.Result));
        }
Пример #4
0
        public async Task <IHttpActionResult> DeleteAsync(int foodId)
        {
            var food = await _foodRepository.FindByIdAsync(foodId);

            if (food != null)
            {
                await _foodRepository.DeleteAsync(food.Id);

                try
                {
                    await _foodRepository.SaveChangedAsync();
                }
                catch (RepositoryException)
                {
                    return(BadRequest());
                }

                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }
Пример #5
0
        public async Task DeleteFoodAsync(int id)
        {
            await _foodRepository.DeleteAsync(id);

            await _unitOfWork.CommitAsync();
        }
Пример #6
0
        /// <inheritdoc />
        public async Task DeleteAsync(long id)
        {
            await _repo.DeleteAsync(id);

            await _repo.SaveAsync();
        }
Пример #7
0
        public async Task DeleteAsync(Guid id)
        {
            var @food = await _foodRepository.GetOrFailAsync(id);

            await _foodRepository.DeleteAsync(@food);
        }