コード例 #1
0
        /// <summary>
        /// To fetch booking, contact
        /// </summary>
        /// <param name="bookingNumber"></param>
        /// <param name="sourceMarket"></param>
        /// <param name="tourOperator"></param>
        /// <param name="brand"></param>
        /// <param name="lastName"></param>
        /// <param name="email"></param>
        /// <param name="surveyResponse"></param>
        private void FetchBookingContact(string bookingNumber, string sourceMarket, string tourOperator, string brand, string lastName, Entity surveyResponse)
        {
            trace.Trace("Processing FetchBookingContact - start");
            var contactCondition      = PrepareContactCondition(lastName);
            var sourceMarketCondition = PrepareSourceMarketCondition(sourceMarket);
            var tourOperatorCondition = PrepareTourOperatorCondition(tourOperator);
            var brandCondition        = PrepareBrandCondition(brand);
            var query = $@"<fetch output-format='xml-platform' distinct='false' version='1.0' mapping='logical'>
                            <entity name='tc_customerbookingrole'>
                                <link-entity name='tc_booking' alias='booking' from='tc_bookingid' to='tc_bookingid'>
                                  <attribute name='tc_bookingid' />                                               
                                    <filter type = 'and'>
                                      <condition attribute='tc_name' operator='eq' value='{bookingNumber}' />
                                    </filter>
                            {sourceMarketCondition}
                            {tourOperatorCondition}
                            {brandCondition}
                                </link-entity>                           
                            {contactCondition}
                            </entity>
                           </fetch>";

            var entColBookingContact = CommonXrm.RetrieveMultipleRecordsFetchXml(query, payloadSurvey.CrmService);

            MapBooking(surveyResponse, entColBookingContact);
            MapContact(surveyResponse, entColBookingContact);
            trace.Trace("Processing FetchBookingContact - end");
        }
コード例 #2
0
        public bool IsBookingOnTour(Guid bookingId)
        {
            var bookingFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>
                  <entity name='tc_booking'>
                    <attribute name='tc_bookingid' />
                    <filter type='and'>
                      <condition attribute='tc_bookingid' operator='eq'  uitype='tc_booking' value='{bookingId}' />
                      <condition attribute='tc_sourcesystem' operator='eq' value='{SourceSystem.OnTour}' />
                      <condition attribute='statecode' operator='eq' value='0' />
                    </filter>
                  </entity>
                </fetch>";


            var bookingCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(bookingFetch, crmService);

            if (bookingCollection != null && bookingCollection.Entities.Count == 1)
            {
                return(true);
            }
            else if (bookingCollection != null && bookingCollection.Entities.Count > 1)
            {
                payloadBooking.Response.ResponseCode = ResponseDetails.ReturnErrorCode400;
            }
            payloadBooking.Response.ResponseMessage = "More than one matching booking record found in MSD with BookingId and SourceSystem OnTour";
            return(false);
        }
コード例 #3
0
        /// <summary>
        /// To map Gateway information to survey record
        /// </summary>
        /// <param name="surveyResponse"></param>
        /// <param name="response"></param>
        private void MapGateway(Entity surveyResponse, Response response)
        {
            trace.Trace("Processing MapGateway - start");
            surveyResponse[Attributes.SurveyResponse.GatewayId] = null;
            if (response.Answers == null || response.Answers.Count == 0)
            {
                return;
            }
            var gatewayCode = AnswerHelper.GetTcdisDestinationAirport(response.Answers, payloadSurvey.Trace);

            if (string.IsNullOrWhiteSpace(gatewayCode))
            {
                return;
            }
            var query = $@"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>
                           <entity name='tc_gateway'>
                           <attribute name='tc_gatewayid'/>
                            <filter type='and'>
                             <condition attribute='tc_iata' value='{gatewayCode}' operator='eq'/>
                            </filter>
                           </entity>
                           </fetch>";

            var entColGateways = CommonXrm.RetrieveMultipleRecordsFetchXml(query, payloadSurvey.CrmService);

            if (entColGateways == null || entColGateways.Entities.Count == 0)
            {
                return;
            }
            surveyResponse.Attributes[Attributes.SurveyResponse.GatewayId] = new EntityReference(EntityName.Gateway, entColGateways.Entities[0].Id);
            trace.Trace("Processing MapGateway - end");
        }
コード例 #4
0
        public bool IsMatchedBooking(int dealSequenceNumber, string consultationReference)
        {
            payloadBooking.Response = new BookingResponse();

            var bookingFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>
                      <entity name='tc_booking'>
                        <attribute name='tc_bookingid' />
                        <attribute name='tc_name' />
                        <order attribute='tc_name' descending='false' />
                        <filter type='and'>
                          <condition attribute='tc_dealsequencenumber' operator='eq' value='{dealSequenceNumber}' />
                          <condition attribute='statecode' operator='eq' value='0' />
                        </filter>
                        <link-entity name='opportunity' from='opportunityid' to='tc_consultationreferenceid' alias='ad'>
                          <filter type='and'>
                            <condition attribute='opportunityid' operator='eq' value='{consultationReference}' />
                          </filter>
                        </link-entity>
                      </entity>
                    </fetch>";

            var bookingCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(bookingFetch, crmService);

            if (bookingCollection != null && bookingCollection.Entities.Count == 1)
            {
                bookingId = bookingCollection.Entities[0].Id;
                return(true);
            }
            else if (bookingCollection != null && bookingCollection.Entities.Count > 1)
            {
                payloadBooking.Response.ResponseCode = ResponseDetails.ReturnErrorCode400;
            }
            payloadBooking.Response.ResponseMessage = "More than one matching booking record found in MSD with DealSequenceNumber and ConsultationReference";
            return(false);
        }
コード例 #5
0
        public bool IsMatchedBooking(string bookingNumber, string bookingSystem)
        {
            var bookingFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>
                  <entity name='tc_booking'>
                    <attribute name='tc_bookingid' />
                    <attribute name='tc_name' />
                    <order attribute='tc_name' descending='false' />
                    <filter type='and'>
                      <condition attribute='tc_name' operator='eq' value='{bookingNumber}' />
                      <condition attribute='tc_sourcesystem' operator='eq' value='{bookingSystem}' />
                      <condition attribute='statecode' operator='eq' value='0' />
                    </filter>
                  </entity>
                </fetch>";

            var bookingCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(bookingFetch, crmService);

            if (bookingCollection != null && bookingCollection.Entities.Count == 1)
            {
                bookingId = bookingCollection.Entities[0].Id;
                return(true);
            }
            else if (bookingCollection != null && bookingCollection.Entities.Count > 1)
            {
                throw new InvalidPluginExecutionException("More than one matching booking record found in MSD with BookingNumber and SourceSystem");
            }
            return(false);
        }
コード例 #6
0
        public void ResolveConsultationReferenceId(string consultationReference)
        {
            var bookingFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>			
                                    <entity name='opportunity'>			
                                    <attribute name='opportunityid' />			
                                    <filter type='and'>			
                                    <condition attribute='name' operator='eq' value='{consultationReference}' />			
                                    </filter>			
                                    </entity>			
                                    </fetch>";

            var bookingCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(bookingFetch, crmService);

            if (bookingCollection != null && bookingCollection.Entities.Count > 0)
            {
                var consultationRef = bookingCollection.Entities[0].Attributes["opportunityid"];
                payloadBooking.BookingInfo.BookingIdentifier.ConsultationReference = consultationRef.ToString();
            }
        }
コード例 #7
0
        private Dictionary <Guid, string> GetExistingSurveyFeedback(Guid surveyId)
        {
            trace.Trace("Processing GetExistingSurveyFeedback - start");
            var existingFeedback = new Dictionary <Guid, string>();

            if (surveyId == Guid.Empty)
            {
                return(existingFeedback);
            }

            var query = $@"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>
                            <entity name='tc_surveyresponsefeedback'>
                            <attribute name='tc_surveyresponsefeedbackid'/>
                            <attribute name='tc_question_id'/>
                              <filter type='and'>
                                <condition attribute='statecode' value='0' operator='eq'/>
                                <condition attribute='tc_surveyfeedbackid' value='{surveyId}' operator='eq'/>
                              </filter>
                            </entity>
                            </fetch>";

            var surveyFeedbackCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(query, payloadSurvey.CrmService);

            if (surveyFeedbackCollection == null || surveyFeedbackCollection.Entities.Count == 0)
            {
                return(existingFeedback);
            }
            for (int i = 0; i < surveyFeedbackCollection.Entities.Count; i++)
            {
                var surveyFeedback = surveyFeedbackCollection.Entities[i];
                if (surveyFeedback == null)
                {
                    continue;
                }
                if (surveyFeedback.Attributes.Contains(Attributes.SurveyResponseFeedback.QuestionId) && surveyFeedback.Attributes[Attributes.SurveyResponseFeedback.QuestionId] != null)
                {
                    existingFeedback.Add(surveyFeedback.Id, surveyFeedback.Attributes[Attributes.SurveyResponseFeedback.QuestionId].ToString());
                }
            }
            trace.Trace("Processing GetExistingSurveyFeedback - end");
            return(existingFeedback);
        }
