Пример #1
0
        public IHttpActionResult PutPerson(int id, Person person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(Ok(person));
        }
Пример #2
0
 // DELETE: api/Trips/5
 public IHttpActionResult Delete(int id)
 {
     using (var context = new LocatorEntities())
     {
         var foundTrip = context.Trips.FirstOrDefault(c => c.Id == id);
         context.Trips.Remove(foundTrip);
         context.SaveChanges();
         return(Ok(foundTrip));
     }
 }
Пример #3
0
 // POST: api/Trips
 public IHttpActionResult Post(Trip newTrip)
 {
     using (var context = new LocatorEntities())
     {
         newTrip.Created = DateTime.Now.ToString();
         context.Trips.Add(newTrip);
         context.SaveChanges();
         return(Ok(newTrip));
     }
 }
Пример #4
0
 // PUT: api/Trips/5
 public IHttpActionResult Put(int id, Trip trip)
 {
     using (var context = new LocatorEntities())
     {
         var foundTrip = context.Trips.FirstOrDefault(c => c.Id == id);
         foundTrip.Name    = trip.Name;
         foundTrip.Created = trip.Created;
         context.SaveChanges();
         return(Ok(foundTrip));
     }
 }