public async Task <IActionResult> Post([FromBody] Patient patient)
 {
     if (ModelState.IsValid)
     {
         try
         {
             await _patientsDataAccess.SavePatientAsync(patient);
         }
         catch (JsonException JEX)
         {
             return(BadRequest(JEX.Message));
         }
         catch (DataAccessException DAX)
         {
             return(StatusCode(500, DAX.Message));
         }
         catch (Exception EX)
         {
             return(StatusCode(500, EX.Message));
         }
         return(Created("", patient));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Пример #2
0
        public async Task SavePrescriptionAsync(Prescription prescription)
        {
            var _prescriptionJson = (string)null;

            try
            {
                _prescriptionJson = JsonConvert.SerializeObject(prescription);
            }
            catch (JsonException jEx)
            {
                throw jEx;
            }
            Document document = null;
            var      patient  = prescription.PatientInfo;

            try
            {
                await _patientsDataAccess.SavePatientAsync(patient);
            }
            catch (DataAccessException DAX)
            {
                throw DAX;
            }
            try
            {
                var dynamoConfig = new AmazonDynamoDBConfig();
                dynamoConfig.RegionEndpoint = Amazon.RegionEndpoint.USWest2;
                using (var dynamoClient = new AmazonDynamoDBClient(dynamoConfig))
                {
                    var table = Table.LoadTable(dynamoClient, "Prescriptions");
                    var item  = Document.FromJson(_prescriptionJson);
                    document = await table.PutItemAsync(item, default(CancellationToken));
                }
            }
            catch (AmazonDynamoDBException dEx)
            {
                _log.LogError("Amazon DynamoDB Exception: " + dEx.Message);
                throw new DataAccessException("An Error Occured While Saving Prescription To Database");
            }
            catch (AmazonServiceException sEx)
            {
                _log.LogError("Amazon Service Exception: " + sEx.Message);
                throw new DataAccessException("An Error Occured While Saving Prescription To Database");
            }
            catch (AmazonClientException cEx)
            {
                _log.LogError("Amazon Client Exception: " + cEx.Message);
                throw new DataAccessException("An Error Occured While Saving Prescription To Database");
            }
            catch (Exception uEx)
            {
                _log.LogError("Unhandled Exception:  " + uEx.Message);
                throw new DataAccessException("An Unknown Error Occured");
            }
            return;
        }