/// <summary> /// Prepare paged poll answer list model /// </summary> /// <param name="searchModel">Poll answer search model</param> /// <param name="poll">Poll</param> /// <returns>Poll answer list model</returns> public virtual PollAnswerListModel PreparePollAnswerListModel(PollAnswerSearchModel searchModel, Poll poll) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (poll == null) { throw new ArgumentNullException(nameof(poll)); } //get poll answers var pollAnswers = poll.PollAnswers.OrderBy(pollAnswer => pollAnswer.DisplayOrder).ToList(); //prepare list model var model = new PollAnswerListModel { //fill in model values from the entity Data = pollAnswers.PaginationByRequestModel(searchModel).Select(pollAnswer => new PollAnswerModel { Id = pollAnswer.Id, PollId = pollAnswer.PollId, Name = pollAnswer.Name, NumberOfVotes = pollAnswer.NumberOfVotes, DisplayOrder = pollAnswer.DisplayOrder }), Total = pollAnswers.Count }; return(model); }
public virtual IActionResult PollAnswers(PollAnswerSearchModel searchModel) { //try to get a poll with the specified id Poll poll = _pollService.GetPollById(searchModel.PollId) ?? throw new ArgumentException("No poll found with the specified id"); //prepare model PollAnswerListModel model = _pollModelFactory.PreparePollAnswerListModel(searchModel, poll); return(Json(model)); }
/// <summary> /// Prepare paged poll answer list model /// </summary> /// <param name="searchModel">Poll answer search model</param> /// <param name="poll">Poll</param> /// <returns>Poll answer list model</returns> public virtual PollAnswerListModel PreparePollAnswerListModel(PollAnswerSearchModel searchModel, Poll poll) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (poll == null) { throw new ArgumentNullException(nameof(poll)); } //get poll answers var pollAnswers = _pollService.GetPollAnswerByPoll(poll.Id, searchModel.Page - 1, searchModel.PageSize); //prepare list model var model = new PollAnswerListModel().PrepareToGrid(searchModel, pollAnswers, () => pollAnswers.Select(pollAnswer => pollAnswer.ToModel <PollAnswerModel>())); return(model); }
/// <summary> /// Prepare paged poll answer list model /// </summary> /// <param name="searchModel">Poll answer search model</param> /// <param name="poll">Poll</param> /// <returns>Poll answer list model</returns> public virtual PollAnswerListModel PreparePollAnswerListModel(PollAnswerSearchModel searchModel, Poll poll) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (poll == null) { throw new ArgumentNullException(nameof(poll)); } //get poll answers var pollAnswers = poll.PollAnswers.OrderBy(pollAnswer => pollAnswer.DisplayOrder).ToList().ToPagedList(searchModel); //prepare list model var model = new PollAnswerListModel().PrepareToGrid(searchModel, pollAnswers, () => pollAnswers.Select(pollAnswer => pollAnswer.ToModel <PollAnswerModel>())); return(model); }