Esempio n. 1
0
        public HttpResponseMessage PutProduct([FromUri] int id, ProductVm model)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <string> errors = ModelState.Values.SelectMany(e => e.Errors).Select(e => e.ErrorMessage);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, String.Join(",", errors)));
            }

            Product product = uow.ProductManager.GetEntity(id);

            if (product == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "product not found"));
            }
            Product prod = Mapper.Map <ProductVm, t>(model);

            prod.Id = product.Id;
            uow.UpdateProduct(prod);
            var    response = Request.CreateResponse(HttpStatusCode.OK, new { status = true, message = "product updated successfully" });
            string uri      = Url.Link("GetProduct", new { id = prod.Id });

            response.Headers.Location = new Uri(uri);
            return(response);
            // return Ok(new { status = true, message = "product updated successfully" });
        }