Example #1
0
        public ActionResult GenerateMenuOne(string txtCombinationDate)
        {
            int mealNumber = int.Parse(Request.Form["ddlMealNumbers"].ToString());
            List <Combination> combinationsList = SQLProcedures.GetSavedMealCombinations();

            combinationsList.Sort((x, y) => x.NumberOfMeals.CompareTo(y.NumberOfMeals));

            ViewBag.Combinations = new SelectList(combinationsList, "NumberOfMeals", "NumberOfMeals", mealNumber);

            if (txtCombinationDate != string.Empty)
            {
                DateTime combinationDate = DateTime.Parse(txtCombinationDate);
                ViewBag.CombinationDate = txtCombinationDate;

                if (!SQLProcedures.CheckSavedMenuForDate(Session["username"].ToString(), combinationDate))
                {
                    Session["mealNumber"]       = int.Parse(Request.Form["ddlMealNumbers"].ToString());
                    Session["selectedCombDate"] = txtCombinationDate;
                    return(GenerateMenuTwo());
                }
                else
                {
                    ViewBag.ShowError    = true;
                    ViewBag.ErrorMessage = "Jelovnik za odabrani datum već postoji!";
                    return(View());
                }
            }
            else
            {
                ViewBag.ShowError    = true;
                ViewBag.ErrorMessage = "Odaberite datum!";
                return(View());
            }
        }
Example #2
0
        public ActionResult GenerateMenuTwo(string submitButton, string txtCombinationDate)
        {
            if (submitButton == "Generiraj novi")
            {
                return(GenerateMenuTwo());
            }

            if (txtCombinationDate != string.Empty)
            {
                DateTime combinationDate = DateTime.Parse(txtCombinationDate);
                ViewBag.CombinationDate = txtCombinationDate;

                if (!SQLProcedures.CheckSavedMenuForDate(Session["username"].ToString(), combinationDate))
                {
                    User        user        = SQLProcedures.GetUser(Session["username"].ToString());
                    Combination combination = SQLProcedures.GetSavedCombination(int.Parse(Session["mealNumber"].ToString()));
                    double      totalKcal   = CalculateTotalKcal();

                    int menuID = SQLProcedures.InsertMenu(user.IDUser, combination.IDCombination, combinationDate, totalKcal);

                    List <MenuMealData> menuMealsList = (List <MenuMealData>)Session["menuMealsList"];
                    foreach (MenuMealData meal in menuMealsList)
                    {
                        SQLProcedures.InsertMealDataForMenu(menuID, meal.MealName, meal.CarbName, meal.CarbUnits, meal.FatName, meal.FatUnits, meal.ProteinName, meal.ProteinUnits);
                    }

                    Session["menuMealList"] = null;
                    return(RedirectToAction("GenerateMenuOne"));
                }
                else
                {
                    ViewBag.ShowError = true;
                    ViewBag.ErrorMsg  = "Jelovnik za odabrani datum već postoji!";
                    return(View());
                }
            }
            else
            {
                ViewBag.ShowError    = true;
                ViewBag.ErrorMessage = "Odaberite datum!";
                return(View());
            }
        }