/// <summary> /// Updates a single video game /// </summary> /// <param name="g"></param> /// <param name="context"></param> /// <returns></returns> public static async Task <VideoGame> UpdateGame(VideoGame g, GameContext context) { context.Update(g); await context.SaveChangesAsync(); return(g); }
/// <summary> /// Adds a member to the database. Returns the member with their MemberId populated. /// </summary> /// <param name="context">The database context to be used</param> /// <param name="m">The new Member to be added</param> /// <returns></returns> public async static Task <Member> Add(GameContext context, Member m) { context.Members.Add(m); await context.SaveChangesAsync(); return(m); }
// had to add using /// <summary> /// Adds a VideoGame to the data store and sets the ID value /// </summary> /// <param name="g">The game to add</param> /// <param name="context">The database context to use</param> /// <returns>VideoGame with ID populated</returns> public static async Task <VideoGame> Add(VideoGame g, GameContext context) { await context.AddAsync(g); await context.SaveChangesAsync(); return(g); }
public static async Task <VideoGame> UpdateGame(VideoGame g, GameContext context) { //Starts tracking to get to update context.Update(g); //Await because this is touching the DB for the update await context.SaveChangesAsync(); return(g); }
/// <summary> /// Adds a video game to the data store. Sets the ID value /// </summary> /// <param name="game">The game to add</param> /// <param name="context">The context used</param> public static async Task <VideoGame> AddAsync(VideoGame game, GameContext context) { // NEEDS THE CONTEXT PASSED IN AS WELL // must add await keyword await context.AddAsync(game); await context.SaveChangesAsync(); return(game); }
/// <summary> /// Deletes a video game by the games id /// </summary> /// <param name="id">The video game's id</param> /// <param name="context">The database context</param> /// <returns></returns> public static async Task DeleteById(int id, GameContext context) { VideoGame g = new VideoGame() { Id = id }; context.Entry(g).State = EntityState.Deleted; await context.SaveChangesAsync(); }
public static async Task DeleteById(int id, GameContext context) { // Create video game object, with the id of the game we want to remove from the database VideoGame g = new VideoGame() { Id = id }; context.Entry(g).State = EntityState.Deleted; await context.SaveChangesAsync(); }
public static async Task DeleteById(int id, GameContext context) { //Create video game object, with the id of the game we want to remove from the database VideoGame g = new VideoGame() { Id = id }; context.Entry(g).State = EntityState.Deleted; //This tells the Entity Framework that we have the video game object, but we are removing it from the database await context.SaveChangesAsync(); }
public static async Task DeleteById(int id, GameContext context) { // create video game with the id we want to remove VideoGame g = new VideoGame() { Id = id }; // tell context we want to remove this game from the database, then save context.Entry(g).State = EntityState.Deleted; await context.SaveChangesAsync(); }