Пример #1
0
 public async Task <IEnumerable <Title> > GetTitlesAsync()
 {
     using (var db = new TitlesContext())
     {
         return(await db.Title.ToListAsync());
     }
 }
Пример #2
0
 public async Task <IEnumerable <TitleGenreDetails> > GetGenresByTitleIdAsync(int titleId)
 {
     using (var db = new TitlesContext())
     {
         var query = from tg in db.TitleGenres
                     join g in db.Genres on tg.GenreId equals g.Id
                     where tg.TitleId == titleId
                     select new TitleGenreDetails
         {
             Id   = tg.Id,
             Name = tg.Genre.Name
         };
         return(await query.ToListAsync());
     }
 }
Пример #3
0
        public async Task <IEnumerable <StoryLine> > GetStoryLineByTitleIdAsync(int titleId)
        {
            using (var db = new TitlesContext())
            {
                var results = await db.StoryLines.Where(s => s.TitleId == titleId).Select(s => new StoryLine
                {
                    Id          = s.Id,
                    TitleId     = s.TitleId,
                    Type        = s.Type,
                    Language    = s.Language,
                    Description = s.Description
                }).ToListAsync();

                return(results);
            }
        }
Пример #4
0
 public async Task <IEnumerable <Participant> > GetPatricipantByTitleIdAsync(int titleId)
 {
     using (var db = new TitlesContext())
     {
         var query = from tp in db.TitleParticipants
                     join p in db.Participants on tp.Id equals p.Id
                     where tp.TitleId == titleId
                     select new Participant
         {
             Id              = p.Id,
             Name            = p.Name,
             ParticipantType = p.ParticipantType
         };
         return(await query.ToListAsync());
     }
 }
Пример #5
0
        public async Task <IEnumerable <Award> > GetAwardsByTitleIdAsync(int titleId)
        {
            using (var db = new TitlesContext())
            {
                var results = await db.Awards.Where(a => a.TitleId == titleId).Select(a => new Award
                {
                    Id           = a.Id,
                    TitleId      = a.TitleId,
                    Award1       = a.Award1,
                    AwardWon     = a.AwardWon,
                    AwardYear    = a.AwardYear,
                    AwardCompany = a.AwardCompany
                }).ToListAsync();

                return(results);
            }
        }
Пример #6
0
        public async Task <IEnumerable <OtherName> > GetOtherTitleByTitleIdAsync(int titleId)
        {
            using (var db = new TitlesContext())
            {
                var results = await db.OtherNames.Where(o => o.TitleId == titleId).Select(o => new OtherName
                {
                    TitleId           = o.TitleId,
                    TitleNameLanguage = o.TitleNameLanguage,
                    TitleNameType     = o.TitleNameType,
                    TitleNameSortable = o.TitleNameSortable,
                    TitleName         = o.TitleName,
                    Id = o.Id
                }).OrderBy(o => o.TitleNameSortable).ToListAsync();

                return(results);
            }
        }
Пример #7
0
 public Handler(TitlesContext context)
 {
     _context = context;
 }
Пример #8
0
 public TitlesController(TitlesContext context)
 {
     _context = context;
 }
Пример #9
0
        public async Task <IEnumerable <Title> > SearchByNameAsyc(string searchString)
        {
            using (var db = new TitlesContext())
            {
                var titles = await db.Title.Where(t => EF.Functions.Like(t.TitleName, "%" + searchString + "%")).Select(t => new Title
                {
                    TitleId              = t.TitleId,
                    TitleName            = t.TitleName,
                    TitleNameSortable    = t.TitleNameSortable,
                    TitleTypeId          = t.TitleTypeId,
                    ReleaseYear          = t.ReleaseYear,
                    ProcessedDateTimeUtc = t.ProcessedDateTimeUtc
                }).OrderBy(t => t.TitleNameSortable).ToListAsync();

                var ids = titles.Select(t => t.TitleId).ToList();
                if (ids.Any())
                {
                    foreach (var id in ids)
                    {
                        var participants = from tp in db.TitleParticipants
                                           join p in db.Participants on tp.Id equals p.Id
                                           where tp.TitleId == id
                                           select new TitleParticipant
                        {
                            Id            = tp.Id,
                            TitleId       = tp.TitleId,
                            ParticipantId = tp.ParticipantId,
                            IsKey         = tp.IsKey,
                            RoleType      = tp.RoleType,
                            IsOnScreen    = tp.IsOnScreen,
                            Name          = tp.Participant.Name
                        };
                        var title = titles.Where(x => x.TitleId == id).FirstOrDefault();
                        foreach (var participant in participants)
                        {
                            title.TitleParticipants.Add(participant);
                        }
                        var titleGenres = from tg in db.TitleGenres
                                          join g in db.Genres on tg.GenreId equals g.Id
                                          where tg.TitleId == id
                                          select new TitleGenre
                        {
                            Id      = tg.Id,
                            Name    = g.Name,
                            GenreId = tg.GenreId
                        };
                        foreach (var titleGenre in titleGenres)
                        {
                            title.TitleGenres.Add(titleGenre);
                        }
                        var storyLines = await db.StoryLines.Where(s => s.TitleId == id).Select(s => new StoryLine
                        {
                            TitleId     = s.TitleId,
                            Type        = s.Type,
                            Language    = s.Language,
                            Description = s.Description
                        }).ToListAsync();

                        foreach (var storyLine in storyLines)
                        {
                            title.StoryLines.Add(storyLine);
                        }
                        var awards = await db.Awards.Where(a => a.TitleId == id).Select(a => new Award
                        {
                            TitleId      = a.TitleId,
                            AwardWon     = a.AwardWon,
                            AwardYear    = a.AwardYear,
                            AwardCompany = a.AwardCompany,
                            Award1       = a.Award1
                        }).ToListAsync();

                        foreach (var award in awards)
                        {
                            title.Awards.Add(award);
                        }
                    }
                }
                return(titles);
            }
        }