public async Task <ActionResult <SavedStudentInternship> > GetSavedStudentInternship(int studentId, int internshipId) { List <SavedStudentInternship> studentInternships = await _context.SavedStudentInternships.ToListAsync(); SavedStudentInternship result = null; foreach (SavedStudentInternship studentInternship in studentInternships) { if (studentInternship.InternshipId == internshipId && studentInternship.StudentId == studentId) { result = studentInternship; } } if (result == null) { return(NotFound()); } return(result); }
public async Task <IActionResult> PutSavedStudentInternship(int studentId, int internshipId, SavedStudentInternship studentInternship) { if (studentId != studentInternship.StudentId && internshipId != studentInternship.InternshipId) { return(BadRequest()); } _context.Entry(studentInternship).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SavedStudentInternshipExists(studentId, internshipId)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <SavedStudentInternship> > PostSavedStudentInternship(SavedStudentInternship studentInternship) { _context.SavedStudentInternships.Add(studentInternship); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (SavedStudentInternshipExists(studentInternship.StudentId, studentInternship.InternshipId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetSavedStudentInternship", new { id = studentInternship.StudentId }, studentInternship)); }