public async Task <IActionResult> PutDosage(long id, Dosage dosage) { if (id != dosage.Id) { return(BadRequest()); } var existingDosage = await _context.Dosages.FindAsync(id); if (existingDosage == null) { return(NotFound()); } //trying to restore a patient if (existingDosage.Deleted && !dosage.Deleted) { return(BadRequest("Cannot restore a dosage")); } if (!_relationshipService.CheckPatientExists(dosage.PatientId)) { return(BadRequest("Patient does not exist or is deleted")); } if (!_relationshipService.CheckDrugExists(dosage.DrugId)) { return(BadRequest("Drug does not exist or is deleted")); } _context.Entry(existingDosage).State = EntityState.Detached; _context.Entry(dosage).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }