/// <summary> /// Gets the keyword with the specified ID. /// </summary> /// <param name="id">The identifier.</param> /// <returns>The keyword or null if not found.</returns> public Keyword GetKeyword(int id) { using (var db = GetContext()) { EfKeyword ef = db.Keywords.Find(id); return(ef != null?EfHelper.GetKeyword(ef) : null); } }
/// <summary> /// Gets the specified page of keywords. /// </summary> /// <param name="filter">The filter.</param> /// <returns>The page.</returns> public DataPage <Keyword> GetKeywords(KeywordFilter filter) { PrepareKeywordFilter(filter); using (var db = GetContext()) { var keywords = db.Keywords.AsQueryable(); if (!string.IsNullOrEmpty(filter.Language)) { keywords = keywords.Where(k => k.Language == filter.Language); } if (!string.IsNullOrEmpty(filter.Value)) { // filter value for keyword can be language:value int i = filter.Value.IndexOf(':'); if (i == 3) { string l = filter.Value.Substring(0, 3); keywords = keywords.Where(k => k.Language == l); if (filter.Value.Length > 4) { string v = filter.Value.Substring(4); keywords = keywords.Where(k => k.Valuex.Contains(v)); } } else { keywords = keywords.Where(k => k.Valuex.Contains(filter.Value)); } } int tot = keywords.Count(); // sort and page keywords = keywords.OrderBy(k => k.Language) .ThenBy(k => k.Value) .ThenBy(k => k.Id); keywords = keywords.Skip(filter.GetSkipCount()).Take(filter.PageSize); return(new DataPage <Keyword>( filter.PageNumber, filter.PageSize, tot, (from k in keywords select EfHelper.GetKeyword(k)).ToList())); } }