public async Task <ActionResult> UpdateCustomerName(UpdatedCustomerName updatedCustomerName) { // Get the customer from the database based on the customer id from the claims via the access token Customer customer = await userManager.FindByIdAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value); // If the customer is found, update his/her name if (customer != null) { customer.FirstName = updatedCustomerName.FirstName; customer.LastName = updatedCustomerName.LastName; // Update the name in the database IdentityResult result = await userManager.UpdateAsync(customer); // If succeeded, return with the new updated name if (result.Succeeded) { return(Ok(new { customer.FirstName, customer.LastName })); } } return(BadRequest()); }
public async Task <ActionResult> UpdateCustomerName(UpdatedCustomerName updatedCustomerName) { // Get the customer from the database based on the customer id from the claims via the access token Customer customer = await userManager.FindByIdAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value); // If the customer is found, update his/her name if (customer != null) { customer.FirstName = updatedCustomerName.FirstName; customer.LastName = updatedCustomerName.LastName; // Update the name in the database IdentityResult result = await userManager.UpdateAsync(customer); if (result.Succeeded) { // Send a confirmation email that the customer name has been changed if (customer.EmailPrefNameChange == true) { emailService.AddToQueue(EmailType.NameChange, "Name change confirmation", new Recipient { FirstName = customer.FirstName, LastName = customer.LastName, Email = customer.Email }, new EmailProperties { Host = GetHost() }); } return(Ok()); } } return(BadRequest()); }