public IHttpActionResult GetValueById(string id) { Section section; using (var ctx = new Models.TeachMeBackendContext()) { section = ctx.Sections.Find(id); } if (section == null) { return(NotFound()); } return(Ok(section)); }
public IHttpActionResult Delete(string id) { using (var dbContext = new Models.TeachMeBackendContext()) { //var section = dbContext.Sections.Find(id); var section = dbContext.Sections.Include(c => c.Lessons).FirstOrDefault(c => c.Id == id); if (section == null) { return(NotFound()); } dbContext.Lessons.RemoveRange(section.Lessons); dbContext.Sections.Remove(section); dbContext.SaveChanges(); } return(Ok()); }