예제 #1
0
 // POST: api/SoldProducts
 public void Post([FromBody] SoldProductModel product)
 {
     if (ModelState.IsValid)
     {
         ISoldProductModel model = product;
         soldProductData.Create(model);
     }
 }
예제 #2
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"));
            }
        }