예제 #1
0
        public async Task <IActionResult> SaveDelivery(Models.Delivery delivery)
        {
            try
            {
                IActionResult result = null;

                if (delivery == null)
                {
                    return(BadRequest($"The delivery is invalid (null)"));
                }
                if (string.IsNullOrEmpty(delivery.Id))
                {
                    return(BadRequest($"The delivery id is invalid (null or empty)"));
                }

                if (await _repository.GetDeliveryByIdAsync(delivery.Id) == null)
                {
                    result = this.CreatedAtRoute(
                        routeName: "Default",
                        value: await _repository.AddDeliveryAsync(delivery)
                        );
                }
                else
                {
                    result = BadRequest($"The delivery with {delivery.Id} already exists");
                }

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