示例#1
0
        /// <summary>
        /// Gets the specified page of authors matching <paramref name="filter" />.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns>
        /// Page of authors.
        /// </returns>
        /// <exception cref="ArgumentNullException">filter</exception>
        public DataPage <Author> GetAuthors(AuthorFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            PrepareAuthorFilter(filter);

            using (var db = GetContext())
            {
                var authors = db.Authors.AsQueryable();
                if (!string.IsNullOrEmpty(filter.Last))
                {
                    authors = authors.Where(a => a.Lastx.Contains(filter.Last));
                }

                int tot = authors.Count();

                // sort and page
                authors = authors.OrderBy(a => a.Last)
                          .ThenBy(a => a.First)
                          .ThenBy(a => a.Suffix)
                          .ThenBy(a => a.Id);
                var pgAuthors = authors.Skip(filter.GetSkipCount())
                                .Take(filter.PageSize)
                                .ToList();

                return(new DataPage <Author>(
                           filter.PageNumber,
                           filter.PageSize,
                           tot,
                           (from a in pgAuthors select EfHelper.GetAuthor(a)).ToList()));
            }
        }
示例#2
0
 /// <summary>
 /// Gets the author with the specified ID.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns>
 /// The author, or null if not found.
 /// </returns>
 public Author GetAuthor(Guid id)
 {
     using (var db = GetContext())
     {
         EfAuthor ef = db.Authors.Find(id);
         return(EfHelper.GetAuthor(ef));
     }
 }