Example #1
0
        public async Task <OutputResponse> Add(PatientHistoryDTO patientHistory)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                //insert a new patient status
                var mappedHistory = new AutoMapperHelper <PatientHistoryDTO, PatientHistory>().MapToObject(patientHistory);
                mappedHistory.DateCreated = DateTime.UtcNow;

                await _context.PatientHistory.AddAsync(mappedHistory);

                //update the patient to reflect the current status
                var patient = await _context.Patients.FirstOrDefaultAsync(x => x.PatientId.Equals(patientHistory.PatientId));

                patient.PatientStatusId = patientHistory.PatientStatusId;

                await _context.SaveChangesAsync();

                scope.Complete();
            }

            return(new OutputResponse
            {
                IsErrorOccured = false,
                Message = MessageHelper.AddNewSuccess
            });
        }
        public async Task <IActionResult> Add([FromBody] PatientHistoryDTO patientHistory)
        {
            var outputHandler = await _service.Add(patientHistory);

            if (outputHandler.IsErrorOccured)
            {
                return(BadRequest(outputHandler.Message));
            }

            return(Created("", outputHandler.Message));
        }