Beispiel #1
0
        public async Task <IHttpActionResult> PutGameIncident(int id, GameIncident gameIncident)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != gameIncident.Id)
            {
                return(BadRequest());
            }

            db.Entry(gameIncident).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameIncidentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PostGameIncident(GameIncident gameIncident)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.GameIncidents.Add(gameIncident);
            await db.SaveChangesAsync();

            // New code:
            // Load author name
            db.Entry(gameIncident).Reference(x => x.GamePlayer).Load();

            var dto = new GameIncidentDTO()
            {
                Id                  = gameIncident.Id,
                IncidentType        = gameIncident.IncidentType,
                IncidentTime        = gameIncident.IncidentTime,
                GamePlayerFirstName = gameIncident.GamePlayer.FirstName,
                GamePlayerLastName  = gameIncident.GamePlayer.LastName,
                TeamName            = gameIncident.GamePlayer.Team.Name
            };

            return(CreatedAtRoute("DefaultApi", new { id = gameIncident.Id }, gameIncident));
        }
Beispiel #3
0
        public async Task <IHttpActionResult> DeleteGameIncident(int id)
        {
            GameIncident gameIncident = await db.GameIncidents.FindAsync(id);

            if (gameIncident == null)
            {
                return(NotFound());
            }

            db.GameIncidents.Remove(gameIncident);
            await db.SaveChangesAsync();

            return(Ok(gameIncident));
        }