Пример #1
0
        public async Task <IActionResult> GetAllDeliveries(string toWhom, DateTime when)
        {
            IActionResult result = null;
            IEnumerable <Models.Delivery> deliveries = null;
            int count = 0;

            if (string.IsNullOrEmpty(toWhom))
            {
                return(BadRequest($"The user {toWhom} is invalid (null or empty)"));
            }

            try
            {
                deliveries = await _repository.GetAllDeliveriesAsync(toWhom, when);

                count = deliveries?.Count() ?? 0;
                if (count == 0)
                {
                    result = NoContent();
                }
                else
                {
                    result = Ok(deliveries);
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new DeliveryDomainException("An error caused an exception", ex);
            }
        }