Пример #1
0
        public ActionResult Index(PollIndexOptions options, PagerParameters pagerParameters)
        {
            var model = new PollsIndexViewModel();
            var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);

            // Default options
            if (options == null)
                options = new PollIndexOptions();

            var polls = _pollService.GetAllPollsWithoutLogs();

            switch (options.Filter)
            {
                case PollBulkFilter.All:
                    break;
                case PollBulkFilter.Closed:
                    polls = polls.Where(p => p.PollState == PollState.Closed);
                    break;
                case PollBulkFilter.Open:
                    polls = polls.Where(p => p.PollState == PollState.Open);
                    break;
            }

            polls = polls.OrderByDescending(p => p.Id)
                .Skip(pager.GetStartIndex())
                .Take(pager.PageSize);



            foreach (var pollRecord in polls.ToList())
            {
                var pollModel = new PollSummaryViewModel
                {
                    EndDate = pollRecord.EndDate,
                    StartDate = pollRecord.StartDate,
                    Id = pollRecord.Id,
                    MaxAnswers = pollRecord.MaxAnswers,
                    PollState = pollRecord.PollState,
                    Question = pollRecord.Question,
                    AnswersCount = pollRecord.Answers.Count
                };
                model.Polls.Add(pollModel);
            }
            model.Pager = Shape.Pager(pager).TotalItemCount(_pollService.GetAllPollsWithoutLogs().Count());
            model.Options = options;
            return View(model);
        }
Пример #2
0
 public ActionResult Index(FormCollection input)
 {
     var viewModel = new PollsIndexViewModel { Options = new PollIndexOptions() };
     TryUpdateModel(viewModel);
     try
     {
         IEnumerable<PollSummaryViewModel> checkedEntries = viewModel.Polls.Where(c => c.IsChecked);
         switch (viewModel.Options.BulkAction)
         {
             case PollBulkAction.None:
                 Services.Notifier.Add(NotifyType.Information, T("Did nothing. Item count: " + checkedEntries.Count()));
                 break;
             case PollBulkAction.Delete:
                 foreach (var pollSummaryViewModel in checkedEntries)
                 {
                     _pollService.Delete(pollSummaryViewModel.Id);
                 }
                 break;
             case PollBulkAction.ChangeStateToClosed:
                 foreach (var pollSummaryViewModel in checkedEntries)
                 {
                     _pollService.SetPollState(pollSummaryViewModel.Id, PollState.Closed);
                 }
                 break;
             case PollBulkAction.ChangeStateToOpen:
                 foreach (var pollSummaryViewModel in checkedEntries)
                 {
                     _pollService.SetPollState(pollSummaryViewModel.Id, PollState.Open);
                 }
                 break;
             default:
                 break;
         }
     }
     catch (Exception exception)
     {
         Logger.Log(LogLevel.Error, exception, "Editing poll failed: {0}", exception.Message);
         return RedirectToAction("Index", "Admin", new { options = viewModel.Options });
     }
     return RedirectToAction("Index");
 }