Ejemplo n.º 1
0
        public async Task <IActionResult> Search(CommentSearchBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.PartialView("_SearchResult", new List <CommentViewModel>()));
            }

            model = TSelfExtensions.TrimStringProperties(model);
            var modelView = await this.commentsService.GetCommentsForPeriodAsync(model);

            return(this.PartialView("_SearchResult", modelView));
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <CommentViewModel> > GetCommentsForPeriodAsync(CommentSearchBindingModel model)
        {
            Validator.ThrowIfNull(model);
            var comments = await this.DbContext.Comments
                           .Where(
                c => c.CreationDate.Date >= model.FromCreationDate.Date &&
                c.CreationDate.Date <= model.ToCreationDate.Date)
                           .Include(c => c.Author)
                           .Include(c => c.Replies)
                           .ThenInclude(r => r.Author)
                           .OrderByDescending(c => c.CreationDate)
                           .ToListAsync();

            var viewModel = this.Mapper.Map <IEnumerable <CommentViewModel> >(comments);

            return(viewModel);
        }