コード例 #1
0
ファイル: CommonUtils.cs プロジェクト: cgenin7/Jojoscar
        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
ファイル: CommonUtils.cs プロジェクト: cgenin7/Jojoscar
        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
ファイル: ResultController.cs プロジェクト: cgenin7/Jojoscar
        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
ファイル: ResultController.cs プロジェクト: cgenin7/Jojoscar
        private List <ResultModel> GetResults(int year, bool excludeNotEligibleForMoney)
        {
            List <ResultModel> results;

            var categories = CategoriesBusinessCtrl.GetCategories(year);

            var    guests        = GuestsBusinessCtrl.GetGuests(year);
            double amountToShare = Calculation.CalculateAmmountToShare(guests, categories);

            Calculation.CalculateResults(guests, categories, GetPercents(), out results, excludeNotEligibleForMoney);

            return(results);
        }
コード例 #6
0
ファイル: ResultController.cs プロジェクト: cgenin7/Jojoscar
        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));
        }