public IHttpActionResult PutLandHistorie(int id, LandHistorie landHistorie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != landHistorie.ID) { return(BadRequest()); } db.Entry(landHistorie).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LandHistorieExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostLandHistorie(LandHistorie landHistorie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.LandHistories.Add(landHistorie); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = landHistorie.ID }, landHistorie)); }
public IHttpActionResult DeleteLandHistorie(int id) { LandHistorie landHistorie = db.LandHistories.Find(id); if (landHistorie == null) { return(NotFound()); } db.LandHistories.Remove(landHistorie); db.SaveChanges(); return(Ok(landHistorie)); }
public IHttpActionResult GetLandHistorie(int managerId, string landIso) { // FirstOrDefault zou SingleOrDefault mogen zijn, maar graag pas na toevoegen unique index op Land en Manager in LandHistorie LandHistorie landHistorie = db.LandHistories.Include(l => l.Land) .FirstOrDefault(land => land.Land.IsoCode == landIso && land.Manager.ID == managerId); if (landHistorie == null) { Land land = db.Landen.SingleOrDefault(l => l.IsoCode == landIso); if (land != null) { return(Ok(new LandHistorieJson { LandNaam = land.Naam, LandIso = land.IsoCode, CompetitieGewonnen = 0, BekerGewonnen = 0, DoelstellingBehaald = 0 })); } else { return(NotFound()); } } else { return(Ok(new LandHistorieJson { LandNaam = landHistorie.Land.Naam, LandIso = landHistorie.Land.IsoCode, CompetitieGewonnen = landHistorie.CompetitieGewonnen, BekerGewonnen = landHistorie.BekerGewonnen, DoelstellingBehaald = landHistorie.DoelstellingBehaald })); } }