public static List <ShowDto> getPagedShows(RtlDbContext showContext, int page) { if (page >= 1) { return(showContext.Shows .Skip((page - 1) * PAGE_ITEM_COUNT) .Take(PAGE_ITEM_COUNT) .Include(show => show.Actors) .Select(show => new ShowDto(show)) .ToList()); } else { return(null); } }
static void insertToDB(List <Show> shows) { var optionsBuilder = new DbContextOptionsBuilder <RtlDbContext>(); optionsBuilder.UseSqlServer(Resources.DefaultConnection); var dbContext = new RtlDbContext(optionsBuilder.Options); dbContext.Database.EnsureCreated(); var dbShows = new List <ShowEntity>(); foreach (var show in shows) { var showEntity = new ShowEntity(); showEntity.Name = show.Name; showEntity.CorrelationId = show.Id; showEntity.Actors = new List <ActorEntity>(); List <Actor> actors = readPersonFile(show.Id); foreach (var actor in actors) { ActorEntity actorEntity = new ActorEntity(); actorEntity.Name = actor.Person.Name; actorEntity.CorrelationId = actor.Person.Id; if (actor.Person.Birthday.HasValue) { actorEntity.Birthday = actor.Person.Birthday.Value.Date; } showEntity.Actors.Add(actorEntity); } dbShows.Add(showEntity); } dbContext.Shows.AddRange(dbShows); dbContext.SaveChanges(); }
public ShowsController(RtlDbContext sc) { showContext = sc; }
public static double getTotalpageCount(RtlDbContext showContext) { return(Math.Ceiling((double)showContext.Shows.LongCount() / PAGE_ITEM_COUNT)); }