public int Post([FromBody] ProductSaveModel model) { if (model == null) { return(0); } var product = _mapper.Map <ProductSaveModel, Product>(model); _context.Products.Add(product); _context.SaveChanges(); return(product.Id); }
public int Put([FromBody] ProductSaveModel model) { if (model == null) { return(0); } var productEntry = _context.Products.Find(model.Id); if (productEntry == null) { return(0); } productEntry.ProductName = model.ProductName; productEntry.CategoryId = model.CategoryId; _context.Products.Update(productEntry); _context.SaveChanges(); return(productEntry.Id); }