Esempio n. 1
0
        public void RemoveProduct(int id)
        {
            Entities.Product product = _context.Product.Find(id);

            if (product != null)
            {
                _context.Product.Remove(product);

                Log.Information($"Product with Id {product.ProductId} has been deleted.");
            }
            else
            {
                Log.Error($"Product with Id {id} could not be removed because it does not exist.");
            }
        }
Esempio n. 2
0
        public void UpdateProduct(Product product)
        {
            Entities.Product currentProduct = _context.Product.Find(product.ProductId);

            if (currentProduct != null)
            {
                Entities.Product newProduct = Mapper.MapProduct(product);

                _context.Entry(currentProduct).CurrentValues.SetValues(newProduct);

                Log.Information($"Product with Id {product.ProductId} has been updated.");
            }
            else
            {
                Log.Error($"Product with Id {product.ProductId} could not be updated because it does not exist.");
            }
        }
Esempio n. 3
0
 public void AddProduct(Product product)
 {
     Entities.Product newProduct = Mapper.MapProduct(product);
     _context.Product.Add(newProduct);
 }