Exemplo n.º 1
0
        public ActionResult AcademyVotes(int year, AcademyChoiceViewModel academyChoice)
        {
            ViewBag.Year = year;
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(academyChoice.Php))
                {
                    List <CategoryNomineeModel> nomineesList;
                    Dictionary <string, CategoryNomineeModel> infos = FormatVotes.GetCategoriesFromPhp(academyChoice.Php, CategoriesBusinessCtrl.GetCategories(year), out nomineesList);

                    CategoriesBusinessCtrl.ReplaceCategoryNominees(year, nomineesList);
                }
                else
                {
                    if (!string.IsNullOrEmpty(academyChoice.AcademyVotes))
                    {
                        academyChoice.Categories = CategoriesBusinessCtrl.GetCategoriesWithNominees(year)
                                                   .Select(c => new CategoryViewModel {
                            Category = c
                        }).ToList();
                        var choices = academyChoice.AcademyVotes.Split(',');
                        if (choices != null && choices.Length == Calculation.NB_CATEGORIES)
                        {
                            for (int c = 0; c < choices.Length; c++)
                            {
                                CategoryModel category   = academyChoice.Categories[c].Category;
                                var           dbCategory = CategoriesBusinessCtrl.GetCategory(year, category.CategoryNb);
                                dbCategory.AcademyChoiceLetter = choices[c];
                                CategoriesBusinessCtrl.EditCategory(year, dbCategory);
                            }
                        }
                        else
                        {
                            foreach (CategoryViewModel category in academyChoice.Categories)
                            {
                                var dbCategory = CategoriesBusinessCtrl.GetCategory(year, category.Category.CategoryNb);
                                dbCategory.AcademyChoiceLetter = "";
                                CategoriesBusinessCtrl.EditCategory(year, dbCategory);
                            }
                        }
                    }
                    else
                    {
                        foreach (CategoryViewModel category in academyChoice.Categories)
                        {
                            var dbCategory = CategoriesBusinessCtrl.GetCategory(year, category.Category.CategoryNb);
                            dbCategory.AcademyChoiceLetter = category.Category.AcademyChoiceLetter;
                            CategoriesBusinessCtrl.EditCategory(year, dbCategory);
                        }
                    }
                }
                return(RedirectToAction("AcademyVotes"));
            }

            return(View(academyChoice));
        }
Exemplo n.º 2
0
        public ActionResult AcademyVotes(int year)
        {
            ViewBag.Year = year;
            AcademyChoiceViewModel model = new AcademyChoiceViewModel();

            model.Categories = CategoriesBusinessCtrl.GetCategoriesWithNominees(year)
                               .Select(c => new CategoryViewModel {
                Category = c
            }).ToList();

            foreach (var category in model.Categories)
            {
                category.Category.CategoryNominees.Insert(0, new CategoryNomineeModel {
                    Letter = "", Description = ""
                });
                category.CategoryNomineesSelectList = new SelectList(category.Category.CategoryNominees,
                                                                     "Letter", "Description",
                                                                     category.Category.AcademyChoiceLetter);

                model.AcademyVotes += (!string.IsNullOrEmpty(model.AcademyVotes) ? "," : "") + category.Category.AcademyChoiceLetter;
            }
            return(View(model));
        }