コード例 #1
0
        private async Task <HttpResponseMessage> HttpClientPostOrderAsync(LicenseOrderDto licenseOrderDto)
        {
            var stringContent = new StringContent(JsonConvert.SerializeObject(licenseOrderDto), Encoding.UTF8, "application/json");
            var path          = $"api/Licenses/CreateLicenseOrder";
            var client        = await CreateHttpClient();

            return(await client.PostAsync(path, stringContent));
        }
コード例 #2
0
        public async Task SendOrderAsync(LicenseOrder licenseOrder)
        {
            var vaultLicenses = await GetLicensesByOrderIdAsync(licenseOrder.Id);

            if (vaultLicenses == null)
            {
                throw new Exception("Hardware vault licenses not found.");
            }

            var licensing = await _appSettingsService.GetLicensingSettingsAsync();

            if (licensing == null)
            {
                throw new Exception("Api Key is empty.");
            }

            var licenseOrderDto = new LicenseOrderDto()
            {
                Id                      = licenseOrder.Id,
                ContactEmail            = licenseOrder.ContactEmail,
                CustomerNote            = licenseOrder.Note,
                LicenseStartDate        = licenseOrder.StartDate,
                LicenseEndDate          = licenseOrder.EndDate,
                ProlongExistingLicenses = licenseOrder.ProlongExistingLicenses,
                CustomerId              = licensing.ApiKey,
                Devices                 = vaultLicenses.Select(d => d.HardwareVaultId).ToList()
            };

            var response = await HttpClientPostOrderAsync(licenseOrderDto);

            if (!response.IsSuccessStatusCode)
            {
                var errorMessage = await response.Content.ReadAsStringAsync();

                throw new Exception(errorMessage);
            }

            licenseOrder.OrderStatus = LicenseOrderStatus.Sent;
            await _licenseOrderRepository.UpdateOnlyPropAsync(licenseOrder, new string[] { "OrderStatus" });
        }