public void PutClearJobDuty(int id, [FromBody] EmployeeJobDuty item) { // Ensure that an "editedItem" is in the entity body if (item == null) { return; } // Ensure that the id value in the URI matches the id value in the entity body if (id != item.Employee) { return; } // Ensure that we can use the incoming data if (ModelState.IsValid) { // Attempt to update the item m.ClearEmployeeJobDuty(item); } else { return; } }
public void ClearEmployeeJobDuty(EmployeeJobDuty item) { // Get a reference to the employee // Must bring back its collection of job duties var employee = ds.Employees .Include("JobDuties") .SingleOrDefault(e => e.Id == item.Employee); if (employee == null) { return; } // Get a reference to the job duty // Notice that we're getting it from the employee object (above) var jobDuty = employee.JobDuties .SingleOrDefault(j => j.Id == item.JobDuty); if (jobDuty == null) { return; } // Make the changes, save, and exit if (employee.JobDuties.Remove(jobDuty)) { ds.SaveChanges(); } }
public void SetEmployeeJobDuty(EmployeeJobDuty item) { // Get a reference to the employee // Must bring back its collection of job duties var employee = ds.Employees .Include("JobDuties") .SingleOrDefault(e => e.Id == item.Employee); if (employee == null) { return; } // Get a reference to the job duty var jobDuty = ds.JobDuties.Find(item.JobDuty); if (jobDuty == null) { return; } // Make the changes, save, and exit employee.JobDuties.Add(jobDuty); ds.SaveChanges(); }