コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
 public void AddGame(GAME game)
 {
     using (var gameContext = new GamesDBEntities())
     {
         gameContext.GAMES.Add(game);
         gameContext.SaveChanges();
     }
 }
コード例 #5
0
 // 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())));
     }
 }
コード例 #6
0
 // 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")));
         }
     }
 }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
 // 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")));
         }
     }
 }
コード例 #9
0
 public void Create(T item)
 {
     Context.Set <T>().Add(item);
     Context.SaveChanges();
 }