public long createCaseTrans(string itemId, HMServiceStatus serviceStatus, string caseId, long appointmentRecId, decimal quantity, string orderId, string unit = "", HMUrgency urgency = HMUrgency.None, string notesToPharmacy = "", string patientInstructionsEng = "", string patientInstructionsArabic = "", long specialityRecId = 0, long treatmentLocationRecId = 0)
        {
            long caseTransRecId = 0;

            //HMCaseServiceClient client = null;

            //try
            //{
            //    client = new HMCaseServiceClient();

            //    CallContext callContext = new CallContext { Company = AppSettings.GetByKey("axCompany") };
            //    client.ClientCredentials.Windows.ClientCredential = new NetworkCredential { Domain = AppSettings.GetByKey("axDomain"), UserName = AppSettings.GetByKey("axUserName"), Password = AppSettings.GetByKey("axPassword") };

            //    caseTransRecId = client.createCaseTrans(callContext, itemId, serviceStatus, new Guid(caseId), appointmentRecId, quantity, new Guid(orderId), unit, urgency, notesToPharmacy, patientInstructionsEng, patientInstructionsArabic, specialityRecId, prnIndication, treatmentLocationRecId);
            //}
            //catch (System.ServiceModel.FaultException<AifFault> aiffaultException)
            //{
            //    throw ValidationException.create(aiffaultException.Message, aiffaultException.HelpLink, aiffaultException.Source);
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            //finally
            //{
            //    client.Close();
            //}
            //return caseTransRecId;

            try
            {
                var endpointAddress = SoapHelper.GetEndPointAddress();
                var binding         = SoapHelper.GetBinding();

                var client  = new HMCaseServiceClient(binding, endpointAddress);
                var channel = client.InnerChannel;
                using (OperationContextScope operationContextScope = new OperationContextScope(channel))
                {
                    SoapHelper.channelHelper();
                    createCaseTransResponse obj = ((HMCaseService)channel).createCaseTrans(new createCaseTrans()
                    {
                        _itemid = itemId, _serviceStatus = serviceStatus, _caseGuid = new Guid(caseId), _apptRecId = appointmentRecId, _quantity = quantity, _orderId = string.IsNullOrEmpty(orderId) ? Guid.Empty : new Guid(orderId), _unit = unit, _urgency = urgency, notesToPharmacy = notesToPharmacy, patientInstructionsEng = patientInstructionsEng, patientInstructionsArabic = patientInstructionsArabic, _specialityRecId = specialityRecId, _treatmentLocation = treatmentLocationRecId
                    });
                    if (obj.result > 0)
                    {
                        caseTransRecId = obj.result;
                    }
                    else
                    {
                        throw new ValidationException(CommonRepository.getErrorMessage(obj.Infolog));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(caseTransRecId);
        }
        public bool updateCaseTransStatus(long caseTransRecId, HMServiceStatus serviceStatus, bool createCharge, long appointmentRecId, string batchId, string caseId, long resourceRecId = 0)
        {
            bool ret = false;

            //HMCaseServiceClient client = null;

            //try
            //{
            //    client = new HMCaseServiceClient();

            //    CallContext callContext = new CallContext { Company = AppSettings.GetByKey("axCompany") };
            //    client.ClientCredentials.Windows.ClientCredential = new NetworkCredential { Domain = AppSettings.GetByKey("axDomain"), UserName = AppSettings.GetByKey("axUserName"), Password = AppSettings.GetByKey("axPassword") };
            //    if (!string.IsNullOrEmpty(caseId))
            //    {
            //        ret = client.updateCaseTransStatus(callContext, caseTransRecId, serviceStatus, createCharge, appointmentRecId, batchId, new Guid(caseId), resourceRecId);
            //    }
            //    else
            //    {
            //        ret = client.updateCaseTransStatus(callContext, caseTransRecId, serviceStatus, createCharge, appointmentRecId, batchId, Guid.Empty, resourceRecId);
            //    }
            //}
            //catch (System.ServiceModel.FaultException<AifFault> aiffaultException)
            //{
            //    throw ValidationException.create(aiffaultException.Message, aiffaultException.HelpLink, aiffaultException.Source);
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            //finally
            //{
            //    client.Close();
            //}

            //return ret;

            try
            {
                updateCaseTransStatusResponse obj;

                var endpointAddress = SoapHelper.GetEndPointAddress();
                var binding         = SoapHelper.GetBinding();

                var client  = new HMCaseServiceClient(binding, endpointAddress);
                var channel = client.InnerChannel;
                using (OperationContextScope operationContextScope = new OperationContextScope(channel))
                {
                    SoapHelper.channelHelper();
                    if (!string.IsNullOrEmpty(caseId))
                    {
                        obj = ((HMCaseService)channel).updateCaseTransStatus(new updateCaseTransStatus()
                        {
                            _caseTransRecId = caseTransRecId, _serviceStatus = serviceStatus, createCharge = createCharge, _apptRecId = appointmentRecId, _batchId = batchId, _caseId = new Guid(caseId), _resourceRecId = resourceRecId
                        });
                    }
                    else
                    {
                        obj = ((HMCaseService)channel).updateCaseTransStatus(new updateCaseTransStatus()
                        {
                            _caseTransRecId = caseTransRecId, _serviceStatus = serviceStatus, createCharge = createCharge, _apptRecId = appointmentRecId, _batchId = batchId, _caseId = Guid.Empty, _resourceRecId = resourceRecId
                        });
                    }

                    if (obj.result)
                    {
                        ret = obj.result;
                    }
                    else
                    {
                        throw new ValidationException(CommonRepository.getErrorMessage(obj.Infolog));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ret);
        }