Exemplo n.º 1
0
        public ActionResult AddShipment([FromBody] Shipment shipment)
        {
            try
            {
                _shipmentService.AddShipment(shipment);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.GetBaseException().Message));
            }
        }
        public async Task <IActionResult> Post([FromBody] ProductShipments model)
        {
            var isSuccessResult = await _shipmentService.AddShipment(model);

            //check if returned result is guid or not
            //if guid it was successfull. Otherwise unsuccessfull
            Guid GuidOutput;
            bool isGuid = Guid.TryParse(isSuccessResult, out GuidOutput);

            if (!isGuid)
            {
                return(BadRequest(isSuccessResult));
            }
            else
            {
                //var NewUri = Url.Link("ProductGet",new{id = new Guid(isSuccessResult)});
                //return Created(NewUri,model);
                return(Ok());
            }
        }
        public HttpResponseMessage PostShipment(ShipmentRequestModel requestModel)
        {
            var createdShipmentResult =
                _shipmentService.AddShipment(requestModel.ToShipment());

            if (!createdShipmentResult.IsSuccess)
            {
                return(new HttpResponseMessage(HttpStatusCode.Conflict));
            }

            var response = Request.CreateResponse(HttpStatusCode.Created,
                                                  createdShipmentResult.Entity.ToShipmentDto());

            response.Headers.Location = new Uri(
                Url.Link(RouteName, new {
                key = createdShipmentResult.Entity.Key
            })
                );

            return(response);
        }
        public async Task <ActionResult> AddShipment(Shipment newShipment)
        {
            var result = await _shipmentService.AddShipment(newShipment);

            return(result == null?Conflict("Shipment with given ID already exists in database") : Ok());
        }