示例#1
0
        // Form to edit a product
        public ActionResult Edit(int?id)
        {
            if (id != null)
            {
                try
                {
                    IProductModel product = productData.FindById((int)id);
                    ViewBag.CategoryID = new SelectList(categoryData.GetAll(), "ID", "Name", product.CategoryID);

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

                catch (Exception ex)
                {
                    log.Error("Could't find a product in the Database", ex);
                    return(View("ErrorRetriveData"));
                }
            }
            else
            {
                log.Error("The product ID was null while trying to edit");
                return(View("ErrorEdit"));
            }
        }
示例#2
0
 // GET: api/Products/5
 public IProductModel Get(int id)
 {
     if (productData.GetAll().Exists(x => x.ID == id))
     {
         return(productData.FindById(id));
     }
     else
     {
         return(null);
     }
 }
示例#3
0
        // Asks for confirmation in order to delete a table from the database
        public ActionResult Delete(int?id)
        {
            if (id != null)
            {
                try
                {
                    ITableModel table = tableData.FindById((int)id);

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

                    if (table.SoldProducts.Count > 0)
                    {
                        log.Info("The user tried to delete a table that was opened");
                        return(View("OpenedTable"));
                    }

                    return(View(table));
                }
                catch (Exception ex)
                {
                    log.Error("Could't find a table in the Database", ex);
                    return(View("ErrorRetriveData"));
                }
            }
            else
            {
                log.Error("The table ID was null while trying to delete");
                return(View("ErrorDelete"));
            }
        }
示例#4
0
        // Menu where is a table with its products and available categories of products
        public ActionResult TableCategories(int?id, string order)
        {
            if (id != null)
            {
                try
                {
                    // Joining list of categories and selected table to a single model
                    mainPageModel.Categories = categoryData.GetAll().OrderBy(x => x.Name).ToList();
                    ITableModel table = tableData.FindById((int)id);

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

                    // Selection of the order of the list
                    table.SoldProducts = MainMenuHelper.OrderListSoldProducts(table.SoldProducts, order);

                    mainPageModel.Tables.Add(table);
                }
                catch (Exception ex)
                {
                    log.Error("Could't load categories or tables from Database", ex);
                    return(View("ErrorRetriveData"));
                }

                return(View(mainPageModel));
            }
            else
            {
                log.Error("The table ID was null while trying to access");
                return(View("ErrorTable"));
            }
        }
示例#5
0
 // GET: api/Tables/5
 public ITableModel Get(int id)
 {
     if (tableData.GetAll().Exists(x => x.ID == id))
     {
         return(tableData.FindById(id));
     }
     else
     {
         return(null);
     }
 }
示例#6
0
        /// <summary>
        /// It maps an object of type ProductModel to SoldProductModel
        /// </summary>
        public static ISoldProductModel ProductToSoldProduct(IProductModel product, int idTable, IDataAccessSubCategory <ITableModel> tableData)
        {
            ISoldProductModel soldProduct = Factory.InstanceSoldProductModel();

            soldProduct.Name          = product.Name;
            soldProduct.Price         = product.Price;
            soldProduct.CategoryID    = product.CategoryID;
            soldProduct.TableID       = idTable;
            soldProduct.Detail        = "";
            soldProduct.Category.ID   = product.CategoryID;
            soldProduct.Category.Name = product.Category.Name;
            soldProduct.Table         = tableData.FindById(idTable);

            return(soldProduct);
        }
示例#7
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"));
            }
        }