Advertisement
wingman007

CourseRepositorySuggestedExample

Sep 28th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. // https://www.youtube.com/watch?v=rtXpYpZdOzM&t=1159s
  2. using Queries.Core.Domain;
  3. using Queries.Core.Repositories;
  4. using System.Collections.Generic;
  5. using System.Data.Entity;
  6. using System.Linq;
  7.  
  8. namespace Queries.Persistence.Repositories
  9. {
  10.     public class CourseRepository : Repository<Course>, ICourseRepository
  11.     {
  12.         public CourseRepository(PlutoContext context)
  13.             : base(context)
  14.         {
  15.         }
  16.  
  17.         public IEnumerable<Course> GetTopSellingCourses(int count)
  18.         {
  19.             return PlutoContext.Courses.OrderByDescending(c => c.FullPrice).Take(count).ToList();
  20.         }
  21.  
  22.         public IEnumerable<Course> GetCoursesWithAuthors(int pageIndex, int pageSize = 10)
  23.         {
  24.             return PlutoContext.Courses
  25.                 .Include(c => c.Author)
  26.                 .OrderBy(c => c.Name)
  27.                 .Skip((pageIndex - 1) * pageSize)
  28.                 .Take(pageSize)
  29.                 .ToList();
  30.         }
  31.  
  32.         public PlutoContext PlutoContext
  33.         {
  34.             get { return Context as PlutoContext; }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement