Пример #1
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();
            }
        }
Пример #2
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();
            }
        }