Exemplo n.º 1
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"));
            }
        }