I am creating a junction table between Identity User and a Game table. This table is called UserGame and has two foreign keys (UserID, GameID) and one additional field to store the score.
public class UserGame
{
[Key]
public string ApplicationUserID { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
public int GameID { get; set; }
public virtual Game Game { get; set; }
public int Score { get; set; }
}
My confusion lies with creating a new UserGame record. How would I go about doing this and is my approach correct?
Update (This worked):
[HttpPost]
public ActionResult SubmitScore(int gameID, int score)
{
var playerRecord = new UserGame();
playerRecord.ApplicationUserID = User.Identity.GetUserId();
playerRecord.GameID = gameID;
playerRecord.Score = score;
return Json(new { success = true });
}