Example #1
0
        public ResultMessage GetAll(ArticlesFilter filter)
        {
            try
            {
                _logger.LogInformation($"START: Article.GetAll: CatId:{filter.CategoryId} ,PageNo:{filter.PageNo} , PageSize:{filter.PageSize} , SearchTxt:{filter.SearchText} , Status:{filter.Status}");

                PagedResult <ArticleGetDto> result = new PagedResult <ArticleGetDto>();

                if (filter.CategoryId == (int)PredefinedArticlesCategories.Championships)
                {
                    result = _unitOfWork.ArticlesRepository.Get().ApplyFilter(filter).Where(c => !c.IsDraft).ApplyChampionshipsFilter().OrderByDescending(c => c.Date.HasValue).ThenBy(c => c.Date).GetPaged(filter.PageNo, filter.PageSize).Adapt(result);
                }
                else
                {
                    result = _unitOfWork.ArticlesRepository.Get().ApplyFilter(filter).Where(c => !c.IsDraft).OrderByDescending(c => c.CreatedAt).GetPaged(filter.PageNo, filter.PageSize).Adapt(result);
                }

                _logger.LogInformation($"END: Article.GetAll --SUCCESS");

                return(new ResultMessage
                {
                    Data = result,
                    Status = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage()
                {
                    ErrorCode = (int)ProductsErrorsCodeEnum.ProductsGetAllError,
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Example #2
0
 public ActionResult GetForWriters([FromQuery] ArticlesFilter filter)
 {
     filter.CreatedBy = GetCurrentUser().Id;
     return(GetStatusCodeResult(_articlesService.GetAll(filter)));
 }
Example #3
0
 public ActionResult GetForAdmin([FromQuery] ArticlesFilter filter)
 {
     return(GetStatusCodeResult(_articlesService.GetAll(filter)));
 }
Example #4
0
 public ActionResult Get([FromQuery] ArticlesFilter filter)
 {
     filter.Status = (int)(StatusFilterEnum.Active);
     return(GetStatusCodeResult(_articlesService.GetAll(filter)));
 }
Example #5
0
        /// <summary>
        /// the response for the search all KB request
        /// </summary>
        /// <param name="subdomain">the site's subdomain</param>
        /// <param name="consumerKey">your consumer key</param>
        /// <param name="consumerSecret">your consumer secret</param>
        /// <param name="query">your search query</param>
        /// <param name="page">the page number</param>
        /// <param name="perPage">the number of articles per page</param>
        /// <param name="filter">how the request response should be filtered</param>
        /// <param name="sort">the order in which the response should be sorted</param>
        /// <returns>IRestResponse containing the requested data</returns>
        private async Task <IRestResponse> SearchAllArticlesResponse(string subdomain, string consumerKey, string consumerSecret, string query, int page = 1, int perPage = 10, ArticlesFilter filter = ArticlesFilter.all, ArticlesSort sort = ArticlesSort.newest)
        {
            _client.BaseUrl       = new Uri(string.Format("https://{0}.uservoice.com/api/v1/", subdomain));
            _client.Authenticator = OAuth1Authenticator.ForProtectedResource(consumerKey, consumerSecret, null, null);

            RestRequest request = new RestRequest("search.json", HttpMethod.Get);

            request.AddHeader("If-Modified-Since", DateTime.Now.ToUniversalTime().ToString("R"));


            request.AddParameter("page", page);
            request.AddParameter("query", query);
            request.AddParameter("per_page", perPage);
            request.AddParameter("filter", filter);
            request.AddParameter("sort", sort);

            return(await _client.Execute(request));
        }
Example #6
0
        /// <summary>
        /// async wrapper for the KnowledgeBase Model
        /// </summary>
        /// <param name="subdomain">the site's subdomain</param>
        /// <param name="consumerKey">your consumer key</param>
        /// <param name="consumerSecret">your consumer secret</param>
        /// <param name="page">the page number</param>
        /// <param name="perPage">the number of articles per page</param>
        /// <param name="filter">how the request response should be filtered</param>
        /// <param name="sort">the order in which the response should be sorted</param>
        /// <returns>data to be filled in the KnowledgeBase model</returns>
        public async Task <KnowledgeBaseResult> GetAllArticles(string subdomain, string consumerKey, string consumerSecret, int page = 1, int perPage = 10, ArticlesFilter filter = ArticlesFilter.all, ArticlesSort sort = ArticlesSort.newest)
        {
            KnowledgeBaseResult allKB = new KnowledgeBaseResult();

            IRestResponse response = await GetAllArticlesResponse(subdomain, consumerKey, consumerSecret, page, perPage, filter, sort);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                string jsonContent = Encoding.UTF8.GetString(response.RawBytes, 0, response.RawBytes.Length);

                allKB = JsonConvert.DeserializeObject <KnowledgeBaseResult>(jsonContent);
            }

            return(allKB);
        }
Example #7
0
        public static IQueryable <Shared.Core.Models.Articles> ApplyFilter(this IQueryable <Shared.Core.Models.Articles> articles, ArticlesFilter filter)
        {
            if (filter == null)
            {
                return(articles);
            }

            switch ((StatusFilterEnum)filter.Status)
            {
            case StatusFilterEnum.Active:
                articles = articles.Where(c => c.IsActive == true);
                break;

            case StatusFilterEnum.Rejected:
                articles = articles.Where(c => c.IsActive == false);
                break;

            case StatusFilterEnum.Pending:
                articles = articles.Where(c => !c.IsActive.HasValue);
                break;
            }

            if (filter.CategoryId != 0)
            {
                articles = articles.Where(c => c.CategoryId == filter.CategoryId);
            }

            if (!string.IsNullOrEmpty(filter.SearchText))
            {
                articles = articles.Where(c => c.Name.ToLower().Contains(filter.SearchText.ToLower()));
            }

            if (!string.IsNullOrEmpty(filter.CreatedBy))
            {
                articles = articles.Where(c => c.CreatedBy == filter.CreatedBy);
            }

            return(articles);
        }