public async Task<IHttpActionResult> PutNation(int id, Nation nation) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != nation.NationID) { return BadRequest(); } Group currentGroup = (nation.GroupID == nation.Group.GroupID) ? nation.Group : db.Groups.Find(nation.GroupID); nation.Group = currentGroup; db.Entry(nation).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NationExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostNation(Nation nation) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var isExistNation=db.Nations.Where(n => n.Name == nation.Name).FirstOrDefault(); if (isExistNation == null) { db.Nations.Add(nation); await db.SaveChangesAsync(); } else { } return CreatedAtRoute("DefaultApi", new { id = nation.NationID }, nation); }