示例#1
0
        public ActionResult Index(int pageIndex = 1)
        {
            NewsSearchResult result = newsService.GetPageList(null, null, null, pageIndex, pageSize);

            return(Json(new AjaxResult {
                Status = "1", Data = result.News
            }));
        }
示例#2
0
 public NewsSearchResult GetPageList(string title, DateTime?startTime, DateTime?endTime, int pageIndex, int pageSize)
 {
     using (MyDbContext dbc = new MyDbContext())
     {
         CommonService <NewsEntity> cs     = new CommonService <NewsEntity>(dbc);
         NewsSearchResult           result = new NewsSearchResult();
         var news = cs.GetAll();
         if (!string.IsNullOrEmpty(title))
         {
             news = news.Where(n => n.Title.Contains(title));
         }
         if (startTime != null)
         {
             news = news.Where(p => p.CreateTime >= startTime);
         }
         if (endTime != null)
         {
             news = news.Where(p => p.CreateTime <= endTime);
         }
         result.TotalCount = news.LongCount();
         result.News       = news.OrderByDescending(p => p.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList().Select(p => ToDTO(p)).ToArray();
         return(result);
     }
 }
示例#3
0
        public PartialViewResult ListGetPage(string title, DateTime?startTime, DateTime?endTime, int pageIndex = 1)
        {
            NewsListViewModel model  = new NewsListViewModel();
            NewsSearchResult  result = newService.GetPageList(title, startTime, endTime, pageIndex, pageSize);

            model.News = result.News;

            //分页
            Pagination pager = new Pagination();

            pager.PageIndex  = pageIndex;
            pager.PageSize   = pageSize;
            pager.TotalCount = result.TotalCount;

            if (result.TotalCount <= pageSize)
            {
                model.Page = "";
            }
            else
            {
                model.Page = pager.GetPagerHtml();
            }
            return(PartialView("NewsListPaging", model));
        }
        public object Search(int contextId, string keywords = "", int offset = 0, int limit = 10, string year = "")
        {
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

            if (!contextId.IsExistingNode())
            {
                return(Request.CreateResponse(JsonMetaResponse.GetError("contextId is not a valid Umbraco-node")));
            }

            List <IPublishedContent> results;
            int total;

            try
            {
                SpecificFields fields = new SpecificFields
                {
                    Fields = new List <ISpecificField>
                    {
                        new SpecificField
                        {
                            FieldName   = "year",
                            SearchTerms = new [] { year }
                        }
                    }
                };
                SearchOptions initialSo = new SearchOptions
                {
                    Text          = keywords,
                    DocumentTypes = new string[] { Constants.SkyConstants.DocumentTypes.NewsPage },
                    RootIds       = new int[] { contextId },
                    Fields        =
                    {
                        FieldList = new List <Field>
                        {
                            Field.GetFieldOption("nodeName_lci", 15, null),
                            Field.GetFieldOption("titel_lci", 15, null),
                            Field.GetFieldOption("teaser_lci", 15, null),
                            Field.GetFieldOption(Constants.SkyConstants.Properties.ContentGrid, null, null)
                        }
                    },
                    Order = new Order()
                    {
                        FieldName      = string.Format("{0}_range", Constants.SkyConstants.Properties.ContentDate),
                        OrderDirection = OrderDirection.Descending,
                        OrderType      = OrderType.String
                    },
                    DateRange = new DateRange()
                    {
                        FieldName = Constants.SkyConstants.Properties.ContentDate,
                        End       = DateTime.MaxValue,
                        Start     = DateTime.MinValue.AddDays(1)
                    },
                    Limit  = limit,
                    Offset = offset,
                    Debug  = HttpContext.Current.IsDebuggingEnabled
                };
                if (!string.IsNullOrEmpty(year))
                {
                    initialSo.SpecificFields = fields;
                }
                results = Skybrud.Umbraco.Search.SkybrudSearch.SearchDocuments(
                    out total,
                    initialSo
                    ).ToList();
            }
            catch (Exception ex)
            {
                Error error = new Error("Der skete en fejl på serveren");
                LogHelper.Error <NewsController>(error.ToString(), ex);
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, error.Message, error)));
            }
            var returnResults         = results.Select(x => NewsSearchResult.GetFromContent(x));
            JsonMetaResponse response = JsonMetaResponse.GetSuccess(returnResults);

            response.SetPagination(new JsonPagination
            {
                Total  = total,
                Limit  = limit,
                Offset = offset
            });
            return(Request.CreateResponse(response));
        }