public bool AddProduct(DataModelResearch.Product product) { var newProduct = new EFModels.Product() { Name = product.Name, CategoryId = product.CategoryId, UnitPrice = product.UnitPrice }; _context.Product.Add(newProduct); _context.SaveChanges(); return(true); }
public void UpdateProduct(DataModelResearch.Product product) { var productToUpdate = _context.Product.FirstOrDefault(x => x.Id == product.Id); productToUpdate.Name = product.Name; productToUpdate.UnitPrice = product.UnitPrice; var newCategory = _context.Category.FirstOrDefault(x => x.Id == product.CategoryId); //productToUpdate.CategoryId = product.CategoryId; productToUpdate.Category = newCategory; _context.SaveChanges(); }