public async Task <ActionResult <IEnumerable <Student> > > DeletDormitoryFromStudent(int dormitoryId, int studentId) { Dormitory dormitory = await context.Dormitories.FindAsync(dormitoryId); if (dormitory == null) { return(BadRequest("Dormitory does not exist")); } Student student = await context.Students.FindAsync(studentId); if (student == null) { return(BadRequest("Dormitory does not exist")); } if (student.DormitoryId != dormitoryId) { return(BadRequest("This student does not live here.")); } student.DormitoryId = null; context.Entry(student).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutDormitory(int id, Dormitory dormitory) { if (id != dormitory.Id) { return(BadRequest()); } _context.Entry(dormitory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DormitoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }