Exemplo n.º 1
0
 public virtual void Delete(T entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
     context.SaveChanges();
 }
        public IHttpActionResult PutSchedule(int id, Schedule schedule)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != schedule.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
 public virtual void Update(T entityToUpdate)
 {
     using (var context = new ScheduleDB())
     {
         context.Entry(entityToUpdate).State = EntityState.Modified;
         context.SaveChanges(); //Must be in using block
     }
 }
Exemplo n.º 4
0
 public virtual void Delete(T entityToDelete)
 {
     using (var context = new ScheduleDB())
     {
         context.Entry(entityToDelete).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }