示例#1
0
        public async Task <ActionResult <bool> > DeleteDosagePatientId(long id)
        {
            var dosage = await _dosageContext.Dosages.Where(dose => dose.PatientId == id && !dose.Deleted).ToListAsync();

            foreach (var dose in dosage)
            {
                dose.Deleted = true;

                _dosageContext.Entry(dose).State = EntityState.Modified;
            }

            await _dosageContext.SaveChangesAsync();

            return(true);
        }
示例#2
0
        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());
        }