I'm trying to update 2 records:
- a user record (bool and custom Object)
- a custom object (named MoviesDB)
I'm using UserManager like so:
private UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
and the code is:
using (ApplicationDbContext dbCtx = new ApplicationDbContext())
{
// user to update
var user = UserManager.Users
.ToList()
.First(u => u.Id == User.Identity.GetUserId());
// movie to update
var movie = db.MoviesDBs.SingleOrDefault(m => m.ID == id);
// this is the only property i want to update
movie.isRented = true;
db.SaveChanges();
// user update
user.isRenting = true;
user.MovieRented = movie;
// this line creates a new movie record for some reason
UserManager.Update(user);
}
as you can see in my comments, the last line of code:
UserManager.Update(user);
is updating the user record like expected but also creates a new record of Movie in the database which I don't want.
all I want is to update an existing movie record and existing user record.