public async Task <etymons[]> getPage(etymfilter f, int start, int pageSize) { try { var q = (from c in db.etymons.AsNoTracking() select c); q = setWordListQueryFilter(f, q); q = setWordListQuerySorting(q); q = q.Skip(start * pageSize).Take(pageSize); return(await q.ToArrayAsync()); } catch (Exception ex) { if (Logger != null) { Logger.LogError(new EventId(0), ex, ex.Message); return(null); } else { throw ex; } } finally { } }
private IQueryable <etymons> setWordListQueryFilter(etymfilter f, IQueryable <etymons> q) { try { if ((f.isStrFiltering) && (!string.IsNullOrEmpty(f.str))) { string s = f.str.Replace('*', '%'); q = q.Where(c => EF.Functions.Like(c.word, s)); } if (f.isHead) { q = q.Where(c => c.ishead == true); } if (f.isLang) { q = q.Where(c => c.lang_code == f.langId); } if (f.isType) { switch (f.typeId) { case 0: //Літературні q = q.Where(c => c.dialect == false); break; case 1: //Діалектні q = q.Where(c => c.dialect == true); break; case 2: //Омоніми q = q.Where(c => c.homonym > 0); break; case 3: //Антропоніми q = q.Where(c => c.antroponym == true); break; } } return(q); } catch (Exception ex) { if (Logger != null) { Logger.LogError(new EventId(0), ex, ex.Message); return(null); } else { throw ex; } } }
public async Task <etymons_base> searchWord(etymfilter f, string word) { //System.Runtime.CompilerServices.StrongBox <T> try { string w = word ?? ""; int start = 0; var q = (from c in db.etymons select c); q = setWordListQueryFilter(f, q); q = setWordListQuerySorting(q); start = await(from c in q where w.CompareTo(c.word.ToUpperInvariant().Replace("<SUP>", "").Replace("</SUP>", "").Replace("\'", "").Replace(" ", "").Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("*", "")) > 0 select c).CountAsync(); int pagenumber = start / 100; int count = q.Count(); if (count <= start) { q = q.Skip((start - 1)).Take(1); } else { q = q.Skip(start).Take(1); } etymons wp = await q.FirstOrDefaultAsync(); etymons_base r = null; if (wp != null) { r = (new etymons_base() { CountOfWords = count, wordsPageNumber = pagenumber, id = wp.id, id_e_classes = wp.id_e_classes, homonym = wp.homonym, word = wp.word }); } return(r); } catch (Exception ex) { if (Logger != null) { Logger.LogError(new EventId(0), ex, ex.Message); return(null); } else { throw ex; } } }
public async Task <int> CountWords(etymfilter f) { try { var q = (from c in db.etymons select c); q = setWordListQueryFilter(f, q); return(await q.CountAsync()); } catch (Exception ex) { if (Logger != null) { Logger.LogError(new EventId(0), ex, ex.Message); return(-1); } else { throw ex; } } }