Пример #1
0
        // -----------------
        // Edit Signature
        // -----------------

        public async Task <IActionResult> EditSignature()
        {
            // Get authenticated user
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // Ensure user is authenticated
            if (user == null)
            {
                return(Unauthorized());
            }

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Your Account"]);
            });

            // Build view model
            var viewModel = new EditSignatureViewModel()
            {
                Id        = user.Id,
                Signature = user.Signature
            };

            // Return view
            return(View((LayoutViewModel)await _editSignatureViewProvider.ProvideEditAsync(viewModel, this)));
        }
Пример #2
0
        public async Task <IActionResult> EditSignaturePost(EditSignatureViewModel model)
        {
            var user = await _userManager.FindByIdAsync(model.Id.ToString());

            if (user == null)
            {
                return(NotFound());
            }

            // Validate model state within all view providers
            if (await _editSignatureViewProvider.IsModelStateValidAsync(model, this))
            {
                // Update user
                user.Signature = model.Signature;

                // Update user
                var result = await _platoUserManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    // Invoke BuildUpdateAsync within involved view providers
                    await _editSignatureViewProvider.ProvideUpdateAsync(model, this);

                    // Ensure model state is still valid after view providers have executed
                    if (ModelState.IsValid)
                    {
                        // Add confirmation
                        _alerter.Success(T["Signature Updated Successfully!"]);
                        // Redirect
                        return(RedirectToAction(nameof(EditSignature)));
                    }
                }
                else
                {
                    // Errors that may have occurred whilst updating the entity
                    foreach (var error in result.Errors)
                    {
                        ViewData.ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }

            // If errors occur manually expire the cache otherwise our
            // modifications made above to the object may persist as the
            // object is not updated and the cache is not invalidated by the store
            _platoUserStore.CancelTokens(user);

            // Display errors
            return(await EditSignature());
        }
Пример #3
0
        // -----------------
        // Edit Signature
        // -----------------

        public async Task <IActionResult> EditSignature()
        {
            // Get authenticated user
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // Ensure user is authenticated
            if (user == null)
            {
                return(Unauthorized());
            }

            // Return Url for authentication & canonical url purposes
            ViewData["ReturnUrl"] = _contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"]       = "Plato.Users",
                ["controller"] = "Home",
                ["action"]     = "EditSignature"
            });

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Your Account"]);
            });

            // Build view model
            var viewModel = new EditSignatureViewModel()
            {
                Id        = user.Id,
                Signature = user.Signature
            };

            // Return view
            return(View((LayoutViewModel)await _editSignatureViewProvider.ProvideEditAsync(viewModel, this)));
        }