Ejemplo n.º 1
0
        public override async Task Execute(Message message, TelegramBotClient client)
        {
            _client  = client;
            _message = message;

            if (IsTextStringLessThan8Char(_message.Text).Result)
            {
                return;
            }

            var text = message.Text.
                       Remove(0, 8).
                       TrimStart();

            if (!IsNameSeriesValid(text).Result)
            {
                return;
            }

            var series = _seriesRepository.GetByNameAllMatchSeries(text).ToList();

            if (!IsSeriesListValid(series).Result)
            {
                return;
            }

            var countSeries = series.
                              FindAll(s => s.IsCompleted).
                              Count;

            if (countSeries != 0)
            {
                var completedSeries = new StringBuilder();
                completedSeries.Append("Серилал(ы) завершившийся(еся):\n");
                foreach (var item in series)
                {
                    if (!item.IsCompleted)
                    {
                        continue;
                    }
                    completedSeries.Append(item.NameRu + ", ");
                }

                var startIndex            = completedSeries.Length - 2;
                var completedSeriesString = completedSeries
                                            .Remove(startIndex, 2)
                                            .Append(".")
                                            .ToString();

                await client.SendTextMessageAsync(message.Chat.Id, completedSeriesString);

                if (series.FindAll(s => s.IsCompleted).Count == series.Count)
                {
                    return;
                }
            }

            await SendSearchButtons(series);
        }