Пример #1
0
        public static void DeleteProduct(int productID)
        {
            EditableProduct product = GetEditableProduct(productID);

            if (product != null)
            {
                GetEditableProducts().Remove(product);
            }
        }
        public ActionResult EditingEdit(int productID)
        {
            EditableProduct editProduct = NorthwindDataProvider.GetEditableProduct(productID);

            if (editProduct == null)
            {
                editProduct           = new EditableProduct();
                editProduct.ProductID = -1;
            }
            return(DemoView("Editing", "EditingForm", editProduct));
        }
Пример #3
0
        public static void InsertProduct(EditableProduct product)
        {
            EditableProduct editProduct = new EditableProduct();

            editProduct.ProductID       = GetNewEditableProductID();
            editProduct.ProductName     = product.ProductName;
            editProduct.CategoryID      = product.CategoryID;
            editProduct.QuantityPerUnit = product.QuantityPerUnit;
            editProduct.UnitPrice       = product.UnitPrice;
            editProduct.UnitsInStock    = product.UnitsInStock;
            editProduct.Discontinued    = product.Discontinued;
            GetEditableProducts().Add(editProduct);
        }
Пример #4
0
        public static void UpdateProduct(EditableProduct product)
        {
            EditableProduct editProduct = GetEditableProduct(product.ProductID);

            if (editProduct != null)
            {
                editProduct.ProductName     = product.ProductName;
                editProduct.CategoryID      = product.CategoryID;
                editProduct.QuantityPerUnit = product.QuantityPerUnit;
                editProduct.UnitPrice       = product.UnitPrice;
                editProduct.UnitsInStock    = product.UnitsInStock;
                editProduct.Discontinued    = product.Discontinued;
            }
        }
        public ActionResult EditingEdit(EditableProduct product)
        {
            if (!ModelState.IsValid)
            {
                return(DemoView("Editing", "EditingForm", product));
            }

            if (product.ProductID == -1)
            {
                NorthwindDataProvider.InsertProduct(product);
            }
            else
            {
                NorthwindDataProvider.UpdateProduct(product);
            }
            return(RedirectToAction("Editing"));
        }
Пример #6
0
 public ActionResult InlineEditingAddNewPartial(EditableProduct product)
 {
     if (ModelState.IsValid)
     {
         try {
             NorthwindDataProvider.InsertProduct(product);
         }
         catch (Exception e) {
             ViewData["EditError"] = e.Message;
         }
     }
     else
     {
         ViewData["EditError"] = "Please, correct all errors.";
     }
     return(PartialView("InlineEditingPartial", NorthwindDataProvider.GetEditableProducts()));
 }
Пример #7
0
 public static void UpdateProduct(EditableProduct product) {
     EditableProduct editProduct = GetEditableProduct(product.ProductID);
     if(editProduct != null) {
         editProduct.ProductName = product.ProductName;
         editProduct.CategoryID = product.CategoryID;
         editProduct.QuantityPerUnit = product.QuantityPerUnit;
         editProduct.UnitPrice = product.UnitPrice;
         editProduct.UnitsInStock = product.UnitsInStock;
         editProduct.Discontinued = product.Discontinued;
     }
 }
Пример #8
0
 public static void InsertProduct(EditableProduct product) {
     EditableProduct editProduct = new EditableProduct();
     editProduct.ProductID = GetNewEditableProductID();
     editProduct.ProductName = product.ProductName;
     editProduct.CategoryID = product.CategoryID;
     editProduct.QuantityPerUnit = product.QuantityPerUnit;
     editProduct.UnitPrice = product.UnitPrice;
     editProduct.UnitsInStock = product.UnitsInStock;
     editProduct.Discontinued = product.Discontinued;
     GetEditableProducts().Add(editProduct);
 }