Ejemplo n.º 1
0
        public async Task <ActionResult> DeclineAdoptOrder(AdoptOrderForDeclineDto adoptOrder)
        {
            if (adoptOrder == null)
            {
                return(BadRequest());
            }
            try
            {
                await _adoptOrderService.DeclineAdoptOrder(adoptOrder);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task DeclineAdoptOrder(AdoptOrderForDeclineDto order)
        {
            var adoptOrder = _adoptOrderRepository.Entities.FirstOrDefault(x => x.Id == order.Id);
            var animal     = _animalRepository.Entities.FirstOrDefault(x => x.Id == adoptOrder.AnimalId);

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

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

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

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