Esempio n. 1
0
        // Menu where is a table with its products and available products do add a from selected category
        public ActionResult TableProducts(int?idTable, int?idCategory)
        {
            if (idCategory != null)
            {
                try
                {
                    // Joining list of products and selected table to a single model
                    ITableModel table = tableData.FindById((int)idTable);
                    mainPageModel.Tables.Add(table);

                    mainPageModel.Products = productData.GetBySubGroup((int)idCategory).OrderBy(x => x.Name).ToList();
                }
                catch (Exception ex)
                {
                    log.Error("Could't load products or tables from Database", ex);
                    return(View("ErrorRetriveData"));
                }

                return(View(mainPageModel));
            }
            else
            {
                log.Error("The category ID was null while trying to access");
                return(View("ErrorCategory"));
            }
        }
Esempio n. 2
0
        // Lists the products that belong to a selected category
        public ActionResult ProductsByCategory(int?id)
        {
            if (id == null)
            {
                log.Error("The category ID was null while trying to load products");
                return(View("ErrorAccessCategory"));
            }

            try
            {
                return(View(productData.GetBySubGroup((int)id).OrderBy(x => x.Name)));
            }
            catch (Exception ex)
            {
                log.Error("Could't load products of a category from Database", ex);
                return(View("ErrorRetriveData"));
            }
        }
Esempio n. 3
0
        // Lists the tables that belong to a selected area
        public ActionResult TablesByArea(int?id)
        {
            if (id == null)
            {
                log.Error("The area ID was null while trying to load tables");
                return(View("ErrorAccessArea"));
            }

            try
            {
                return(View(tableData.GetBySubGroup((int)id)));
            }
            catch (Exception ex)
            {
                log.Error("Could't load tables of a area from Database", ex);
                return(View("ErrorRetriveData"));
            }
        }
Esempio n. 4
0
        // Asks for confirmation in order to delete an area from the database
        public ActionResult Delete(int?id)
        {
            if (id != null)
            {
                try
                {
                    IAreaModel area = areaData.FindById((int)id);

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

                    // It gets the number of tables in selected area in order to display to the user
                    List <ITableModel> tables = tableData.GetBySubGroup((int)id);
                    area.NumberOfTables = tables.Count();

                    foreach (ITableModel table in tables)
                    {
                        if (table.Occupied)
                        {
                            log.Info("The user tried to delete an area with opened tables");
                            return(View("OpenedTable"));
                        }
                    }

                    return(View(area));
                }

                catch (Exception ex)
                {
                    log.Error("Could't find an area in the Database", ex);
                    return(View("ErrorRetriveData"));
                }
            }
            else
            {
                log.Error("The area ID was null while trying to delete");
                return(View("ErrorDelete"));
            }
        }
Esempio n. 5
0
        // Asks for confirmation in order to delete a category from the database
        public ActionResult Delete(int?id)
        {
            if (id != null)
            {
                try
                {
                    ICategoryModel category = categoryData.FindById((int)id);

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

                    // Checking if the category to delete doesn't have products on the tables or alredy sold
                    if (soldProductData.GetByCategory((int)id).Count() > 0 ||
                        soldProductAccomplishedData.GetByCategory((int)id).Count > 0)
                    {
                        log.Info("The user tried to delete a category with products in opened tables");
                        return(View("OpenedTables"));
                    }

                    // Getting the number of products in category in order to display to user
                    category.NumberOfProducts = productData.GetBySubGroup((int)id).Count();

                    return(View(category));
                }
                catch (Exception ex)
                {
                    log.Error("Could't find a category in the Database", ex);
                    return(View("ErrorRetriveData"));
                }
            }
            else
            {
                log.Error("The category ID was null while trying to delete");
                return(View("ErrorDelete"));
            }
        }