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)); }
public virtual void Update(T entityToUpdate) { using (var context = new ScheduleDB()) { context.Entry(entityToUpdate).State = EntityState.Modified; context.SaveChanges(); //Must be in using block } }
public virtual void Delete(T entityToDelete) { using (var context = new ScheduleDB()) { context.Entry(entityToDelete).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } }
public IActionResult CreateDiscipline(discipline item) { using (var db = new ScheduleDB()) { db.discipline.Add(item); db.SaveChanges(); } return(Redirect("/Discipline")); }
public virtual void Insert(T entity) { dbSet.Add(entity); context.SaveChanges(); }