Beispiel #1
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (_loaded)
            {
                return;
            }

            _loaded = true;

            _creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
                        StartsWith("admin/instruction_sets/create",
                                   StringComparison.InvariantCulture);

            if (Id <= 0 &&
                !_creating)
            {
                return;
            }

            _model = _creating ? new Database.Models.InstructionSet() : await Service.GetAsync(Id);

            _authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();

            _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
                       StartsWith("admin/instruction_sets/edit/",
                                  StringComparison.InvariantCulture);

            StateHasChanged();
        }
Beispiel #2
0
        async void OnCancelClicked()
        {
            _editing = false;

            if (_creating)
            {
                NavigationManager.ToBaseRelativePath("admin/instruction_sets");

                return;
            }

            _model = await Service.GetAsync(Id);

            StateHasChanged();
        }
Beispiel #3
0
        async void OnSaveClicked()
        {
            if (string.IsNullOrWhiteSpace(_model.Name) ||
                _model.Name.Length > 45 ||
                !Service.VerifyUnique(_model.Name))
            {
                return;
            }

            if (_creating)
            {
                Id = await Service.CreateAsync(_model, (await UserManager.GetUserAsync(_authState.User)).Id);
            }
            else
            {
                await Service.UpdateAsync(_model, (await UserManager.GetUserAsync(_authState.User)).Id);
            }

            _editing  = false;
            _creating = false;
            _model    = await Service.GetAsync(Id);

            StateHasChanged();
        }