public IHttpActionResult PutRaceResultSet(int id, RaceResultSet raceResultSet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != raceResultSet.Id)
            {
                return(BadRequest());
            }

            db.Entry(raceResultSet).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RaceResultSetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        // POST api/driver
        public HttpResponseMessage Post(Driver value)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (KartingEntities entities = new KartingEntities())
                    {
                        entities.Driver.Add(value);
                        entities.SaveChanges();

                        var response = Request.CreateResponse(HttpStatusCode.OK);
                        response.Content = new StringContent(value.Id.ToString(), Encoding.UTF8, "application/json");
                        return(response);
                        //return Request.CreateResponse(HttpStatusCode.OK);
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, "invalid New Value"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutRace(int id, Race race)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != race.Id)
            {
                return(BadRequest());
            }

            db.Entry(race).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Console.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RaceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public IHttpActionResult PostRace(Race race)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (KartingEntities entities = new KartingEntities())
                    {
                        entities.Race.Add(race);
                        entities.SaveChanges();

                        var response = Request.CreateResponse(HttpStatusCode.OK);
                        response.Content = new StringContent(race.Id.ToString(), Encoding.UTF8, "application/json");
                        return(CreatedAtRoute("DefaultApi", new { id = race.Id }, race));
                        //return Request.CreateResponse(HttpStatusCode.OK);
                    }
                }
                else
                {
                    return(BadRequest(ModelState));
                    //return Request.CreateResponse(HttpStatusCode.InternalServerError, "invalid New Value");
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            //db.Race.Add(race);

            //try
            //{
            //    db.SaveChanges();
            //}
            //catch (DbUpdateException)
            //{
            //    if (RaceExists(race.ID))
            //    {
            //        return Conflict();
            //    }
            //    else
            //    {
            //        throw;
            //    }
            //}

            //return CreatedAtRoute("DefaultApi", new { id = race.ID }, race);
        }
Ejemplo n.º 5
0
 // DELETE api/driver/5
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (KartingEntities entities = new KartingEntities())
         {
             Driver drv = entities.Driver.SingleOrDefault <Driver>(b => b.Id == id);
             // delete record
             entities.Driver.Remove(drv);
             // flush to disk
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK));;
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Ejemplo n.º 6
0
 // PUT api/driver/5
 public HttpResponseMessage Put(int id, Driver value)
 {
     try
     {
         using (KartingEntities entities = new KartingEntities())
         {
             Driver drv = entities.Driver.SingleOrDefault <Driver>(b => b.Id == id);
             // update all the fields
             drv.FirstName = value.FirstName;
             drv.LastName  = value.LastName;
             drv.BirthDate = value.BirthDate;
             // flush to disk
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }