public IHttpActionResult PutStudio(int id, Studio studio) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != studio.Id) { return(BadRequest()); } db.Entry(studio).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudioExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutGameDeveloper(int id, GameDeveloper gameDeveloper) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != gameDeveloper.GameId) { return(BadRequest()); } db.Entry(gameDeveloper).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GameDeveloperExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "Id,Name,ReleaseDate,CategoryId,RatingId,PublisherId,PlatformId")] Game game) { if (ModelState.IsValid) { db.Games.Add(game); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(game)); }
public void AddGame(GAME game) { using (var gameContext = new GamesDBEntities()) { gameContext.GAMES.Add(game); gameContext.SaveChanges(); } }
// POST api/Games public HttpResponseMessage Post([FromBody] tblGame game) { using (GamesDBEntities entities = new GamesDBEntities()) { entities.tblGames.Add(game); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, new Uri(Request.RequestUri + "/" + game.GameID.ToString()))); } }
// DELETE api/Games/5 public HttpResponseMessage Delete(int id) { using (GamesDBEntities entities = new GamesDBEntities()) { tblGame game = entities.tblGames.FirstOrDefault(g => g.GameID == id); if (game != null) { entities.tblGames.Remove(game); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format($"Game with ID {id} was Deleted"))); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"Game with ID {id} was not Found"))); } } }
public void EditGame(int gameId) { using (var gameContext = new GamesDBEntities()) { var query = from game in GDBEntities.GAMES where game.Id == gameId select game; foreach (GAME game in query) { game.Complete = true; game.DateOfCompletion = DateTime.Today; } gameContext.SaveChanges(); } }
// PUT api/Games/5 public HttpResponseMessage Put(int id, [FromBody] tblGame game) { using (GamesDBEntities entities = new GamesDBEntities()) { tblGame game_To_Update = entities.tblGames.FirstOrDefault(g => g.GameID == id); // LINQ - Check if Found ID First or Default if (game_To_Update != null) { game_To_Update.Game_Name = game.Game_Name; game_To_Update.Player1 = game.Player1; game_To_Update.Player2 = game.Player2; game_To_Update.Who_won = game.Who_won; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format($"game with ID {id} Updated"))); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"game wite ID {id} not Found"))); } } }
public void Create(T item) { Context.Set <T>().Add(item); Context.SaveChanges(); }