示例#1
0
        public async Task <IActionResult> Edit(UserForEdit userForEdit)
        {
            if (userForEdit != null && ModelState.IsValid)
            {
                IdentityResult result = await _dataProcessingConveyor.EditUserAsync(userForEdit);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    string errorText, key;
                    foreach (var error in result.Errors)
                    {
                        errorText = error.Description;
                        key       = String.Empty;
                        if (error.Code == "DuplicateUserName")
                        {
                            errorText = "Имя уже занято, выберете другое";
                            key       = "Name";
                        }
                        ModelState.AddModelError(key, errorText);
                    }
                    return(View(userForEdit));
                }
            }
            return(View(userForEdit));
        }