Exemple #1
0
        public async Task <IActionResult> UploadSoftware([FromBody] SoftwareCreateViewModel model)
        {
            // Lock in bdd
            Result <int> result = await _softwareGateway.CreateSoftware(model.Name, model.Description);

            if (result.ErrorMessage == "Software with this name exists")
            {
                return(BadRequest(result.ErrorMessage));
            }

            SoftwareForDiggosViewModel contentForDiggos = new SoftwareForDiggosViewModel();

            contentForDiggos.Id          = result.Content;
            contentForDiggos.LinkProject = model.LinkProject;

            // Upload software on diggos
            HttpResponseMessage theLastResponse = await _diggosService.InstallSoftware(contentForDiggos);

            if (!theLastResponse.IsSuccessStatusCode)
            {
                // Delete in bdd
                await _softwareGateway.DeleteSoftware(result.Content);

                return(StatusCode(502, "Error on diggos"));
            }

            return(Ok(result.Content));
        }
Exemple #2
0
        public async Task <HttpResponseMessage> InstallSoftware(SoftwareForDiggosViewModel model)
        {
            string url       = _options.Value.Url + "Software/Install";
            string jsonModel = Json.Serialize <SoftwareForDiggosViewModel>(model);

            using (HttpClient client = new HttpClient())
                using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(url)))
                {
                    request.Content = new StringContent(jsonModel, Encoding.UTF8, "application/json");
                    request.Headers.Add("Authorization", string.Format("Bearer {0}", _tokenService.GenerateToken()));
                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        return(response);
                    }
                }
        }