예제 #1
0
        private int? RequestShow(out string showTitle)
        {
            if (string.IsNullOrEmpty(Arguments))
            {
                Program.Logger.Debug($"{GetType().Name}: Sending 'Enter show title' prompt");
                try
                {
                    TelegramApi.SendMessage(Message.From, "Введите название сериала");
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while sending prompt", e);
                }

                Program.Logger.Debug($"{GetType().Name}: Waiting for a message that contains show title");
                try
                {
                    showTitle = TelegramApi.WaitForMessage(Message.From).Text;
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while waiting for a message that contains show title", e);
                }
            }
            else
            {
                showTitle = Arguments;
            }

            Show show;
            using (AppDbContext db = new AppDbContext())
            {
                Program.Logger.Debug($"{GetType().Name}: Searching show {showTitle} in database");
                try
                {
                    show = db.GetShowByTitle(showTitle);
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while searching show {showTitle} in database", e);
                }
            }
            return show?.Id;
        }
예제 #2
0
        private static void UpdateEpisodes(List<Show> shows)
        {
            using (var db = new AppDbContext())
            {
                foreach (var show in shows)
                {
                    var dbShow = db.GetShowByTitle(show.SiteTypeId, show.Title);
                    if (dbShow != null)
                    {
                        foreach (var episode in show.Episodes)
                        {
                            dbShow.Episodes.Add(episode);
                        }
                    }
                    else
                    {
                        db.Shows.Add(show);
                    }

                    Logger.Info($"{show.Title} - {string.Join(", ", show.Episodes.Select(e => e.Title))}");
                }

                db.SaveChanges();
            }
        }