public void AddProduct(Product product)
 {
     _context.Products.Add(product);
 }
        private static ProductViewModel MapProductToModel(Product product)
        {
            ProductViewModel model = new ProductViewModel()
            {
                Id = product.Id,
                Name = product.Name,
                Price = product.Price,
                Manufacturer = product.Manufacturer,
                UnitMeasure = product.UnitMeasure,
                CategoryId = product.Category.Id,
                CategoryName = product.Category.Name
            };

            return model;
        }
 public void UpdateProduct(Product product)
 {
     var oldProduct = GetSingleActiveProductOrNull(product.Id);
     if (oldProduct != null)
     {
         oldProduct.Name = product.Name;
         Category cat = GetSingleActiveCategoryOrNull(product.CategoryId);
         if (cat == null)
         {
             //Somehow an invalid category was selected
             throw new InvalidOperationException("Invalid category provided for the product");
         }
         oldProduct.Category = cat;
         oldProduct.Manufacturer = product.Manufacturer;
         oldProduct.Price = product.Price;
         oldProduct.UnitMeasure = product.UnitMeasure;
     }
     else
     {
         throw new InvalidOperationException("The product for edit does not exist or is not in use");
     }
 }
 private static Product MapModelToProduct(ProductViewModel model, bool isActive = true)
 {
     Product result = new Product()
     {
         Id = model.Id,
         Name = model.Name,
         Manufacturer = model.Manufacturer,
         Price = model.Price,
         UnitMeasure = model.UnitMeasure,
         CategoryId = model.CategoryId,
         IsActive = isActive,
     };
     return result;
 }