public ActionResult ByCategory(int?id) { ContestCategoryViewModel contestCategory; if (id.HasValue) { contestCategory = this.Data.ContestCategories .All() .Where(cc => cc.Id == id && !cc.IsDeleted && cc.IsVisible) .OrderBy(cc => cc.OrderBy) .Select(ContestCategoryViewModel.FromContestCategory) .FirstOrDefault(); } else { contestCategory = new ContestCategoryViewModel { CategoryName = Resource.Main_categories, Contests = new HashSet <ContestViewModel>(), SubCategories = this.Data.ContestCategories .All() .Where(cc => cc.IsVisible && !cc.IsDeleted && cc.Parent == null) .OrderBy(cc => cc.OrderBy) .Select(ContestCategoryListViewModel.FromCategory) }; } if (contestCategory == null) { throw new HttpException((int)HttpStatusCode.NotFound, Resource.Category_not_found); } foreach (var contest in contestCategory.Contests) { contest.UserIsAdminOrLecturerInContest = this.UserProfile != null && this.CheckIfUserHasContestPermissions(contest.Id); contest.UserCanCompete = this.UserProfile != null && this.contestsBusiness.CanUserCompeteByContestByUserAndIsAdmin( contest.Id, this.UserProfile.Id, this.User.IsAdmin()); contest.UserIsParticipant = this.UserProfile != null && this.contestsData.IsUserParticipantInByContestAndUser(contest.Id, this.UserProfile.Id); } contestCategory.IsUserLecturerInContestCategory = this.UserProfile != null && this.CheckIfUserHasContestCategoryPermissions(contestCategory.Id); if (this.Request.IsAjaxRequest()) { this.ViewBag.IsAjax = true; return(this.PartialView(contestCategory)); } this.ViewBag.IsAjax = false; return(this.View(contestCategory)); }
private ContestCategoryViewModel GetContestCategoryFromCache(int?id) { var contestCategory = new ContestCategoryViewModel { Id = id ?? default(int), CategoryName = Resource.Main_categories }; if (id.HasValue) { var categoryName = this.cacheItems.GetContestCategoryName(id.Value); if (categoryName == null) { return(null); } contestCategory.CategoryName = categoryName; } if (!contestCategory.SubCategories.Any()) { contestCategory.SubCategories = this.cacheItems.GetContestSubCategoriesList(id); } return(contestCategory); }
public ActionResult EditEntry(int contestId, string email, string code) { EditContestEntryViewModel viewModel = new EditContestEntryViewModel(); viewModel.ContestEntry = this._contestRepository.GetContestEntry(contestId, email, code); if (viewModel.ContestEntry != null && viewModel.ContestEntry.Email == email && viewModel.ContestEntry.VerificationCode == code) { viewModel.ContestEntryId = viewModel.ContestEntry.Id; viewModel.Contest = this._contestRepository.GetContest(viewModel.ContestEntry.ContestId); viewModel.Categories = new List <ContestCategoryViewModel>(); foreach (var category in viewModel.Contest.AcademyAwardsCategories) { ContestCategoryViewModel cat = new ContestCategoryViewModel(); cat.CategoryId = category.Id; cat.CategoryTitle = category.CategoryTitle; cat.SortOrder = category.SortOrder; cat.Nominees = new List <ContestNomineeViewModel>(); var selection = viewModel.ContestEntry.AcademyAwardsContestEntrySelections.FirstOrDefault(c => c.AcademyAwardsCategoryId == category.Id); if (selection != null) { cat.SelectedNomineeId = selection.SelectedAcademyAwardNomineeId; } foreach (var nominee in category.AcademyAwardsNominees) { cat.Nominees.Add(new ContestNomineeViewModel() { NomineeId = nominee.Id, NomineeText = nominee.NomineeText, SortOrder = nominee.SortOrder }); } viewModel.Categories.Add(cat); } return(View(viewModel)); } else { Danger("Invalid verification code and email address. Click the link sent to your email or submit a new contest entry", true); } return(RedirectToAction("Index", "Contest")); }
public ActionResult ByCategory(int?id) { ContestCategoryViewModel contestCategory; if (id.HasValue) { contestCategory = this.Data.ContestCategories .All() .Where(x => x.Id == id && !x.IsDeleted && x.IsVisible) .OrderBy(x => x.OrderBy) .Select(ContestCategoryViewModel.FromContestCategory) .FirstOrDefault(); } else { contestCategory = new ContestCategoryViewModel { CategoryName = Resource.Main_categories, Contests = new HashSet <ContestViewModel>(), SubCategories = this.Data.ContestCategories .All() .Where(x => x.IsVisible && !x.IsDeleted && x.Parent == null) .OrderBy(x => x.OrderBy) .Select(ContestCategoryListViewModel.FromCategory) }; } if (contestCategory == null) { throw new HttpException((int)HttpStatusCode.NotFound, Resource.Category_not_found); } if (this.Request.IsAjaxRequest()) { this.ViewBag.IsAjax = true; return(this.PartialView(contestCategory)); } this.ViewBag.IsAjax = false; return(this.View(contestCategory)); }
public ActionResult SignUp(int?contestId) { if (contestId == null) { contestId = CoreConfiguration.ActiveContestId; } if (contestId != null) { ContestSignUpViewModel viewModel = new ContestSignUpViewModel(); viewModel.ContestId = Convert.ToInt32(contestId); viewModel.Contest = this._contestRepository.GetContest(Convert.ToInt32(contestId)); viewModel.Categories = new List <ContestCategoryViewModel>(); foreach (var category in viewModel.Contest.AcademyAwardsCategories) { ContestCategoryViewModel cat = new ContestCategoryViewModel(); cat.CategoryId = category.Id; cat.CategoryTitle = category.CategoryTitle; cat.SortOrder = category.SortOrder; cat.Nominees = new List <ContestNomineeViewModel>(); foreach (var nominee in category.AcademyAwardsNominees) { cat.Nominees.Add(new ContestNomineeViewModel() { NomineeId = nominee.Id, NomineeText = nominee.NomineeText, SortOrder = nominee.SortOrder }); } viewModel.Categories.Add(cat); } return(View(viewModel)); } Danger("There is no contest to sign up for at this time"); return(RedirectToAction("Index", "Contest")); }