public async void Test_GivennUser_WhenUpdateUser_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.UpdateAsync(It.IsAny <CognitoUser>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); var output = await userManager.UpdateAsync(GetCognitoUser()).ConfigureAwait(false); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } if (!ModelState.IsValid) { await LoadAsync(user); return(Page()); } user.Attributes[CognitoAttribute.Address.AttributeName] = Input.Address; user.Attributes[CognitoAttribute.BirthDate.AttributeName] = Input.BirthDate; user.Attributes[CognitoAttribute.Gender.AttributeName] = Input.Gender; user.Attributes[CognitoAttribute.NickName.AttributeName] = Input.NickName; user.Attributes[CognitoAttribute.PhoneNumber.AttributeName] = Input.PhoneNumber; user.Attributes[CognitoAttribute.FamilyName.AttributeName] = Input.FamilyName; user.Attributes[CognitoAttribute.GivenName.AttributeName] = Input.GivenName; var result = await _userManager.UpdateAsync(user); return(RedirectToPage()); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } if (!ModelState.IsValid) { await LoadAsync(user); return(Page()); } if (string.IsNullOrWhiteSpace(Input.FamilyName)) { Input.FamilyName = "default"; } if (string.IsNullOrWhiteSpace(Input.Address)) { Input.Address = "default"; } if (string.IsNullOrWhiteSpace(Input.Gender)) { Input.Gender = "default"; } if (string.IsNullOrWhiteSpace(Input.GivenName)) { Input.GivenName = "default"; } if (string.IsNullOrWhiteSpace(Input.BirthDate)) { Input.BirthDate = "0000-00-00"; } if (string.IsNullOrWhiteSpace(Input.PhoneNumber)) { Input.PhoneNumber = "+01234567890"; } if (string.IsNullOrWhiteSpace(Input.NickName)) { Input.NickName = "default"; } if (string.IsNullOrWhiteSpace(Input.AddressLine1)) { Input.AddressLine1 = "default"; } if (string.IsNullOrWhiteSpace(Input.AddressLine2)) { Input.AddressLine2 = "default"; } if (string.IsNullOrWhiteSpace(Input.City)) { Input.City = "default"; } if (string.IsNullOrWhiteSpace(Input.State)) { Input.State = "default"; } if (string.IsNullOrWhiteSpace(Input.Country)) { Input.Country = "default"; } if (string.IsNullOrWhiteSpace(Input.ZipCode)) { Input.ZipCode = "default"; } //update cognito user.Attributes[CognitoAttribute.Address.AttributeName] = Input.Address; user.Attributes[CognitoAttribute.BirthDate.AttributeName] = Input.BirthDate; user.Attributes[CognitoAttribute.Gender.AttributeName] = Input.Gender; user.Attributes[CognitoAttribute.NickName.AttributeName] = Input.NickName; user.Attributes[CognitoAttribute.PhoneNumber.AttributeName] = Input.PhoneNumber; user.Attributes[CognitoAttribute.FamilyName.AttributeName] = Input.FamilyName; user.Attributes[CognitoAttribute.GivenName.AttributeName] = Input.GivenName; user.Attributes["custom:AddressLine1"] = Input.AddressLine1; user.Attributes["custom:AddressLine2"] = Input.AddressLine2; user.Attributes["custom:City"] = Input.City; user.Attributes["custom:State"] = Input.State; user.Attributes["custom:Country"] = Input.Country; user.Attributes["custom:ZipCode"] = Input.ZipCode; var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } //input and update customer address information into the DB else { var id = user.Attributes[CognitoAttribute.Sub.AttributeName]; //get customer information var recentCustomer = await _context.Customer.FindAsync(id); var address = from m in _context.Address where m.Customer == recentCustomer && m.IsPrimary == true select m; if (address == null) { var newAddress = new Address { IsPrimary = true, AddressLine1 = Input.AddressLine1, AddressLine2 = Input.AddressLine2, City = Input.City, Country = Input.Country, State = Input.State, Customer = recentCustomer, ZipCode = Convert.ToInt32(Input.ZipCode) }; _context.Add(newAddress); } else { Address recentAddress = new Address(); foreach (var add in address) { recentAddress = add; } //var recentAddress =await _context.Address.FindAsync(addressId); recentAddress.AddressLine1 = Input.AddressLine1; recentAddress.AddressLine2 = Input.AddressLine2; recentAddress.City = Input.City; recentAddress.Country = Input.Country; recentAddress.ZipCode = Convert.ToInt32(Input.ZipCode); recentAddress.State = Input.State; recentAddress.Customer = recentCustomer; recentAddress.IsPrimary = true; _context.Update(recentAddress); } await _context.SaveChangesAsync(); } return(RedirectToPage()); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } if (!ModelState.IsValid) { await LoadAsync(user); return(Page()); } if (string.IsNullOrWhiteSpace(Input.AddressLine1)) { Input.AddressLine1 = "default"; } if (string.IsNullOrWhiteSpace(Input.AddressLine2)) { Input.AddressLine2 = "default"; } if (string.IsNullOrWhiteSpace(Input.City)) { Input.City = "default"; } if (string.IsNullOrWhiteSpace(Input.State)) { Input.State = "default"; } if (string.IsNullOrWhiteSpace(Input.Country)) { Input.Country = "default"; } if (string.IsNullOrWhiteSpace(Input.ZipCode)) { Input.ZipCode = "default"; } user.Attributes["custom:AddressLine1"] = Input.AddressLine1; user.Attributes["custom:AddressLine2"] = Input.AddressLine2; user.Attributes["custom:City"] = Input.City; user.Attributes["custom:State"] = Input.State; user.Attributes["custom:Country"] = Input.Country; user.Attributes["custom:ZipCode"] = Input.ZipCode; var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } //input customer information into the DB else { var id = user.Attributes[CognitoAttribute.Sub.AttributeName]; //get customer information var recentCustomer = await _context.Customer.FindAsync(id); var address = from m in _context.Address where m.Customer == recentCustomer && m.IsPrimary == true select m; Address recentAddress = new Address(); foreach (var add in address) { //addressId = add.Address_Id; recentAddress = add; } //var recentAddress =await _context.Address.FindAsync(addressId); recentAddress.AddressLine1 = Input.AddressLine1; recentAddress.AddressLine2 = Input.AddressLine2; recentAddress.City = Input.City; recentAddress.Country = Input.Country; //recentAddress.ZipCode = Convert.ToInt32(Input.ZipCode); recentAddress.State = Input.State; recentAddress.Customer = recentCustomer; recentAddress.IsPrimary = true; _context.Update(recentAddress); await _context.SaveChangesAsync(); } return(RedirectToPage()); }