예제 #1
0
        // 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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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;
 }