public override void Execute()
        {
            using (AppDbContext db = new AppDbContext())
            {
                Program.Logger.Debug($"{GetType().Name}: Searching user's settings in database");
                var settings = db.GetSettingsByUser(db.GetUserByTelegramId(Message.From.Id));
                var text = GetMessageContent(settings);
                Program.Logger.Debug($"{GetType().Name}: Sending commands list");
                try
                {
                    TelegramApi.SendMessage(Message.From, text);
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while sending commands list", e);
                }

                bool newSettings = false;
                if (settings == null)
                {
                    Program.Logger.Debug($"{GetType().Name}: Creating new settings for {Message.From}");
                    newSettings = true;
                    settings = new Settings { User = db.GetUserByTelegramId(Message.From.Id) };
                }

                Message msg;
                do
                {
                    Program.Logger.Debug($"{GetType().Name}: Waiting for a command");
                    try
                    {
                        msg = TelegramApi.WaitForMessage(Message.From);
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"{GetType().Name}: An error occurred while waiting for a command", e);
                    }

                    SetSetting(settings, msg);
                }
                while (msg.Text != SaveSettingsCommand && msg.Text != CancelCommand);

                if (msg.Text == SaveSettingsCommand)
                {
                    Program.Logger.Debug($"{GetType().Name}: Saving changes to database");
                    if (newSettings)
                    {
                        db.Settings.Add(settings);
                    }

                    db.SaveChanges();
                }
                else
                {
                    Program.Logger.Debug($"{GetType().Name}: Exiting without saving changes to database");
                }
            }

            Status = true;
        }
        public override void Execute()
        {
            using (AppDbContext db = new AppDbContext())
            {
                Program.Logger.Debug($"{GetType().Name}: Searching user with TelegramId: {Message.From.Id} in database");
                var user = db.GetUserByTelegramId(Message.From.Id);
                if (user == null)
                {
                    user = new User
                    {
                        TelegramUserId = Message.From.Id,
                        FirstName = Message.From.FirstName,
                        LastName = Message.From.LastName,
                        Username = Message.From.Username
                    };

                    Program.Logger.Info($"{GetType().Name}: {user} is new User");
                    Program.Logger.Debug($"{GetType().Name}: Adding user {user} to database");
                    db.Users.Add(user);
                }
                else
                {
                    Program.Logger.Debug($"{GetType().Name}: User {user} is already exist");
                }

                Program.Logger.Debug($"{GetType().Name}: Subscribing {user} to all shows");
                var subscriptions = user.Subscriptions.ToList();
                foreach (Show show in db.Shows)
                {
                    Subscription subscription = new Subscription
                    {
                        User = user,
                        Show = show,
                        SubscriptionDate = DateTime.Now
                    };

                    if (subscriptions.Any(s => Equals(s.Show, show)))
                    {
                        continue;
                    }

                    db.Subscriptions.Add(subscription);
                }

                Program.Logger.Debug($"{GetType().Name}: Saving changes to database");
                db.SaveChanges();
            }

            Program.Logger.Debug($"{GetType().Name}: Sending response to {Message.From}");
            try
            {
                TelegramApi.SendMessage(Message.From, "Вы, братишка, подписаны на все сериалы");
            }
            catch (Exception e)
            {
                throw new Exception($"{GetType().Name}: An error occurred while sending response to {Message.From}", e);
            }

            Status = true;
        }
        public override void Execute()
        {
            using (var db = new AppDbContext())
            {
                User user = db.GetUserByTelegramId(Message.From.Id);
                if (user == null || !user.Subscriptions.Any())
                {
                    SendResponse("Вы не подписаны ни на один сериал");
                    Status = true;
                    return;
                }

                if (ShowId != null)
                {
                    var show = db.GetShowById(ShowId.Value);
                    if (show == null)
                    {
                        SendResponse($"Сериал с идентификатором {ShowId} не найден");
                    }
                    else
                    {
                        var response = Unsubscribe(user, show);
                        SendResponse(response);
                    }
                }
                else
                {
                    SendSubscriptions(user, GetMessageSize());
                }
            }

            Status = true;
        }
        public override void Execute()
        {
            User user;
            List<Show> userShows = null;
            using (var db = new AppDbContext())
            {
                Program.Logger.Debug(
                    $"{GetType().Name}: Searching user with TelegramId: {Message.From.Id} in database");
                try
                {
                    user = db.GetUserByTelegramId(Message.From.Id);
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while searching user in database", e);
                }

                if (user == null)
                {
                    Program.Logger.Debug($"{GetType().Name}: User {Message.From} is not exists");
                }
                else
                {
                    Program.Logger.Debug($"{GetType().Name}: Retrieving user's subscriptions");
                    try
                    {
                        userShows = db.Subscriptions
                            .Where(s => s.User.Id == user.Id)
                            .Select(s => s.Show)
                            .ToList();
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"{GetType().Name}: An error occurred while retrieving user's subscriptions", e);
                    }
                }
            }

            if (userShows == null || userShows.Count == 0)
            {
                Program.Logger.Debug($"{GetType().Name}: Sending response to {Message.From}");
                try
                {
                    TelegramApi.SendMessage(Message.From, "Вы не подписаны ни на один сериал");
                }
                catch (Exception e)
                {
                    throw new Exception(
                        $"{GetType().Name}: An error occurred while sending response to {Message.From}", e);
                }

                Status = true;
                return;
            }

            List<string> pages = GetPages(userShows.Select(s => $"- {s.Title} ({s.OriginalTitle})").ToList(), MaxPageSize);
            SendPages(pages);
            Status = true;
        }
        public override void Execute()
        {
            Show show;
            string showTitle = string.Empty;
            bool subscribeById = ShowId != null;
            if (ShowId == null)
            {
                int messageSize;
                int.TryParse(Arguments, out messageSize);
                if (messageSize == 0)
                {
                    messageSize = MaxPageSize;
                }
                messageSize = Math.Min(messageSize, MaxPageSize);

                ShowId = RequestShow(out showTitle);
                if (ShowId == null)
                {
                    SendShowList(showTitle, messageSize);
                    Status = true;
                    return;
                }
            }

            string response;
            Program.Logger.Info($"{GetType().Name}: {Message.From} is trying to subscribe to '{(subscribeById ? $"Id = {ShowId}" : showTitle)}'");
            using (AppDbContext db = new AppDbContext())
            {
                show = db.GetShowById(ShowId.Value);
                if (show == null)
                {
                    Program.Logger.Info($"{GetType().Name}: Show '{(subscribeById ? $"Id = {ShowId}" : showTitle)}' was not found");
                    response = $"Сериал '{(subscribeById ? $"Id = {ShowId}" : showTitle)}' не найден";
                    Program.Logger.Debug($"{GetType().Name}: Sending response to {Message.From}");
                    try
                    {
                        TelegramApi.SendMessage(Message.From, response);
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"{GetType().Name}: An error occurred while sending response to {Message.From}", e);
                    }
                    Status = true;
                    return;
                }

                Program.Logger.Debug($"{GetType().Name}: Searching user with TelegramId: {Message.From.Id} in database");
                User user;
                try
                {
                    user = db.GetUserByTelegramId(Message.From.Id);
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while searching user in database", e);
                }
                bool newUser = false;
                if (user == null)
                {
                    user = new User
                    {
                        TelegramUserId = Message.From.Id,
                        FirstName = Message.From.FirstName,
                        LastName = Message.From.LastName,
                        Username = Message.From.Username
                    };
                    newUser = true;
                }

                if (newUser)
                {
                    Program.Logger.Info($"{GetType().Name}: {user} is new User");
                }
                else
                {
                    Program.Logger.Debug($"{GetType().Name}: User {user} is already exist");
                }

                bool subscriptionExists;
                Program.Logger.Debug($"{GetType().Name}: Checking for subscription existence");
                try
                {
                    subscriptionExists = user.Subscriptions.Any(s => s.Show.Id == show.Id);
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while checking for subscription existence", e);
                }
                if (subscriptionExists)
                {
                    Program.Logger.Info($"{GetType().Name}: User {Message.From} is already subscribed to {show.OriginalTitle}");
                    response = $"Вы уже подписаны на сериал '{show.Title}'";
                }
                else
                {
                    Subscription subscription = new Subscription
                    {
                        User = user,
                        Show = show,
                        SubscriptionDate = DateTimeOffset.Now
                    };

                    if (newUser)
                    {
                        user.Subscriptions.Add(subscription);
                        db.Users.Add(user);
                    }
                    else
                    {
                        db.Subscriptions.Add(subscription);
                    }
                    response = $"Вы подписались на сериал '{show.Title}'";
                }

                Program.Logger.Debug($"{GetType().Name}: Saving changes to database");
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while saving changes to database", e);
                }
            }

            Program.Logger.Debug($"{GetType().Name}: Sending response to {Message.From}");
            try
            {
                TelegramApi.SendMessage(Message.From, response);
            }
            catch (Exception e)
            {
                throw new Exception($"{GetType().Name}: An error occurred while sending response to {Message.From}", e);
            }

            Status = true;
        }
 private User GetUser(Telegram.User user)
 {
     using (AppDbContext db = new AppDbContext())
     {
         Program.Logger.Debug($"{GetType().Name}: Searching user with TelegramId: {user.Id} in database");
         try
         {
             return db.GetUserByTelegramId(user.Id);
         }
         catch (Exception e)
         {
             throw new Exception($"{GetType().Name}: An error occurred while searching user in database", e);
         }
     }
 }
        public override void Execute()
        {
            string response;
            using (var db = new AppDbContext())
            {
                do
                {
                    Program.Logger.Debug($"{GetType().Name}: Searching user with TelegramId: {Message.From.Id} in database");
                    var user = db.GetUserByTelegramId(Message.From.Id);
                    if (user == null)
                    {
                        Program.Logger.Debug($"{GetType().Name}: User with TelegramId: {Message.From.Id} is not found");
                        response = "Вы не подписаны ни на один сериал";
                        break;
                    }

                    var subscriptions = user.Subscriptions;
                    if (!subscriptions.Any())
                    {
                        Program.Logger.Debug($"{GetType().Name}: {user} has no subscriptions");
                        response = "Вы не подписаны ни на один сериал";
                        break;
                    }

                    Program.Logger.Debug($"{GetType().Name}: Sending the confirmation message to {user}");
                    try
                    {
                        TelegramApi.SendMessage(Message.From, "Вы действительно хотите отписаться от всех сериалов?\n/yes /no");
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"{GetType().Name}: An error occurred while sending the confirmation message to {user}", e);
                    }

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

                    if (msg.Text.ToLower() != "/yes")
                    {
                        Program.Logger.Debug($"{GetType().Name}: {user} cancel command");
                        Status = true;
                    }

                    Program.Logger.Debug($"{GetType().Name}: Deleting notifications for all subscriptions");
                    foreach (var subscription in subscriptions)
                    {
                        db.Notifications.RemoveRange(db.Notifications.Where(n => n.Subscription.Id == subscription.Id));
                    }

                    Program.Logger.Debug($"{GetType().Name}: Deleting all subscriptions");
                    db.Subscriptions.RemoveRange(subscriptions);
                    response = "Вы отписались от всех сериалов";
                }
                while (false);

                Program.Logger.Debug($"{GetType().Name}: Saving changes to database");
                db.SaveChanges();
            }

            Program.Logger.Debug($"{GetType().Name}: Sending response to {Message.From}");
            try
            {
                TelegramApi.SendMessage(Message.From, response);
            }
            catch (Exception e)
            {
                throw new Exception($"{GetType().Name}: An error occurred while sending response to {Message.From}", e);
            }

            Status = true;
        }
        public override void Execute()
        {
            using (AppDbContext db = new AppDbContext())
            {
                Settings settings = null;
                Program.Logger.Debug($"{GetType().Name}: Searching user's settings in database");
                try
                {
                    settings = db.GetSettingsByUser(db.GetUserByTelegramId(Message.From.Id));
                }
                catch (Exception e)
                {
                    Program.Logger.Error(e, $"{GetType().Name}: An error occurred while searching user's settings in database");
                }

                string text =
                    $"{(String.IsNullOrEmpty(settings?.WebUiUrl) ? "*" : String.Empty)}Адрес web-интерфейса uTorrent: {WebUiUrlSetCommand}\n" +
                    $"{(String.IsNullOrEmpty(settings?._WebUiPassword) ? "*" : String.Empty)}Пароль web-интерфейса uTorrent: {WebUiPasswordSetCommand}\n" +
                    $"{(String.IsNullOrEmpty(settings?.SiteLogin) ? "*" : String.Empty)}Имя учетной записи LostFilm.tv: {SiteLoginSetCommand}\n" +
                    $"{(String.IsNullOrEmpty(settings?._SitePassword) ? "*" : String.Empty)}Пароль учетной записи LostFilm.tv: {SitePasswordSetCommand}\n" +
                    $"Сохранить настройки: {SaveSettingsCommand}\n" +
                    $"Выйти без сохранения изменений: {CancelCommand}";

                Program.Logger.Debug($"{GetType().Name}: Sending commands list");
                try
                {
                    TelegramApi.SendMessage(Message.From, text);
                }
                catch (Exception e)
                {
                    throw new Exception($"{GetType().Name}: An error occurred while sending commands list", e);
                }

                bool newSettings = false;
                if (settings == null)
                {
                    Program.Logger.Debug($"{GetType().Name}: Creating new settings for {Message.From}");
                    newSettings = true;
                    settings = new Settings {User = db.GetUserByTelegramId(Message.From.Id)};
                }

                Message msg;
                do
                {
                    Program.Logger.Debug($"{GetType().Name}: Waiting for a command");
                    try
                    {
                        msg = TelegramApi.WaitForMessage(Message.From);
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"{GetType().Name}: An error occurred while waiting for a command", e);
                    }

                    switch (msg.Text)
                    {
                        case WebUiUrlSetCommand:
                            Program.Logger.Debug($"{GetType().Name}: {WebUiUrlSetCommand} command received");
                            settings.WebUiUrl = TelegramApi.WaitForMessage(Message.From).Text;
                            break;
                        case WebUiPasswordSetCommand:
                            Program.Logger.Debug($"{GetType().Name}: {WebUiPasswordSetCommand} command received");
                            settings.WebUiPassword = TelegramApi.WaitForMessage(Message.From).Text;
                            break;
                        case SiteLoginSetCommand:
                            Program.Logger.Debug($"{GetType().Name}: {SiteLoginSetCommand} command received");
                            settings.SiteLogin = TelegramApi.WaitForMessage(Message.From).Text;
                            break;
                        case SitePasswordSetCommand:
                            Program.Logger.Debug($"{GetType().Name}: {SitePasswordSetCommand} command received");
                            settings.SitePassword = TelegramApi.WaitForMessage(Message.From).Text;
                            break;
                        case SaveSettingsCommand:
                            Program.Logger.Debug($"{GetType().Name}: {SaveSettingsCommand} command received");
                            break;
                        case CancelCommand:
                            Program.Logger.Debug($"{GetType().Name}: {CancelCommand} command received");
                            break;
                        default:
                            Program.Logger.Debug($"{GetType().Name}: Unknown command received");
                            TelegramApi.SendMessage(Message.From, "Пощади, братишка");
                            break;
                    }
                } while (msg.Text != SaveSettingsCommand && msg.Text != CancelCommand);

                if (msg.Text == SaveSettingsCommand)
                {
                    Program.Logger.Debug($"{GetType().Name}: Saving changes to database");
                    try
                    {
                        if (newSettings)
                        {
                            db.Settings.Add(settings);
                        }
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"{GetType().Name}: An error occurred while saving changes to database", e);
                    }
                }
                else
                {
                    Program.Logger.Debug($"{GetType().Name}: Exiting without saving changes to database");
                }
            }
            Status = true;
        }
        public override void Execute()
        {
            Show show;
            string showTitle = string.Empty;
            bool subscribeById = ShowId != null;
            if (ShowId == null)
            {
                bool showFound = RequestShow(out showTitle);
                if (!showFound)
                {
                    SendShowList(showTitle, GetMessageSize());
                }

                Status = true;
                return;
            }

            string response;
            Program.Logger.Info($"{GetType().Name}: {Message.From} is trying to subscribe to '{(subscribeById ? $"Id = {ShowId}" : showTitle)}'");
            using (AppDbContext db = new AppDbContext())
            {
                show = db.GetShowById(ShowId.Value);
                if (show == null)
                {
                    Program.Logger.Info($"{GetType().Name}: Show '{(subscribeById ? $"Id = {ShowId}" : showTitle)}' was not found");
                    response = $"Сериал '{(subscribeById ? $"Id = {ShowId}" : showTitle)}' не найден";
                    Program.Logger.Debug($"{GetType().Name}: Sending response to {Message.From}");
                    try
                    {
                        TelegramApi.SendMessage(Message.From, response);
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"{GetType().Name}: An error occurred while sending response to {Message.From}", e);
                    }

                    Status = true;
                    return;
                }

                Program.Logger.Debug($"{GetType().Name}: Searching user with TelegramId: {Message.From.Id} in database");
                var user = db.GetUserByTelegramId(Message.From.Id);
                bool newUser = false;
                if (user == null)
                {
                    user = new User
                    {
                        TelegramUserId = Message.From.Id,
                        FirstName = Message.From.FirstName,
                        LastName = Message.From.LastName,
                        Username = Message.From.Username
                    };

                    newUser = true;
                }

                Program.Logger.Debug($"{GetType().Name}: Checking for subscription existence");
                var subscriptionExists = user.Subscriptions.Any(s => s.Show.Id == show.Id);
                if (subscriptionExists)
                {
                    Program.Logger.Info($"{GetType().Name}: User {Message.From} is already subscribed to {show.OriginalTitle}");
                    response = $"Вы уже подписаны на сериал \"{show.Title}\" ({show.SiteType.Title})";
                }
                else
                {
                    Subscribe(db, user, show, newUser);
                    response = $"Вы подписались на сериал \"{show.Title}\" ({show.SiteType.Title})";
                }

                Program.Logger.Debug($"{GetType().Name}: Saving changes to database");
                db.SaveChanges();
            }

            Program.Logger.Debug($"{GetType().Name}: Sending response to {Message.From}");
            try
            {
                TelegramApi.SendMessage(Message.From, response);
            }
            catch (Exception e)
            {
                throw new Exception($"{GetType().Name}: An error occurred while sending response to {Message.From}", e);
            }

            Status = true;
        }