Beispiel #1
0
        public async Task <IActionResult> EditRecord(RecordForAddEditDetails record)
        {
            var patientToEdit = await _patientRepo.GetPatient(record.PatientId, true);

            var patientRecord = patientToEdit.Records.FirstOrDefault(rec => rec.Id == record.Id);

            if (patientRecord == null)
            {
                return(BadRequest("This record is not for this patient"));
            }

            if (!await _repo.RecordExists(record.Id))
            {
                return(BadRequest("Record does not exist"));
            }
            else if (patientToEdit == null)
            {
                return(BadRequest("Patient does not exist"));
            }
            else
            {
                var newRecord = _repo.EditRecord(_mapper.Map <Record>(record)).Result;


                return(Ok(newRecord));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> AddRecord(RecordForAddEditDetails record)
        {
            if (record.Id > 0)
            {
                return(BadRequest("Record already exits"));
            }
            else if (await _patientRepo.GetPatient(record.PatientId, false) == null)
            {
                return(BadRequest("Patient does not exist"));
            }
            else
            {
                var newRecord = _repo.AddRecord(_mapper.Map <Record>(record)).Result;

                var patientToReturn = _mapper.Map <RecordForAddEditDetails>(newRecord);

                return(Ok(patientToReturn));
            }
        }