Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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
                }));
            }
        }