public Student CreateStudent(Student student) { var sect = db.Sections.Find(student.SectionId); db.Entry(student).State = EntityState.Added; student.SectionCode = sect.SectionCode; student.SectionName = sect.SectionName; db.Students.Add(student); db.SaveChanges(); var studentId = db.Entry(student).Entity.StudentId; return(student); }
public async Task <IActionResult> PutTraining([FromRoute] int id, [FromBody] Training training) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != training.Id) { return(BadRequest()); } _context.Entry(training).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrainingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public Section UpdateSection(int sectionId, Section section) { db.Entry(section).State = EntityState.Modified; db.SaveChanges(); return(db.Sections.Find(sectionId)); }
public async Task <bool> DeleteTraining(Training training) { context.Entry <Training>(training).State = EntityState.Deleted; return(await context.SaveChangesAsync() > 0); }