コード例 #1
0
 public ActionResult Edit([Bind(Include = "ID,Name,CategoryID,Price")] ProductModel product)
 {
     if (ModelState.IsValid)
     {
         try
         {
             // Checking if already exist a product with same name that is not the one selected (case insensitive)
             if (productData.CheckIfAlreadyExist(product.Name) == false ||
                 productData.FindById(product.ID).Name == product.Name)
             {
                 IProductModel model = product;
                 productData.Update(model);
                 return(RedirectToAction("Index"));
             }
             else
             {
                 log.Info("The user tried to add a product that already existed");
                 return(View("AlreadyExists"));
             }
         }
         catch (Exception ex)
         {
             log.Error("Could't edit a product from Database", ex);
             return(View("ErrorRetriveData"));
         }
     }
     else
     {
         log.Error("The model state of the product is invalid");
         return(View("ErrorEdit"));
     }
 }
コード例 #2
0
 // PUT: api/Tables/5
 public void Put([FromBody] TableModel table)
 {
     if (ModelState.IsValid)
     {
         ITableModel model = table;
         tableData.Update(model);
     }
 }
コード例 #3
0
        public ActionResult TableAddProduct(int?idTable, int?idCategory, int?idProduct)
        {
            if (idProduct != null)
            {
                try
                {
                    // Finding the selected product and the table where is going to be added
                    ITableModel   table   = tableData.FindById((int)idTable);
                    IProductModel product = productData.FindById((int)idProduct);

                    if (product == null)
                    {
                        log.Error("Could't find a product in the Database - return null");
                        return(View("ErrorAddProduct"));
                    }

                    // Creates a SoldProductModel from a ProductModel that can be added to a list in each TableModel
                    ISoldProductModel soldProduct = MappingObjects.ProductToSoldProduct(product, (int)idTable, tableData);
                    soldProductData.Create(soldProduct);

                    // Sets the current table as opened (Occupied by products)
                    table.Occupied = true;
                    tableData.Update(table);
                    table.SoldProducts = soldProductData.GetByTable(table.ID);

                    // Joins list of products and selected table to a single model
                    mainPageModel.Products = productData.GetBySubGroup((int)idCategory).OrderBy(x => x.Name).ToList();;
                    mainPageModel.Tables.Add(table);
                }
                catch (Exception ex)
                {
                    log.Error("Could't load products, sold products or tables from Database", ex);
                    return(View("ErrorRetriveData"));
                }

                return(View(mainPageModel));
            }
            else
            {
                log.Error("The product ID was null while trying to access");
                return(View("ErrorAddProduct"));
            }
        }
コード例 #4
0
 // PUT: api/Products/5
 public void Put([FromBody] ProductModel product)
 {
     if (ModelState.IsValid)
     {
         if (productData.CheckIfAlreadyExist(product.Name) == false ||
             productData.FindById(product.ID).Name == product.Name)
         {
             IProductModel model = product;
             productData.Update(model);
         }
     }
 }