コード例 #8
0
        private Guid GetSurveyId(long surveyId)
        {
            trace.Trace("Processing GetSurveyId - start");
            var surveyGuid       = Guid.Empty;
            var query            = $@"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>
                           <entity name='tc_surveyresponse'>
                           <attribute name='activityid'/>
                               <filter type='and'>
                                 <condition attribute='tc_response_id' value='{surveyId.ToString()}' operator='eq'/>
                               </filter>
                           </entity>
                           </fetch>";
            var surveyCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(query, payloadSurvey.CrmService);

            if (surveyCollection != null && surveyCollection.Entities.Count > 0)
            {
                surveyGuid = surveyCollection.Entities[0].Id;
            }
            trace.Trace("Processing GetSurveyId - end");
            return(surveyGuid);
        }
コード例 #9
0
        public string GetCustomerSourceSystemId(Guid bookingId)
        {
            string sourceSystemId = string.Empty;

            var customerBookingRoleFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>
                          <entity name='tc_customerbookingrole'>
                            <attribute name='tc_customerbookingroleid' />
                            <attribute name='tc_customer' />
                            <order attribute='tc_customer' descending='false' />
                            <filter type='and'>
                              <condition attribute='tc_bookingid' operator='eq' uitype='tc_booking' value='{bookingId}' />
                              <condition attribute='statecode' operator='eq' value='0' />
                            </filter>
                            <link-entity name='contact' from='contactid' to='tc_customer' visible='false' link-type='outer' alias='con'>
                              <attribute name='tc_sourcesystemid' />
                            </link-entity>
                            <link-entity name='account' from='accountid' to='tc_customer' visible='false' link-type='outer' alias='acc'>
                              <attribute name='tc_sourcesystemid' />
                            </link-entity>
                          </entity>
                        </fetch>";


            var customerBookingRoleCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(customerBookingRoleFetch, crmService);

            if (customerBookingRoleCollection != null && customerBookingRoleCollection.Entities.Count > 0)
            {
                var customerBookingRole = customerBookingRoleCollection.Entities[0];
                if (customerBookingRole.Attributes.Contains("con.tc_sourcesystemid") && customerBookingRole.Attributes["con.tc_sourcesystemid"] != null)
                {
                    sourceSystemId = ((AliasedValue)customerBookingRole.Attributes["con.tc_sourcesystemid"]).Value.ToString();
                }
                else if (customerBookingRole.Attributes.Contains("acc.tc_sourcesystemid") && customerBookingRole.Attributes["acc.tc_sourcesystemid"] != null)
                {
                    sourceSystemId = ((AliasedValue)customerBookingRole.Attributes["acc.tc_sourcesystemid"]).Value.ToString();
                }
            }
            return(sourceSystemId);
        }
コード例 #10
0
        public bool IsMatchedCustomer(string customerId)
        {
            //Validate payload for customer
            if (payloadBooking.BookingInfo == null)
            {
                throw new InvalidPluginExecutionException("Booking info missing in payload.");
            }
            if (payloadBooking.BookingInfo.Customer == null)
            {
                throw new InvalidPluginExecutionException("Customer is missing in payload.");
            }
            ;
            if (payloadBooking.BookingInfo.Customer.CustomerIdentifier == null)
            {
                throw new InvalidPluginExecutionException("Customer Identifier is missing.");
            }


            if (payloadBooking.BookingInfo.Customer.CustomerGeneral.CustomerType == CustomerType.Company)
            {
                var accountFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>
                      <entity name='account'>
                        <attribute name='accountid' />
                        <filter type='and'>
                          <condition attribute='tc_sourcesystemid' operator='eq' value='{customerId}' />
                          <condition attribute='statecode' operator='eq' value='0' />
                        </filter>
                      </entity>
                    </fetch>";

                var accountCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(accountFetch, crmService);
                if (accountCollection != null && accountCollection.Entities.Count == 1)
                {
                    return(true);
                }
                else if (accountCollection != null && accountCollection.Entities.Count > 1)
                {
                    throw new InvalidPluginExecutionException("More than one matching customer found in MSD with SourceSystemId");
                }

                return(false);
            }
            else if (payloadBooking.BookingInfo.Customer.CustomerGeneral.CustomerType == CustomerType.Person)
            {
                var contactFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>
                      <entity name='contact'>
                        <attribute name='contactid' />
                        <filter type='and'>
                          <condition attribute='tc_sourcesystemid' operator='eq' value='{customerId}' />
                          <condition attribute='statecode' operator='eq' value='0' />
                        </filter>
                      </entity>
                    </fetch>";

                var contactCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(contactFetch, crmService);
                if (contactCollection != null && contactCollection.Entities.Count == 1)
                {
                    return(true);
                }
                else if (contactCollection != null && contactCollection.Entities.Count > 1)
                {
                    throw new InvalidPluginExecutionException("More than one matching customer found in MSD with SourceSystemId");
                }
                return(false);
            }
            else
            {
                throw new InvalidPluginExecutionException("Customer type has not been specified.");
            }
        }