public NewsInfo get_NewItem(SPWeb web, int id) { var list = web.Lists[listName]; var newsInfo = new NewsInfo(); SPQuery query = new SPQuery() { Query = string.Format(Constants.News.Queries.getNewbyID, id) }; var items = list.GetItems(query); if (items != null && items.Count > 0) { var item = items[0]; newsInfo = new NewsInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Content = Convert.ToString(item[Constants.News.InternalFields.Content]), Image = Convert.ToString(item[Constants.News.InternalFields.Thumbar]), Created = Convert.ToDateTime(item[Constants.News.InternalFields.FromDate]).ToShortDateString(), Description = Convert.ToString(item[Constants.News.InternalFields.Description]), Category = Convert.ToString(item[Constants.News.InternalFields.Category]) }; } return(newsInfo); }
public NewsInfo get_top1News(SPWeb web, string catId) { var list = web.Lists[listName]; var newsInfo = new NewsInfo(); var query = Camlex.Query().Where(c => c[Constants.News.InternalFields.Category] == (DataTypes.LookupId)catId && (Boolean)c[Constants.News.InternalFields.Activate] && (DateTime)c[Constants.News.InternalFields.FromDate] <= DateTime.Today && (c[Constants.News.InternalFields.ToDate] == null || (DateTime)c[Constants.News.InternalFields.ToDate] >= DateTime.Today)).OrderBy(c => new[] { c[Constants.News.InternalFields.ShowHomePage] as Camlex.Desc, c[Constants.CommonField.Created] as Camlex.Desc }).ToSPQuery(); query.RowLimit = 1; var items = list.GetItems(query); if (items.Count > 0) { SPListItem item = items[0]; newsInfo = new NewsInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Content = Convert.ToString(item[Constants.News.InternalFields.Content]), Image = Convert.ToString(item[Constants.News.InternalFields.Thumbar]), Created = Convert.ToDateTime(item[Constants.News.InternalFields.FromDate]).ToShortDateString(), Description = Convert.ToString(item[Constants.News.InternalFields.Description]), Category = Convert.ToString(item[Constants.News.InternalFields.Category]), CreatedSystem = Convert.ToDateTime(item[Constants.News.InternalFields.FromDate]), }; } else { query = Camlex.Query().Where(c => c[Constants.News.InternalFields.Category] == (DataTypes.LookupId)catId && (Boolean)c[Constants.News.InternalFields.Activate] && (DateTime)c[Constants.News.InternalFields.FromDate] <= DateTime.Today && (c[Constants.News.InternalFields.ToDate] == null || (DateTime)c[Constants.News.InternalFields.ToDate] >= DateTime.Today)).OrderBy(c => new[] { c[Constants.News.InternalFields.ShowHomePage] as Camlex.Desc, c[Constants.CommonField.Created] as Camlex.Desc }).ToSPQuery(); query.RowLimit = 1; items = list.GetItems(query); if (items.Count > 0) { SPListItem item = items[0]; newsInfo = new NewsInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Content = Convert.ToString(item[Constants.News.InternalFields.Content]), Image = Convert.ToString(item[Constants.News.InternalFields.Thumbar]), Created = Convert.ToDateTime(item[Constants.News.InternalFields.FromDate]).ToShortDateString(), Description = Convert.ToString(item[Constants.News.InternalFields.Description]), Category = Convert.ToString(item[Constants.News.InternalFields.Category]), CreatedSystem = Convert.ToDateTime(item[Constants.News.InternalFields.FromDate]), }; } } return(newsInfo); }