Exemple #1
0
        public async Task <IActionResult> Edit(EditViewModel model, int id)
        {
            if (ModelState.IsValid)
            {
                var roles = model.Roles
                            .FindAll(r => r.IsOptionSelected)
                            .Select(r => r.Name)
                            .ToList();

                if (roles.Count == 0)
                {
                    ModelState.AddModelError("", "Выберите хотя бы одну роль");
                    return(View(model));
                }

                var user = await _userData.EditUser(id, model.Email, model.Phone, model.Name, model.LastName, model.Patronymic,
                                                    model.Password, roles);

                if (user != null)
                {
                    return(RedirectToAction("Index", "Admin"));
                }

                ModelState.AddModelError("", "Пользователь с таким Email уже существует");
            }

            return(View(model));
        }
        public void EditUser(User updatedUser)
        {
            var currentUser = userProvider.GetUserByName(updatedUser.UserName);

            if (userProvider.IsExistsByEmail(updatedUser.Email) && currentUser.Email != updatedUser.Email)
            {
                throw new CreateOrUpdateUserException(UserCreateStatus.DuplicateEmail);
            }

            userDataService.EditUser(updatedUser);
        }