1) I'm trying to allow the user to change their UserName (email) etc. in a ASP.MVC/Identity app
Asp.net identity has a class called UserManager. This class exposes many function including Update which will automatically update the user's data in UserStore.
Using FluentValidation I'd like to check that no other user is using the new email.
If you use Create function of UserManager class for creating new user then this function automatically take care about the duplicate username entry validation. In case of invalid Or duplicate entry, Create function return well descriptive error messages which you can show to your users.
2) What is the best way to store such changes. Right now I'm using AutoMapper:
I don't understand the code you mentioned in your 2 point. The only purpose of Automapper is to mapped one object to another. In that code
- you fetch the user from the database
- create a mapping configuration (You should do this thing only once, no need to create mapping configuration again and again. So the best place for such type of things is global.asax file)
- Then you mapped your viewmodel object to domain model object.
But this thing never put any change in the current context, so context.SaveChanges() have no effect.
And i think this is the reason why your User.Identity.GetUserName() is not updated.