public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Не могу загрузить аккаунт с ID '{_userManager.GetUserId(User)}'.")); } if (!ModelState.IsValid) { await LoadAsync(user); return(Page()); } var profile = await _dbContext.Profiles .Include(p => p.Account) .AsNoTracking() .FirstOrDefaultAsync(p => p.Account.Id.Equals(user.Id)); profile.FirstName = Input.FName; profile.SecondName = Input.SName; profile.Patronymic = Input.Patronymic; _dbContext.Update(profile); await _dbContext.SaveChangesAsync(); StatusMessage = "Ваша персональная информация успешно изменена."; return(RedirectToPage()); }
/// <summary> /// Инициализация пользователей /// </summary> /// <returns></returns> private async Task UsersInitAsync() { if (_userManager.Users.Count() == 0) { Profile adminProfile = new Profile() { FirstName = "Администратор", SecondName = "Биллинга", Address = "Пушкина 9-15", Tariff = await _dbContext.Tariffs .FirstOrDefaultAsync(t => t.Name.Equals("Коллегиальный")), User = new User() { UserName = "******", Email = "admin@localhost", PhoneNumber = "099-999-99-99", EmailConfirmed = true, LockoutEnabled = true } }; var result = await _userManager.CreateAsync(adminProfile.User, _password); if (result.Succeeded) { var adminRole = [email protected](); adminProfile.User.RoleId = (await _roleManager.FindByNameAsync(adminRole)).Id; await _userManager.AddToRoleAsync(adminProfile.User, adminRole); await _dbContext.Profiles.AddAsync(adminProfile); await _dbContext.SaveChangesAsync(); } Profile operatorProfile = new Profile() { FirstName = "Оператор", SecondName = "Биллинга", Address = "Пушкина 9-15", Tariff = await _dbContext.Tariffs .FirstOrDefaultAsync(t => t.Name.Equals("Коллегиальный")), User = new User() { UserName = "******", Email = "operator@localhost", PhoneNumber = "099-999-99-99", EmailConfirmed = true, LockoutEnabled = true } }; result = await _userManager.CreateAsync(operatorProfile.User, _password); if (result.Succeeded) { var operatorRole = [email protected](); operatorProfile.User.RoleId = (await _roleManager.FindByNameAsync(operatorRole)).Id; await _userManager.AddToRoleAsync(operatorProfile.User, operatorRole); await _dbContext.Profiles.AddAsync(operatorProfile); await _dbContext.SaveChangesAsync(); } Profile casherProfile = new Profile() { FirstName = "Кассир", SecondName = "Биллинга", Address = "Пушкина 9-15", Tariff = await _dbContext.Tariffs .FirstOrDefaultAsync(t => t.Name.Equals("Коллегиальный")), User = new User() { UserName = "******", Email = "casher@localhost", PhoneNumber = "099-999-99-99", EmailConfirmed = true, LockoutEnabled = true } }; result = await _userManager.CreateAsync(casherProfile.User, _password); if (result.Succeeded) { var casherRole = Helpers.RoleName.casher.ToString(); casherProfile.User.RoleId = (await _roleManager.FindByNameAsync(casherRole)).Id; await _userManager.AddToRoleAsync(casherProfile.User, casherRole); await _dbContext.Profiles.AddAsync(casherProfile); await _dbContext.SaveChangesAsync(); } } }