public async Task <PrescriptionBarcodeResponse> Create([FromBody] PrescriptionBarcodeRequest prescriptionBarcodeRequest) { return(await _prescriptionBarcodeService.Create(prescriptionBarcodeRequest)); }
public async Task <PrescriptionBarcodeResponse> Create(PrescriptionBarcodeRequest prescriptionBarcodeRequest) { var response = new PrescriptionBarcodeResponse(); response.ItemsInfo = new List <PrescriptionBarcodeDetailesResponse>(); var prescriptionBarcodeDetailes = new PrescriptionBarcodeDetailes(); TTAC tTAC = new TTAC(_serviceProvider); var prescriptionBarcodeDetailesResponse = new PrescriptionBarcodeDetailesResponse(); try { if (string.IsNullOrEmpty(prescriptionBarcodeRequest.BarcodeUid) || string.IsNullOrEmpty(prescriptionBarcodeRequest.GenericCode) || prescriptionBarcodeRequest.Amount == 0 || prescriptionBarcodeRequest.PrescriptionId == 0) { return(response.ToIncompleteInput <PrescriptionBarcodeResponse>()); } if (string.IsNullOrEmpty(prescriptionBarcodeRequest.ReCheckCode)) { prescriptionBarcodeRequest.ReCheckCode = Guid.NewGuid().ToString(); } PrescriptionBarcode prescriptionBarcode = new PrescriptionBarcode(); prescriptionBarcodeRequest.CopyPropertiesTo(prescriptionBarcode); var result = await _prescriptionRepository.FirstOrDefault(a => a.OutPrescriptionId == prescriptionBarcodeRequest.PrescriptionId); if (result == null) { return(response.ToNotFoundPrescription <PrescriptionBarcodeResponse>()); } prescriptionBarcode.PrescriptionId = result.Id; prescriptionBarcode.PrescriptionBarcodeStatusId = (int)PrescriptionBarcodeStatusEnum.InsertRequest; await _prescriptionBarcodeRepository.Add(prescriptionBarcode); if (prescriptionBarcodeRequest.BarcodeUid.Length > 80) { prescriptionBarcode.OutErrorCode = (int)HealthESBApiResponseCode.InvalidLenghtBarcodeUcid; prescriptionBarcode.OutErrorMessage = HealthESBApiResponseMessages.InvalidLenghtBarcodeUcid; await _prescriptionBarcodeRepository.Update(prescriptionBarcode); return(response.ToInvalidLenghtBarcodeUcid <PrescriptionBarcodeResponse>()); } TTACPrescriptionBarcodeRequest tTACPrescriptionBarcodeRequest = new TTACPrescriptionBarcodeRequest(); TTACPrescriptionBarcodeResponse tTACPrescriptionBarcodeResponse = new TTACPrescriptionBarcodeResponse(); prescriptionBarcodeRequest.CopyPropertiesTo(tTACPrescriptionBarcodeRequest); tTACPrescriptionBarcodeRequest.Username = Constants.TTAC_UserName; tTACPrescriptionBarcodeRequest.Password = Constants.TTAC_Password; tTACPrescriptionBarcodeResponse = await tTAC.CallCheckSingleBarcodeApi(tTACPrescriptionBarcodeRequest); prescriptionBarcode.OutErrorCode = tTACPrescriptionBarcodeResponse.ErrorCode; prescriptionBarcode.OutErrorMessage = tTACPrescriptionBarcodeResponse.ErrorMessage; response.ErrorCode = tTACPrescriptionBarcodeResponse.ErrorCode; response.ErrorMessage = tTACPrescriptionBarcodeResponse.ErrorMessage; response.PrescriptionId = tTACPrescriptionBarcodeResponse.PrescriptionId; prescriptionBarcode.PrescriptionBarcodeStatusId = (int)PrescriptionBarcodeStatusEnum.GetResponseFromServiceProvider; prescriptionBarcode.ReCheckCode = prescriptionBarcodeRequest.ReCheckCode; await _prescriptionBarcodeRepository.Update(prescriptionBarcode); foreach (var item in tTACPrescriptionBarcodeResponse.ItemsInfo) { prescriptionBarcodeDetailes = new PrescriptionBarcodeDetailes(); item.CopyPropertiesTo(prescriptionBarcodeDetailes); item.CopyPropertiesTo(prescriptionBarcodeDetailesResponse); response.ItemsInfo.Add(prescriptionBarcodeDetailesResponse); prescriptionBarcodeDetailes.PrescriptionBarcodeId = prescriptionBarcode.Id; prescriptionBarcodeDetailes.PrescriptionBarcodeDetailesTypesId = (int)PrescriptionBarcodeDetailesTypeEnum.RegisterBarcodeItems; await _prescriptionBarcodeDetailesRepository.Add(prescriptionBarcodeDetailes); } response.HasError = false; return(response); } catch (Exception e) { _logService.LogText("PrescriptionBarcodeInternalError" + e.Message.ToString()); throw new Exception(e.Message); } }