Esempio n. 1
0
        // subroutine of the http POST handler
        private IActionResult SaveCreatedOrEditedUser(string maintenanceMode, UsersViewModel uvm, string originalEmail)
        {
            User user = mapper.Map <User>(uvm);

            if (!ValidateUser(maintenanceMode, originalEmail, uvm, user))
            {
                new ViewBagConfigurer().ConfigureViewBag(ViewBag, maintenanceMode);
                return(View("Maintenance", uvm));
            }

            userService.AddOrReplaceUser(user, originalEmail);
            siteSecurityConfig.Refresh();
            UpdateRouteData(user.EmailAddress);
            LogDebug(user.Name, maintenanceMode);
            return(RedirectToAction(nameof(Index)));                    // total success
        }
Esempio n. 2
0
        public IActionResult UpdateUser(UsersViewModel usersviewmodel)
        {
            usersviewmodel.Active             = true;
            usersviewmodel.Ask                = true;
            usersviewmodel.NotifyOnAllComment = true;
            usersviewmodel.NotifyOnNewPost    = true;
            usersviewmodel.NotifyOnOwnComment = true;

            ModelState.Clear();

            if (string.IsNullOrWhiteSpace(usersviewmodel.Password))
            {
                ModelState.AddModelError("", "Invalid Password.");
            }

            if (string.IsNullOrWhiteSpace(usersviewmodel.DisplayName))
            {
                ModelState.AddModelError("", "Invalid Display Name.");
            }

            if (string.IsNullOrWhiteSpace(usersviewmodel.EmailAddress))
            {
                ModelState.AddModelError("", "Invalid Email Address.");
            }

            if (ModelState.ErrorCount > 0)
            {
                return(View("ViewEditUser", usersviewmodel));
            }

            var dasbloguser = mapper.Map <User>(usersviewmodel);

            userService.AddOrReplaceUser(dasbloguser, usersviewmodel.OriginalEmail);
            siteSecurityConfig.Refresh();

            var uvm = mapper.Map <UsersViewModel>(userService.GetFirstUser());

            logger.LogInformation(new EventDataItem(EventCodes.EditUser, null, "Edit User: {0}", uvm.DisplayName));

            return(Index());
        }