public IActionResult Post([FromBody] ProductViewModel product) { if (product == null) { return(BadRequest("objeto nulo")); } var p = new Product(product.Name, product.Description, product.Price); _repository.Add(p); _repository.Save(); return(Created("api/v1/product", p)); }
//sirve para crear o actualizar productos public async Task <ServiceResponse> Save(SaveProductRequest rq) { var sr = new ServiceResponse(); try { sr.Data = await _repositoryProduct.Save(_mapper.Map <Product>(rq)); } catch (Exception ex) { sr.AddError(ex); } return(sr); }
/// <summary> /// POST /products /// returns HTTP Response => /// 201 Created /// Location: http://localhost/products/{newProductGuid} /// {newMovie DTO in [xml|json|jsv|etc]} /// </summary> public object Post(Product product) { var vendorModel = VendorRepository.GetById(product.Vendor.Guid); var productModel = product.ToProductModel(vendorModel); ProductRepository.Save(productModel); var p = ProductRepository.GetById(productModel.ProductId.ToString()); var newProduct = new ProductResponse { Product = p.ToProduct() }; return(new HttpResult(newProduct) { StatusCode = HttpStatusCode.Created, Headers = { { HttpHeaders.Location, base.Request.AbsoluteUri.CombineWith(newProduct.Product.Guid) } } }); }