예제 #1
0
        public static List <CategoryViewModel> BuildStatisticViewModel(int year, List <GuestModel> statsByLetter)
        {
            var categories = CategoriesBusinessCtrl.GetCategoriesWithNominees(year)
                             .Select(c => new CategoryViewModel {
                Category = c
            }).ToList();

            foreach (var statForALetter in statsByLetter)
            {
                List <string> counts = statForALetter.GetVotes();

                for (int c = 0; c < categories.Count; c++)
                {
                    int count = 0;
                    int.TryParse(counts[c], out count);
                    categories[c].NbVotesForEachNominee.Add(count);
                }
            }

            foreach (var category in categories)
            {
                category.MaxVotes = category.NbVotesForEachNominee.Max();
            }

            return(categories);
        }
예제 #2
0
        public static GuestViewModel BuildGuestViewModel(int year, GuestModel guest)
        {
            var guestViewModel = new GuestViewModel();

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

            var votes = guestViewModel.Guest.GetVotes();

            if (votes != null && votes.Count == Calculation.NB_CATEGORIES)
            {
                for (int i = 0; i < guestViewModel.Categories.Count; i++)
                {
                    guestViewModel.Categories[i].SelectedLetter = votes[i];
                    if (guestViewModel.Categories[i].Category.AcademyChoiceLetter == votes[i])
                    {
                        guestViewModel.TotalNbPoints += guestViewModel.Categories[i].Category.NbPoints;
                        guestViewModel.TotalNbResponses++;
                    }
                }
            }
            return(guestViewModel);
        }
예제 #3
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));
        }
예제 #4
0
        public ActionResult GenerateVoteFile(int year)
        {
            ViewBag.Year = year;
            var guests = GuestsBusinessCtrl.GetGuests(year);

            FormatVotes.CreateDoc("D:\\Votes" + year + ".doc", CategoriesBusinessCtrl.GetCategoriesWithNominees(year),
                                  guests);

            return(View("Index", guests));
        }
예제 #5
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));
        }