public string AddNewProduct(string data)
        {
            string result = "";
            try
            {
                Products product = new Products();
                product.ProductName = data.Split(';')[0].ToString();
                product.SupplierID = Convert.ToInt32(data.Split(';')[1].ToString());
                product.CategoryID = Convert.ToInt32(data.Split(';')[2].ToString());
                product.QuantityPerUnit = data.Split(';')[3].ToString();
                product.UnitPrice = Convert.ToDecimal(data.Split(';')[4].ToString());
                product.UnitsInStock = Convert.ToInt16(data.Split(';')[5].ToString());
                product.UnitsOnOrder = Convert.ToInt16(data.Split(';')[6].ToString());
                product.ReorderLevel = Convert.ToInt16(data.Split(';')[7].ToString());

                if (data.Split(';')[8].ToString() == "1")
                {
                    product.Discontinued = true;
                }
                else if (data.Split(';')[8].ToString() == "0")
                {
                    product.Discontinued = false;
                }

                ProductOperation productOperation = new ProductOperation();
                result = productOperation.InsertProduct(product);
            }
            catch (Exception)
            {

                result = "An error occurred during this operation.";
            }

            return result;
        }
 public string DeleteProduct(int id)
 {
     string result = "";
     Products product = new Products();
     using (NORTHWNDEntities context = new NORTHWNDEntities())
     {
         try
         {
             product = context.Products.FirstOrDefault(p => p.ProductID == id);
             context.Products.Remove(product);
             context.SaveChanges();
             result = "The record has deleted succesfully.";
         }
         catch (Exception ex)
         {
             result = "An error occurred during this operation.";
         }
     }
     return result;
 }
        public string InsertProduct(Products product)
        {
            string result = "";
            using (NORTHWNDEntities ent = new NORTHWNDEntities())
            {
                try
                {
                    ent.Products.Add(product);
                    ent.SaveChanges();
                    result = "The product has added successfully";
                }
                catch (Exception)
                {
                    result = "An error occurred during this operation.";
                }

            }
            return result;
        }
 public string UpdateProduct(Products product, int id)
 {
     string result = "";
     using (NORTHWNDEntities context = new NORTHWNDEntities())
     {
         Products currentproduct = new Products();
         try
         {
             currentproduct = context.Products.FirstOrDefault(p => p.ProductID == id);
             currentproduct.ProductName = product.ProductName;
             currentproduct.CategoryID = product.CategoryID;
             currentproduct.SupplierID = product.SupplierID;
             currentproduct.QuantityPerUnit = product.QuantityPerUnit;
             currentproduct.UnitPrice = product.UnitPrice;
             currentproduct.UnitsInStock = product.UnitsInStock;
             currentproduct.UnitsOnOrder = product.UnitsOnOrder;
             currentproduct.ReorderLevel = product.ReorderLevel;
             currentproduct.Discontinued = product.Discontinued;
             context.SaveChanges();
             result = "The record has updated succesfully.";
         }
         catch (Exception ex)
         {
             result = "An error occurred during this operation.";
         }
     }
     return result;
 }