public IActionResult GetDataBotStore([FromBody] BotStoreRequest requestData) { using (var context = new tasktDbContext()) { if (!context.Workers.Any(f => f.WorkerID == requestData.workerID)) { return(Unauthorized()); } var requestedItem = context.BotStore.Where(f => f.BotStoreName == requestData.BotStoreName).FirstOrDefault(); if (requestedItem == null) { return(NotFound()); } switch (requestData.requestType) { case BotStoreRequest.RequestType.BotStoreValue: return(Ok(requestedItem.BotStoreValue)); case BotStoreRequest.RequestType.BotStoreModel: return(Ok(requestedItem)); default: return(StatusCode(400)); } } }
public static string GetData(string key, BotStoreRequestType requestType) { var botStoreRequest = new BotStoreRequest(); botStoreRequest.BotStoreName = key; botStoreRequest.WorkerID = _appSettings.ServerSettings.HTTPGuid; botStoreRequest.RequestType = requestType; var scriptJson = JsonConvert.SerializeObject(botStoreRequest); //create webclient and upload WebClient webClient = new WebClient(); webClient.Headers["Content-Type"] = "application/json"; var api = new Uri(_appSettings.ServerSettings.HTTPServerURL + "/api/BotStore/Get"); return(webClient.UploadString(api, "POST", scriptJson)); }