public JsonResult List(Guid categoryId, string keywords, int? skip, int? take, string sortField, string orderBy) { var xtake = 10; var xskip = 0; long total = 0; if (skip != null) { xskip = skip.Value; } if (take != null) { xtake = take.Value; } if (string.IsNullOrEmpty(sortField)) { sortField = nameof(FeNews.CreatedDate); } if (string.IsNullOrEmpty(orderBy)) { orderBy = "desc"; } List<FeNews> rows = new List<FeNews>(); List<ContentLanguage> contentLanguages = null; var tempNews = NewsSearchServices.Search(keywords, LanguageId, new List<Guid>() { categoryId }, null, xskip, xtake, out contentLanguages, out total); foreach (var n in tempNews) { var i = new FeNews(); i.CreatedDate = n.CreatedDate; i.Id = n.Id; i.Published = n.Published; i.AllowComment = n.AllowComment; i.Title = contentLanguages.GetValue(i.Id, "Title"); i.UrlImage = contentLanguages.GetValue(i.Id, "UrlImage"); i.SeoUrlFriendly = contentLanguages.GetValue(i.Id, "SeoUrlFriendly"); rows.Add(i); } return Json(new { total, rows, success = true }, JsonRequestBehavior.AllowGet); }
public JsonResult ListResult(string keywords, int?skip, int?take, string sortField, string orderBy) { var xtake = 10; var xskip = 0; long total = 0; if (skip != null) { xskip = skip.Value; } if (take != null) { xtake = take.Value; } if (string.IsNullOrEmpty(sortField)) { sortField = nameof(FeNews.CreatedDate); } if (string.IsNullOrEmpty(orderBy)) { orderBy = "desc"; } List <FeNews> rows = new List <FeNews>(); if (!string.IsNullOrEmpty(keywords)) { List <ContentLanguage> contentLanguages = null; var tempNews = NewsSearchServices.Search(keywords, LanguageId, new List <Guid>() { }, true, xskip, xtake, out contentLanguages, out total); if (tempNews.Count == 0) { rows.Add(new FeNews() { Title = "Not found any content match with keywords" }); } else { foreach (var n in tempNews) { var i = new FeNews(); i.CreatedDate = n.CreatedDate; i.Id = n.Id; i.Published = n.Published; i.Title = contentLanguages.GetValue(n.Id, "Title"); i.ShortDescription = contentLanguages.GetValue(n.Id, "ShortDescription"); i.UrlImage = contentLanguages.GetValue(n.Id, "UrlImage"); i.SeoUrlFriendly = contentLanguages.GetValue(n.Id, "SeoUrlFriendly"); rows.Add(i); } } } else { rows.Add(new FeNews() { Title = "No keywords to search" }); } return(Json(new { total, rows, success = true }, JsonRequestBehavior.AllowGet)); }