protected void NavigateToUserDetail(ADUser user)
 {
     if (!UserRepository.ADUserExists(user.Id))
     {
         UserRepository.Save(user);
     }
     NavigationManager.NavigateTo("/gebruiker/" + user.Id);
 }
Esempio n. 2
0
        protected async Task Submit()
        {
            var auth      = AuthenticationStateTask.Result;
            var stockuser = UserRepository.GetByEmail(auth.User.Identity.Name);

            if (string.IsNullOrWhiteSpace(_serialNumber))
            {
                ToastService.ShowWarning("Serienummer mag niet leeg zijn.");
                return;
            }
            _item.SerialNumber = Regex.Replace(_serialNumber, @"\s+", "");

            if (_selectedProduct == null)
            {
                ToastService.ShowWarning("Selecteer een product.");
                return;
            }
            _item.Product = _products.First(i => _selectedProduct == i.Id);
            if (_selectedSupplier == null)
            {
                ToastService.ShowWarning("Selecteer een leverancier.");
                return;
            }

            if (_initialStatus != _selectedStatus)
            {
                _item.ChangeStatus(_selectedStatus, stockuser);
            }

            if (_item.ItemStatus == ItemStatus.OUTSTOCK)
            {
                var selectedUser = userSearch.GetSelectedUser();
                if (selectedUser != null)
                {
                    if (_initialUser?.Id != selectedUser?.Id)
                    {
                        _item.ReturnToStock(stockuser);
                        ADUser newUser = null;

                        if (!UserRepository.ADUserExists(selectedUser.Id))
                        {
                            newUser = new ADUser(selectedUser);
                            Repository.Save(newUser);
                        }
                        else
                        {
                            newUser = (ADUser)UserRepository.GetById(typeof(ADUser), selectedUser.Id);
                        }

                        _item.RemoveFromStock(newUser, stockuser);
                    }
                }
            }

            _item.Supplier     = _suppliers.First(i => _selectedSupplier == i.Id);
            _item.Comment      = _comment;
            _item.DeliveryDate = _deliveryDate;
            _item.InvoiceDate  = _invoiceDate;

            _item.Carepack  = string.IsNullOrWhiteSpace(_carepack) ? null : _carepack;
            _item.Hostname  = string.IsNullOrWhiteSpace(_hostname) ? null : _hostname;
            _item.Imei      = string.IsNullOrWhiteSpace(_imei) ? null : _imei;
            _item.License   = string.IsNullOrWhiteSpace(_license) ? null : _license;
            _item.VGDNumber = string.IsNullOrWhiteSpace(_vgdnumber) ? null : _vgdnumber;
            try
            {
                Repository.Save(_item);
            } catch (Exception ex)
            {
                Telemetry.TrackException(ex);
                ToastService.ShowError("Kon item niet opslaan.");
            }

            if (!await _fileUpload.IsEmpty())
            {
                try
                {
                    await Upload(_item);
                }
                catch (Exception ex)
                {
                    Telemetry.TrackException(ex);
                    ToastService.ShowError("Kon foto niet opslaan.");
                }
            }
            Telemetry.TrackEvent("ItemUpdate");
            ToastService.ShowSuccess("Item succesvol geëditeerd.");
            NavigationManager.NavigateTo("itemhistoriek/" + _item.Id);
        }