public void PopulateGiveawayModel(GiveawaysViewModel model) { if (String.IsNullOrEmpty(model.SearchText) == false) { model.Giveaways = model.Giveaways.Where(a => a.PrizeText().ToLower().Contains(model.SearchText.Trim().ToLower())).ToList(); } model.TotalItems = model.Giveaways.Count; if (model.LoggedInUser.PaginationPreference != 0) { if (model.SelectedPage != 0) { model.CurrentPage = model.SelectedPage; } if (model.CurrentPage < 1) { model.CurrentPage = 1; } model.UserPaginationPreference = model.LoggedInUser.PaginationPreference; if (model.ActionName.CompareTo("Closed") == 0) { model.Giveaways = model.Giveaways.OrderByDescending(a => a.EndDate).Skip((model.CurrentPage - 1) * model.UserPaginationPreference).Take(model.UserPaginationPreference).ToList(); } else { model.Giveaways = model.Giveaways.OrderBy(a => a.EndDate).Skip((model.CurrentPage - 1) * model.UserPaginationPreference).Take(model.UserPaginationPreference).ToList(); } } else { model.CurrentPage = 1; model.Giveaways = model.Giveaways.OrderBy(a => a.EndDate).ToList(); } }
public async Task <ActionResult> Index(GiveawaysViewModel model) { ViewBag.Title = "Open Gives"; model.Giveaways = userService.GetGiveaways().Where(g => g.IsOpen()).ToList(); List <String> destNames = new List <String>() { openGivesText }; model.FullNavList = CreateGiveawayNavList(destNames); model.LoggedInUser = await userService.GetCurrentUser(); model.ActionName = "Index"; PopulateGiveawayModel(model); ModelState.Clear(); return(View(model)); }
public async Task <ActionResult> Closed() { GiveawaysViewModel model = new GiveawaysViewModel(); ViewBag.Title = "Closed Gives"; model.Giveaways = userService.GetGiveaways().Where(a => a.IsOpen() == false).ToList(); List <String> destNames = new List <String>() { closedGivesText }; model.FullNavList = CreateGiveawayNavList(destNames); model.LoggedInUser = await userService.GetCurrentUser(); model.ActionName = "Closed"; PopulateGiveawayModel(model); model.Giveaways = model.Giveaways.OrderByDescending(a => a.EndDate).ToList(); return(View("Index", model)); }