public WindowWorkList(WorkFilter filtr, bool t) { Init(filtr); AddToCounts.Visibility = Visibility.Visible; }
/// <summary> /// Gets the specified page of filtered works. /// </summary> /// <param name="filter">The filter.</param> /// <returns>The works page.</returns> /// <exception cref="ArgumentNullException">filter</exception> public DataPage <WorkInfo> GetWorks(WorkFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } PrepareWorkFilter(filter); using (var db = GetContext()) { IQueryable <EfWork> works = db.Works .AsNoTracking() .Include(w => w.Type) .Include(w => w.Container) .Include(w => w.AuthorWorks) .ThenInclude(aw => aw.Author) .Include(w => w.KeywordWorks) .ThenInclude(kw => kw.Keyword); if (filter.IsMatchAnyEnabled) { // we need a predicate builder to chain clauses with OR // (note: this requires package LinqKit.Core) // http://www.albahari.com/nutshell/predicatebuilder.aspx var predicate = PredicateBuilder.New <EfWork>(); if (!string.IsNullOrEmpty(filter.Key)) { predicate.Or(w => w.Key.Equals(filter.Key)); } if (!string.IsNullOrEmpty(filter.Type)) { predicate.Or(w => w.Type.Equals(filter.Type)); } if (filter.AuthorId != Guid.Empty) { predicate.Or(w => w.AuthorWorks.Any( aw => aw.AuthorId == filter.AuthorId)); } if (!string.IsNullOrEmpty(filter.LastName)) { predicate.Or(w => w.AuthorWorks.Any(aw => aw.Author.Lastx.Contains(filter.LastName))); } if (!string.IsNullOrEmpty(filter.Language)) { predicate.Or(w => w.Language.Equals(filter.Language)); } if (!string.IsNullOrEmpty(filter.Title)) { predicate.Or(w => w.Titlex.Contains(filter.Title)); } if (filter.ContainerId != Guid.Empty) { predicate.Or(w => w.Container.Id.Equals(filter.ContainerId)); } if (!string.IsNullOrEmpty(filter.Keyword)) { predicate.Or(w => w.KeywordWorks.Any( kw => kw.Keyword.Valuex.Equals(filter.Keyword))); } if (filter.YearPubMin > 0) { predicate.Or(w => w.YearPub >= filter.YearPubMin); } if (filter.YearPubMax > 0) { predicate.Or(w => w.YearPub <= filter.YearPubMax); } works = works.AsExpandable().Where(predicate); } else { // key if (!string.IsNullOrEmpty(filter.Key)) { works = works.Where(w => w.Key == filter.Key); } // type if (!string.IsNullOrEmpty(filter.Type)) { works = works.Where(w => w.Type.Name == filter.Type); } // author ID if (filter.AuthorId != Guid.Empty) { works = works.Where(w => w.AuthorWorks.Any( aw => aw.AuthorId == filter.AuthorId)); } // last if (!string.IsNullOrEmpty(filter.LastName)) { works = works.Where(w => w.AuthorWorks.Any( aw => aw.Author.Lastx.Contains(filter.LastName))); } // language if (!string.IsNullOrEmpty(filter.Language)) { works = works.Where(w => w.Language == filter.Language); } // title if (!string.IsNullOrEmpty(filter.Title)) { works = works.Where(w => w.Titlex.Contains(filter.Title)); } // container ID if (filter.ContainerId != Guid.Empty) { works = works.Where(w => w.ContainerId.Equals(filter.ContainerId)); } // keyword if (!string.IsNullOrEmpty(filter.Keyword)) { works = works.Where(w => w.KeywordWorks.Any( kw => kw.Keyword.Valuex.Equals(filter.Keyword))); } // yearpubmin if (filter.YearPubMin > 0) { works = works.Where(w => w.YearPub >= filter.YearPubMin); } // yearpubmax if (filter.YearPubMax > 0) { works = works.Where(w => w.YearPub <= filter.YearPubMax); } } int tot = works.Count(); // sort and page works = works .OrderBy(w => w.AuthorWorks.Select(aw => aw.Author) .First().Lastx) .ThenBy(w => w.AuthorWorks.Select(aw => aw.Author) .First().First) .ThenBy(w => w.Titlex) .ThenBy(w => w.Key) .ThenBy(w => w.Id); var pgWorks = works.Skip(filter.GetSkipCount()) .Take(filter.PageSize) .ToList(); return(new DataPage <WorkInfo>( filter.PageNumber, filter.PageSize, tot, (from w in pgWorks select EfHelper.GetWorkInfo(w, db)).ToList())); } }
public WindowWorkList(WorkFilter filtr) { Init(filtr); }