예제 #1
0
        public async Task DeleteOrderAsync(LicenseOrder licenseOrder)
        {
            if (licenseOrder == null)
            {
                throw new Exception("Order does not exist.");
            }

            await _licenseOrderRepository.DeleteAsync(licenseOrder);
        }
예제 #2
0
        private async Task CreateRenewLicenseOrderAsync()
        {
            try
            {
                await ButtonSpinnerRenewOrder.SpinAsync(async() =>
                {
                    if (_renewLicenseOrder.EndDate < DateTime.Now)
                    {
                        ValidationErrorMessageRenewOrder.DisplayError(nameof(RenewLicenseOrder.EndDate), $"End Date must not be less than Start Date.");
                        return;
                    }

                    if (!_renewLicenseOrder.HardwareVaults.Where(x => x.Checked).Any())
                    {
                        ValidationErrorMessageRenewOrder.DisplayError(nameof(RenewLicenseOrder.HardwareVaults), $"Select at least one hardware vault.");
                        return;
                    }

                    var checkedHardwareVaults = _renewLicenseOrder.HardwareVaults.Where(x => x.Checked).ToList();
                    var maxEndDate            = checkedHardwareVaults.Select(x => x.LicenseEndDate).Max();

                    if (_renewLicenseOrder.EndDate < maxEndDate)
                    {
                        ValidationErrorMessageRenewOrder.DisplayError(nameof(RenewLicenseOrder.HardwareVaults), $"The selected End Date less than max end date for selected hardware vaults.");
                        return;
                    }

                    var licenseOrder = new LicenseOrder()
                    {
                        ContactEmail            = _renewLicenseOrder.ContactEmail,
                        Note                    = _renewLicenseOrder.Note,
                        ProlongExistingLicenses = true,
                        StartDate               = null,
                        EndDate                 = _renewLicenseOrder.EndDate.Date
                    };

                    await LicenseService.CreateOrderAsync(licenseOrder, checkedHardwareVaults);
                    await SynchronizationService.UpdateLicenses(ExceptPageId);
                    await ToastService.ShowToastAsync("Order created.", ToastType.Success);
                    await ModalDialogService.CloseAsync();
                });
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);

                await ModalDialogService.CloseAsync();
            }
        }
예제 #3
0
        public async Task <LicenseOrder> EditOrderAsync(LicenseOrder licenseOrder, List <HardwareVault> hardwareVaults)
        {
            if (licenseOrder == null)
            {
                throw new ArgumentNullException(nameof(licenseOrder));
            }

            using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                await _licenseOrderRepository.UpdateAsync(licenseOrder);
                await AddOrUpdateHardwareVaultEmptyLicensesAsync(licenseOrder.Id, hardwareVaults.Select(x => x.Id).ToList());

                transactionScope.Complete();
            }

            return(licenseOrder);
        }
예제 #4
0
        private async Task CreateNewLicenseOrderAsync()
        {
            try
            {
                await ButtonNewOrder.SpinAsync(async() =>
                {
                    if (_newLicenseOrder.StartDate < DateTime.Now.Date)
                    {
                        ValidationErrorMessageNewOrder.DisplayError(nameof(NewLicenseOrder.StartDate), $"Start Date must be at least current date.");
                        return;
                    }

                    if (_newLicenseOrder.EndDate < _newLicenseOrder.StartDate)
                    {
                        ValidationErrorMessageNewOrder.DisplayError(nameof(NewLicenseOrder.EndDate), $"End Date must not be less than Start Date.");
                        return;
                    }

                    if (!_newLicenseOrder.HardwareVaults.Where(x => x.Checked).Any())
                    {
                        ValidationErrorMessageNewOrder.DisplayError(nameof(NewLicenseOrder.HardwareVaults), $"Select at least one hardware vault.");
                        return;
                    }

                    var licenseOrder = new LicenseOrder()
                    {
                        ContactEmail            = _newLicenseOrder.ContactEmail,
                        Note                    = _newLicenseOrder.Note,
                        ProlongExistingLicenses = false,
                        StartDate               = _newLicenseOrder.StartDate.Date,
                        EndDate                 = _newLicenseOrder.EndDate.Date
                    };

                    var checkedHardwareVaults = _newLicenseOrder.HardwareVaults.Where(x => x.Checked).ToList();
                    await LicenseService.CreateOrderAsync(licenseOrder, checkedHardwareVaults);
                    await ToastService.ShowToastAsync("Order created.", ToastType.Success);
                    await ModalDialogClose();
                });
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
                await ModalDialogCancel();
            }
        }
예제 #5
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" });
        }