Esempio n. 1
0
        /// <summary>
        /// Поиск постов
        /// </summary>
        /// <param name="search"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public async Task <ActionResult> SearchPosts(string search, List <Messangers> result)
        {
            if (result == null || !result.Any())
            {
                return(PartialView("_Results", await CheckPosts(await _vkService.GetPosts(search))));
            }

            foreach (var t in result)
            {
                switch (t)
                {
                case Messangers.YouTube:
                {
                    return(PartialView("_Results", await CheckPosts(await _youtubeService.GetVideos(search))));
                }

                case Messangers.Vk:
                {
                    return(PartialView("_Results", await CheckPosts(await _vkService.GetPosts(search))));
                }

                case Messangers.Telegram:
                {
                    try
                    {
                        var responce = await SetTaskTimeout <SearchModelResponse[]>(_telegramService.GetAudioAsync(search, 15));

                        return(PartialView("_Results", await CheckPosts(responce)));
                    }
                    catch (TimeoutException)
                    {
                        await _telegramService.RemoveSessionAsync();

                        return(RedirectToAction("Index"));
                    }
                    catch
                    {
                        return(null);
                    }
                }
                }
            }



            return(null);
        }