Exemplo n.º 1
0
        // 提供获取文章列表的数据接口
        // Get: /ArticlesList/

        public string ArticlesList(ArticlesQuery articlesQuery)
        {
            var query = db.Articles.Where(p => p.ShowType == "文章");

            if (!String.IsNullOrEmpty(articlesQuery.title))
            {
                query = query.Where(p => p.Title.Contains(articlesQuery.title));
            }

            if (!String.IsNullOrEmpty(articlesQuery.type))
            {
                query = query.Where(p => p.Type == articlesQuery.type);
            }
            var articlesList = query.OrderByDescending(u => u.CreateTime)
                               .Skip((articlesQuery.page - 1) * articlesQuery.limit)
                               .Take(articlesQuery.limit).ToList();
            int           count   = articlesList.Count();
            StringBuilder strJson = new StringBuilder();
            var           iso     = new IsoDateTimeConverter();

            iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            foreach (var item in articlesList)
            {
                strJson.Append(JsonConvert.SerializeObject(item, iso) + ",");
            }
            return("{\"code\":0,\"msg\":\"\",\"count\":" + count + ",\"data\":[" + strJson.ToString().TrimEnd(',') + "]}");
        }
Exemplo n.º 2
0
        public async Task <ArticleModel> GetAsync(Guid id)
        {
            var query = new ArticlesQuery {
                FilterIds = id.Collect()
            };
            // query.AsLazy();
            var article = (await _queryInvoker.Execute <ArticlesQuery, Article>(query)).SingleOrDefault();

            return(_mapper.Map <ArticleModel>(article));
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <ArticleModel> > GetAsync([FromQuery] string nameLike,
                                                                 [FromQuery] ArticleType?typeExact, [FromQuery] Guid?uomExact, [FromQuery] string codeLike,
                                                                 int?take, int?skip, string orderBy, string orderMode)
        {
            var query = new ArticlesQuery
            {
                Take                   = take,
                Skip                   = skip,
                OrderBy                = orderBy,
                OrderMode              = orderMode,
                FilterNameLike         = nameLike,
                FilterArticleTypeExact = typeExact,
                FilterUomExact         = uomExact,
                FilterCodeLike         = codeLike,
            };
            //  query.AsLazy();
            var articles = await _queryInvoker.Execute <ArticlesQuery, Article>(query);

            return(_mapper.Map <IEnumerable <ArticleModel> >(articles));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Index([FromQuery] ArticlesQuery query, [FromRoute] int page = 0)
        {
            page = Math.Max(0, page);

            string viewerUserId = this.GetViewerUserId();

            // Temporary for disabling tags feature
            query.Tag = string.Empty;

            ArticlesResponse blogResponse = null;

            if (string.IsNullOrEmpty(query.Q))
            {
                blogResponse = await _articleService.Get(PageSize, page, query.Year, query.Tag, specificUserId : query.UserId,
                                                         viewerUserId : viewerUserId, oldest : query.Oldest).CAF();
            }
            // else
            // {
            //     _logger.LogInformation("Searching for {SearchQuery}", query.Q);
            //     // To minimize spam of searches
            //     await Task.Delay(1000).CAF();
            //
            //     blogResponse = await _articleService.Get(PageSize, query.Q).CAF();
            // }

            if (blogResponse is null)
            {
                return(Redirect("/"));
            }
            if (blogResponse.Articles.Count == 0 && blogResponse.CurrentPage > 0)
            {
                return(Redirect("/"));
            }

            // blogResponse.MostPopularTags = await _tagService.GetTopTags(10).ConfigureAwait(false);

            return(View("Articles", blogResponse));
        }
Exemplo n.º 5
0
        public ActionResult Article(ArticlesQuery articlesQuery)
        {
            var query = db.Articles
                        .OrderByDescending(p => p.CreateTime)
                        .Where(p => p.ShowType == "文章" && p.IsPub == "是");

            if (!string.IsNullOrEmpty(articlesQuery.title))
            {
                query = query.Where(p => p.Title.Contains(articlesQuery.title));
            }
            if (!string.IsNullOrEmpty(articlesQuery.type))
            {
                query = query.Where(p => p.Type == articlesQuery.type);
            }
            if (!string.IsNullOrEmpty(articlesQuery.tags))
            {
                query = query.Where(p => p.Tags == articlesQuery.tags);
            }
            var total = query.Count();
            var count = total / articlesQuery.limit;

            //如果余数是0
            if (total % articlesQuery.limit != 0)
            {
                count++;
            }
            var articleList = query
                              .Skip((articlesQuery.page - 1) * articlesQuery.limit)
                              .Take(articlesQuery.limit).ToList();

            ViewBag.Count       = count;
            ViewBag.CurrentPage = articlesQuery.page;
            ViewBag.Search      = articlesQuery.title;
            ViewBag.Type        = articlesQuery.type;
            ViewBag.Tags        = articlesQuery.tags;
            return(View(articleList));
        }