public async Task <IActionResult> ClassTeacherAssignment(ClassModel model) { var user = await userManager.GetUserAsync(User); ClassRepository repo = new ClassRepository(configModel.ConnectionString); VolunteerRepository vRepo = new VolunteerRepository(configModel.ConnectionString); // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { return(Utilities.ErrorJson("Not authorized")); } // Make sure the provided class and volunteer ids are valid if (model.Id == 0 || repo.GetClass(model.Id) == null) { return(Utilities.ErrorJson("Must include a valid class ID")); } if (model.TeacherId == 0 || vRepo.GetVolunteer(model.TeacherId) == null) { return(Utilities.ErrorJson("Must include a valid volunteer id as TeacherId")); } // Update in the database try { repo.AssignTeacher(model.Id, model.TeacherId); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(Utilities.NoErrorJson()); }