Ejemplo n.º 1
0
        public Task <PagedList <VoteViewModel> > GetVotes(SearchVoteModel model, string userId)
        {
            var votes = _context.Votes as IQueryable <Vote>;

            if (!string.IsNullOrWhiteSpace(model.Title))
            {
                model.Title = model.Title.Trim();
                votes       = votes.Where(x => x.Title == model.Title);
            }

            var dateTime       = DateTime.Now;
            var voteViewModels = votes
                                 .Where(x => x.CreatedById == userId)
                                 .Select(x => new VoteViewModel
            {
                Id        = x.Id,
                Title     = x.Title,
                Remaining =
                    $"{(x.Deadline - dateTime).Days}days " +
                    $"{(x.Deadline - dateTime).Hours}hrs " +
                    $"{(x.Deadline - dateTime).Minutes}minus",
                IsPublish = x.IsPublish ? "已发布" : "未发布"
            });

            return(PagedList <VoteViewModel> .CreateAsync(voteViewModels, model.PageNumber, model.PageSize));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(SearchVoteModel model)
        {
            var user = await GetCurrentUserAsync();

            var models = await _voteService.GetVotes(model, user.Id);

            return(View(models));
        }