コード例 #1
0
        public async Task <ActionResult> DeclineAdoptOrder(BookOrderForDeclineDto adoptOrder)
        {
            if (adoptOrder == null)
            {
                return(BadRequest());
            }
            try
            {
                await _bookOrderService.DeclineBookOrder(adoptOrder);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #2
0
ファイル: BookOrderService.cs プロジェクト: yakubovych/PetUA
        public async Task DeclineBookOrder(BookOrderForDeclineDto order)
        {
            var bookOrder = _bookOrderRepository.Entities.FirstOrDefault(x => x.Id == order.Id);
            var animal    = _animalRepository.Entities.FirstOrDefault(x => x.Id == bookOrder.AnimalId);

            if (OrderStatus.Declined == bookOrder.Status)
            {
                throw new ObjectException(nameof(bookOrder.AnimalId), "animal is declined already");
            }

            if (bookOrder == null || bookOrder.Status == OrderStatus.Declined)
            {
                throw new ObjectNotFoundException("Threre isn't book order or it's declined already");
            }

            animal.Status = AnimalStatus.None;
            _animalRepository.Update(animal);

            _mapper.Map(order, bookOrder);
            bookOrder.Status      = OrderStatus.Declined;
            bookOrder.ClosingDate = DateTime.Now;
            _bookOrderRepository.Update(bookOrder);
            await _bookOrderRepository.SaveAsync();
        }