// PUT api/Battle/5 public IHttpActionResult PutBattle(int id, Battle battle) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != battle.BattleId) { return BadRequest(); } db.Entry(battle).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BattleExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostBattle(Battle battle) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var serverBattle = db.Battles.Where(x => x.ArenaUniqueId == battle.ArenaUniqueId).SingleOrDefault(); if (serverBattle != null) { battle = serverBattle; } else { db.Battles.Add(battle); db.SaveChanges(); } return CreatedAtRoute("DefaultApi", new { id = battle.BattleId }, battle); }
private Battle PostBattle(Battle battle) { var serverBattle = db.Battles.Where(x => x.ArenaUniqueId == battle.ArenaUniqueId).SingleOrDefault(); if (serverBattle == null) { db.Battles.Add(battle); db.SaveChanges(); serverBattle = battle; } return serverBattle; }