public IActionResult Post([FromBody] ProductModifyDto product) { var model = AutoMapper.Mapper.Map <Product>(product); var createdProduct = _productsService.Add(model); var productDto = AutoMapper.Mapper.Map <ProductDto>(createdProduct); return(CreatedAtRoute("GetProduct", new { id = productDto.Id }, productDto)); }
public ActionResult Create(IFormCollection collection) { try { WebShopLibrary.Models.Products product = new WebShopLibrary.Models.Products(); product.ProductName = collection["ProductName"]; product.ProductNumber = Convert.ToInt32(collection["ProductNumber"]); product.ProductDescription = collection["ProductDescription"]; product.QuantityUnit = Convert.ToInt64(collection["QuantityUnit"]); product.UnitPrice = Convert.ToInt64(collection["UnitPrice"]); product.Discount = Convert.ToInt32(collection["Discount"]); // TODO: Add insert logic here _productsService.Add(product); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }