public JsonResult GetBot(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Json(false));
            }

            var botDto = _botsRepository.GetBot(id);

            return(botDto != null
                                ? Json(botDto.Transform())
                                : Json(false));
        }
Esempio n. 2
0
        public async static Task <BotViewModel> GetBotViewModel(string id, IConfiguration _configuration, BotsRepository _botsRepository)
        {
            var httpClient = new HttpClient();

            var bot = _botsRepository.GetBot(id);

            var botResult = await httpClient.GetStringAsync($"{_configuration["RunnerApiUrl"]}/check?id={id}");

            var botParsedResult = JsonConvert.DeserializeObject <Response>(botResult);

            var botViewModel = new BotViewModel
            {
                Bot    = bot,
                Status = Convert.ToBoolean(botParsedResult.status)
            };

            return(botViewModel);
        }
Esempio n. 3
0
        public async static Task <IEnumerable <BotViewModel> > GetBotsViewModels(IConfiguration _configuration,
                                                                                 SystemUserRepository _botsRepository, BotsRepository botsRepository, string userId)
        {
            var httpClient = new HttpClient();

            var bots = _botsRepository.GetUserBots(userId) ?? new List <string>();

            var botsViewModels = await Task.WhenAll(bots.Select(async _ =>
            {
                var result       = await httpClient.GetStringAsync($"{_configuration["RunnerApiUrl"]}/check?id={_}");
                var parsedResult = JsonConvert.DeserializeObject <Response>(result);
                return(new BotViewModel
                {
                    Bot = botsRepository.GetBot(_),
                    Status = parsedResult.status
                });
            }));

            return(botsViewModels);
        }