Exemple #1
0
        public static Category GetMostPlayedActorCategory(this DVDRentalContext context, int actorId)
        {
            var films   = context.GetFilmsByActor(actorId);
            var filmIds = films.ToList().Select(film =>
            {
                return(film.film_id);
            }).ToArray();

            var filmCategories     = context.GetCategoryOfFilm(filmIds);
            var mostPlayedCategory = filmCategories.GroupBy(category =>
            {
                return(category.category_id);
            }).Select(group => new
            {
                CategoryId = group.Key,
                Count      = group.Count()
            }).OrderByDescending(group => group.Count).FirstOrDefault();

            if (mostPlayedCategory != null)
            {
                return(GetCategories(context, mostPlayedCategory.CategoryId).SingleOrDefault());
            }
            else
            {
                return(default(Category));
            }
        }
        public static IEnumerable <FilmToCategory> GetCategoryOfFilm(this DVDRentalContext context, params int[] filmId)
        {
            if (!filmId.Any())
            {
                return(new List <FilmToCategory>());
            }

            string parameter = string.Join(",", filmId);

            return(context.FillEntity <FilmToCategory>(string.Format("select * from film_category where film_id IN ({0})", parameter)));
        }
Exemple #3
0
 public UnitOfWork(DVDRentalContext context)
 {
     Context       = context;
     Actors        = new ActorRepository(Context);
     Addresses     = new AddressRepository(Context);
     Cities        = new CityRepository(Context);
     Countries     = new CountryRepository(Context);
     Directors     = new DirectorRepository(Context);
     Genres        = new GenreRepository(Context);
     Inventory     = new InventoryRepository(Context);
     Languages     = new LanguageRepository(Context);
     Media         = new MediaRepository(Context);
     Movies        = new MovieRepository(Context);
     MovieActors   = new MovieActorRepository(Context);
     Producers     = new ProducerRepository(Context);
     RentalHistory = new RentalHistoryRepository(Context);
     Roles         = new RoleRepository(Context);
     States        = new StateRepository(Context);
     Stores        = new StoreRepository(Context);
     Users         = new UserRepository(Context);
     Writers       = new WriterRepository(Context);
     MovieThumbs   = new MovieThumbRepository(Context);
 }
Exemple #4
0
 public static IQueryable <Category> GetCategories(this DVDRentalContext context, params int[] ids)
 {
     return(context.Categorys.Where(category => ids.Contains(category.category_id)));
 }
Exemple #5
0
 public static int GetFilmCountForActor(this DVDRentalContext context, int actorId)
 {
     return(context.GetFilmToActor(actorId).Count());
 }
Exemple #6
0
 public static IQueryable <Film> GetThreeLongestFilmsByActor(this DVDRentalContext context, int actorId)
 {
     return(context.GetFilmsByActor(actorId).OrderByDescending(film => film.length).Take(3));
 }
Exemple #7
0
 public GenericRepository(DVDRentalContext context)
 {
     _entities = context.Set <T>();
 }
Exemple #8
0
        public static IQueryable <Film> GetFilmsByActor(this DVDRentalContext context, int actorId)
        {
            var filmIds = context.GetFilmToActor(actorId).Select(relation => { return(relation.film_id); });

            return(context.Films.Where(film => filmIds.Contains(film.film_id)));
        }
 public CountryRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
Exemple #10
0
 public AddressRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
Exemple #11
0
 public MediaRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
 public static Actor GetActorById(this DVDRentalContext context, int id)
 {
     return(context.Actors.SingleOrDefault(actor => actor.actor_id == id));
 }
Exemple #13
0
 public FilmContext(DVDRentalContext context = null) : base(context)
 {
 }
 public LanguageRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
Exemple #15
0
 public RentalHistoryRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
 public ProducerRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
Exemple #17
0
 public Context(DVDRentalContext context = null)
 {
     this.context = context ?? new DVDRentalContext();
 }
Exemple #18
0
 public Context(DVDRentalContext context = null)
 {
     this.context = context ?? new DVDRentalContext();
 }
Exemple #19
0
 public MovieThumbRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
Exemple #20
0
 public GenreRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
 public FilmContext(DVDRentalContext context = null)
     : base(context)
 {
 }
 public ActorRepository(DVDRentalContext context) : base(context)
 {
     _context = context;
 }
Exemple #23
0
 public static IEnumerable <FilmToActor> GetFilmToActor(this DVDRentalContext context, int actorId)
 {
     return(context.FillEntity <FilmToActor>(string.Format("select * from film_actor where actor_id = {0}", actorId)));
 }