Esempio n. 1
0
        public async Task<HttpResponseMessage> Post(SupplierRequestModel requestModel)
        {
            var postResult = await _supplierService.AddSupplier(requestModel.ToSupplier());

            if (!postResult.IsSuccess)
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);

            var response = Request.CreateResponse(HttpStatusCode.Created, postResult.Entity.ToSupplierDto());

            response.Headers.Location = new Uri(Url.Link("GetSupplierById", new { id = postResult.Entity.SupplierID }));

            return response;
        }
Esempio n. 2
0
        public async Task<HttpResponseMessage> Put(int id, SupplierRequestModel requestModel)
        {
            var supplier = await _supplierService.GetSupplier(id);

            if (supplier == null)
                return new HttpResponseMessage(HttpStatusCode.NotFound);

            requestModel.SupplierID = id;

            var putResult = await _supplierService.EditSupplier(requestModel.ToSupplier());

            if (!putResult.IsSuccess)
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);

            var response = Request.CreateResponse(HttpStatusCode.OK, putResult.Entity.ToSupplierDto());

            response.Headers.Location = new Uri(Url.Link("GetSupplierById", new { id = putResult.Entity.SupplierID }));

            return response;
        }