public async Task <IActionResult> Search(PostSearchBindingModel model)
        {
            model = TSelfExtensions.TrimStringProperties(model);
            var modelView = await this.postsService.GetPostsAsync(model);

            return(this.PartialView("_SearchResult", modelView));
        }
        public async Task <PostSearchBindingModel> PreparePostSearchFormAsync()
        {
            var authors = await this.GenerateAuthorsSelectListAsync();

            var categories = await this.GenerateCategoriesSelectListAsync();

            var model = new PostSearchBindingModel()
            {
                Categories = categories.OrderBy(c => c.Value),
                Authors    = authors.OrderBy(a => a.Value)
            };

            return(model);
        }
        public async Task <IEnumerable <PostConciseViewModel> > GetPostsAsync(PostSearchBindingModel model)
        {
            Validator.ThrowIfNull(model);
            var posts = await this.DbContext.Posts
                        .Where(p =>
                               (model.AuthorId == null || p.AuthorId == model.AuthorId) &&
                               (model.CategoryId == null || p.CategoryId == model.CategoryId.Value) &&
                               (model.PostId == null || p.Id == model.PostId.Value) &&
                               (model.Title == null || p.Title == model.Title) &&
                               (model.FromCreationDate == null || p.CreationDate.Date >= model.FromCreationDate.Value) &&
                               (model.ToCreationDate == null || p.CreationDate.Date <= model.ToCreationDate.Value))
                        .Include(p => p.Comments)
                        .ThenInclude(c => c.Replies)
                        .OrderByDescending(p => p.CreationDate)
                        .ToListAsync();

            var viewModel = this.Mapper.Map <IEnumerable <PostConciseViewModel> >(posts);

            return(viewModel);
        }
Пример #4
0
        public static async Task AddSearchBindingModel(this IEntityService <Search> service, PostSearchBindingModel model)
        {
            var entity = model.CreateInstanceOf <Search>();
            await service.AddAsync(entity);

            var objMongo = model.CreateInstanceOf <SearchMongoModel>();

            objMongo.ParentId = entity.Id.ToString();
            var idMongo = await service.MongoService.InsertMongoObject <SearchMongoModel>(objMongo);
        }