public async Task <IActionResult> PutStaffProgram([FromRoute] int id, [FromBody] StaffProgram staffProgram) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != staffProgram.StaffProgramId) { return(BadRequest()); } _context.Entry(staffProgram).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StaffProgramExists(id)) { return(NotFound()); } else { throw; } } staffProgram = _context.StaffPrograms.Include(e => e.College).Include(e => e.Department).FirstOrDefault(e => e.CollegeId == staffProgram.CollegeId && e.DepartmentId == staffProgram.DepartmentId); return(Ok(staffProgram)); }
public async Task <IActionResult> PostStaffProgram([FromBody] StaffProgram staffProgram) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.StaffPrograms.Add(staffProgram); await _context.SaveChangesAsync(); staffProgram = _context.StaffPrograms.Include(e => e.College).Include(e => e.Department).FirstOrDefault(e => e.CollegeId == staffProgram.CollegeId && e.DepartmentId == staffProgram.DepartmentId); return(CreatedAtAction("GetStaffProgram", new { id = staffProgram.StaffProgramId }, staffProgram)); }