private EntityCollection RetrieveCreatedEntityCaches(string type, int numberOfElements)
        {
            if (string.IsNullOrEmpty(type))
            {
                throw new ArgumentNullException(nameof(type), "Type parameter cannot be empty");
            }

            var query = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                     <entity name='{EntityName.EntityCache}'>
                       <attribute name='{Attributes.EntityCache.EntityCacheId}' />
                       <attribute name='{Attributes.EntityCache.Name}' />
                       <attribute name='{Attributes.EntityCache.CreatedOn}' />
                       <attribute name='{Attributes.EntityCache.Type}' />
                       <attribute name='{Attributes.EntityCache.StatusReason}' />
                       <attribute name='{Attributes.EntityCache.State}' />
                       <attribute name='{Attributes.EntityCache.SourceMarket}' />
                       <attribute name='{Attributes.EntityCache.RecordId}' />
                       <attribute name='{Attributes.EntityCache.Operation}' />
                       <attribute name='{Attributes.EntityCache.Data}' />
                       <order attribute='{Attributes.EntityCache.CreatedOn}' descending='false' />
                       <filter type='and'>
                         <filter type='and'>
                           <condition attribute='{Attributes.EntityCache.Type}' operator='eq' value='{type}' />
                           <condition attribute='{Attributes.EntityCache.StatusReason}' operator='eq' value='{(int)EntityCacheStatusReason.Active}' />
                           <condition attribute='{Attributes.EntityCache.Operation}' operator='eq' value='{(int)EntityCacheOperation.Create}' />
                         </filter>
                       </filter>
                     </entity>
                   </fetch>";

            EntityCollection entityCacheCollection = crmService.RetrieveMultipleRecordsFetchXml(query, numberOfElements);

            return(entityCacheCollection);
        }
        public EntityCollection RetrieveEntityCaches(string type, int numberOfElements)
        {
            if (string.IsNullOrEmpty(type))
            {
                throw new ArgumentNullException(nameof(type), "Type parameter cannot be empty");
            }

            var query = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                     <entity name='tc_entitycache'>
                       <attribute name='tc_entitycacheid' />
                       <attribute name='tc_name' />
                       <attribute name='createdon' />
                       <attribute name='tc_type' />
                       <attribute name='statuscode' />
                       <attribute name='statecode' />
                       <attribute name='tc_sourcemarket' />
                       <attribute name='tc_recordid' />
                       <attribute name='tc_operation' />
                       <attribute name='tc_data' />
                       <order attribute='createdon' descending='false' />
                       <filter type='and'>
                         <filter type='and'>
                           <condition attribute='tc_type' operator='eq' value='{type}' />
                           <condition attribute='statuscode' operator='eq' value='{(int)EntityCacheStatusReason.Active}' />
                           <condition attribute='tc_operation' operator='eq' value='{(int)EntityCacheOperation.Create}' />
                         </filter>
                       </filter>
                     </entity>
                   </fetch>";

            EntityCollection entityCacheCollection = crmService.RetrieveMultipleRecordsFetchXml(query, numberOfElements);

            return(entityCacheCollection);
        }
        private EntityCollection RetrieveCreatedEntityCaches(string type, int numberOfElements)
        {
            if (string.IsNullOrEmpty(type))
            {
                throw new ArgumentNullException(nameof(type), "Type parameter cannot be empty");
            }

            var query = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>
								<entity name='{EntityName.EntityCache}'>
									<attribute name='{Attributes.EntityCache.EntityCacheId}' groupby='true' alias='{Attributes.EntityCache.EntityCacheId}' />
									<attribute name='{Attributes.EntityCache.Name}' groupby='true' alias='{Attributes.EntityCache.Name}' />
									<attribute name='{Attributes.EntityCache.CreatedOn}' groupby='true' dategrouping='day' alias='{Attributes.EntityCache.CreatedOn}' />
									<attribute name='{Attributes.EntityCache.Type}' groupby='true' alias='{Attributes.EntityCache.Type}' />
									<attribute name='{Attributes.EntityCache.StatusReason}' groupby='true' alias='{Attributes.EntityCache.StatusReason}' />
									<attribute name='{Attributes.EntityCache.State}' groupby='true' alias='{Attributes.EntityCache.State}' />
									<attribute name='{Attributes.EntityCache.SourceMarket}' groupby='true' alias='{Attributes.EntityCache.SourceMarket}' />
									<attribute name='{Attributes.EntityCache.RecordId}' groupby='true' alias='{Attributes.EntityCache.RecordId}' />
									<attribute name='{Attributes.EntityCache.Operation}' groupby='true' alias='{Attributes.EntityCache.Operation}' />
									<attribute name='{Attributes.EntityCache.Data}' groupby='true' alias='{Attributes.EntityCache.Data}' />
									<link-entity name='{EntityName.EntityCacheMessage}' from='{Attributes.EntityCache.EntityCacheId}' to='{Attributes.EntityCache.EntityCacheId}' link-type='outer' alias='{EntityCacheMessagAlias}'> 
										<attribute name='{Attributes.EntityCacheMessage.EntityCacheMessageId}' aggregate='countcolumn' alias='{EntityCacheMessagCountAlias}' />
									</link-entity> 
									<order alias='{Attributes.EntityCache.CreatedOn}' descending='false' />
									<filter type='and'>
										<filter type='or'>
											<condition attribute='{Attributes.EntityCache.StatusReason}' operator='eq' value='{(int)EntityCacheStatusReason.Active}' />
											<filter type='and'>
												<condition attribute='{Attributes.EntityCache.StatusReason}' operator='eq' value='{(int)EntityCacheStatusReason.InProgress}' />
												<condition attribute='{Attributes.EntityCache.EligibleRetryTime}' operator='le' value='{DateTime.UtcNow.ToString("o")}' />
												<condition attribute='{Attributes.EntityCache.WasLastOperationSuccessful}' operator='eq' value='{false}' />
											</filter>
										</filter>
										<filter type='and'>
											<condition attribute='{Attributes.EntityCache.Type}' operator='eq' value='{type}' />
											<condition attribute='{Attributes.EntityCache.Operation}' operator='eq' value='{(int)EntityCacheOperation.Create}' />
										</filter>
									</filter>
								</entity>
							</fetch>"                            ;

            EntityCollection entityCacheCollection = crmService.RetrieveMultipleRecordsFetchXml(query, numberOfElements);

            return(entityCacheCollection);
        }
예제 #4
0
        public DeallocationExecutionRequest FetchBookingsForDeallocation(DeallocationRequest bookingDeallocationRequest)
        {
            //logger.LogInformation("GetBookingAllocations - start");

            // don't process invalid request
            if (bookingDeallocationRequest == null || bookingDeallocationRequest.Destination == null ||
                bookingDeallocationRequest.Destination.Count == 0 ||
                bookingDeallocationRequest.Date == null || bookingDeallocationRequest.Date == DateTime.MinValue || bookingDeallocationRequest.Date == DateTime.MaxValue)
            {
                return(null);
            }

            var destinationGateWays = GetLookupConditions(bookingDeallocationRequest.Destination);
            // get ids of bookings, filtered by return date and destination gateway, ordered by booking id, whose owner is hotel team
            // via customerbookingrole ordered by customer:
            // - get ids of contacts of booking and ids of their active incidents
            // - get ids of accounts of booking and ids of their active incidents
            // via country to business unit get business unit name and get business unit default team id
            var query = string.Format(
                @"<fetch distinct='true' mapping='logical' output-format='xml-platform' version='1.0'>
                    <entity name='tc_booking'>
                    <attribute name='tc_bookingid' />
                    <filter type='and'>
                        <condition attribute='tc_returndate' operator='on' value='{0}' />
                        <condition attribute='tc_destinationgatewayid' operator='in'>
                        {1}
                        </condition>
                    </filter>
                    <order attribute='tc_bookingid' />
                    <link-entity name='team' from='teamid' to='owningteam' link-type='inner'>
                        <filter type='and'>
                        <condition attribute='tc_hotelteam' operator='eq' value='1' />
                        </filter>
                    </link-entity>
                    <link-entity name='tc_customerbookingrole' from='tc_bookingid' to='tc_bookingid' link-type='outer'>
                        <order attribute='tc_customer' />
                        <link-entity name='contact' from='contactid' to='tc_customer' link-type='outer' alias='contact' visible='true'>
                            <attribute name='contactid' />
                            <link-entity name='incident' from='customerid' to='contactid' link-type='outer' alias='contactincident' visible='true'>
                                <attribute name='incidentid' />
                                <attribute name='ownerid' />
                                <filter type='and'>
                                    <condition attribute='statecode' operator='eq' value='0' />
                                </filter>
                            </link-entity>
                        </link-entity>
                        <link-entity name='account' from='accountid' to='tc_customer' link-type='outer' alias='account'>
                            <attribute name='accountid' />
                            <link-entity name='incident' from='customerid' to='accountid' link-type='outer' alias='accountincident' visible='true'>
                                <attribute name='incidentid' />
                                <attribute name='ownerid' />
                                <filter type='and'>
                                    <condition attribute='statecode' operator='eq' value='0' />
                                </filter>
                            </link-entity>
                        </link-entity>
                    </link-entity>
                    <link-entity name='tc_country' from='tc_countryid' to='tc_sourcemarketid' link-type='inner'>
                        <link-entity name='businessunit' from='businessunitid' to='tc_sourcemarketbusinessunitid' link-type='inner' alias='businessunit' visible='true'>
                            <attribute name='name' />
                            <link-entity name='team' from='businessunitid' to='businessunitid' link-type='inner' alias='team' visible='true'>
                                <attribute name='teamid' />
                                <filter>
                                    <condition attribute='isdefault' operator='eq' value='1' />
                                </filter>                                
                            </link-entity>
                        </link-entity>
                    </link-entity>
                    </entity>
                </fetch>",
                new object[] { bookingDeallocationRequest.Date.ToString("yyyy-MM-dd"),
                               destinationGateWays.ToString() });

            EntityCollection bookingCollection = crmService.RetrieveMultipleRecordsFetchXml(query);
            var caseOwnersandDefaultTeams      = GetCaseOwnersandDefaultTeams(bookingCollection);
            var customerRelationUsers          = GetUsersBySecurityRole(caseOwnersandDefaultTeams, bookingDeallocationRequest.UserRolesToAssignCase);
            var customerRelationTeams          = GetTeamsBySecurityRole(caseOwnersandDefaultTeams, bookingDeallocationRequest.TeamRolesToAssignCase);
            var result = ConvertCrmResponse(bookingCollection, customerRelationUsers, customerRelationTeams);

            return(result);
        }
예제 #5
0
        public IList <BookingAllocationResponse> GetBookingAllocations(BookingAllocationRequest bookingAllocationRequest)
        {
            if (bookingAllocationRequest == null)
            {
                throw new ArgumentNullException("bookingAllocationRequest");
            }

            if (bookingAllocationRequest.Destination == null)
            {
                throw new ArgumentNullException("bookingAllocationRequest.Destination");
            }

            var destinationGateWays = GetDestinationGateways(bookingAllocationRequest.Destination);

            if (bookingAllocationRequest.DepartureDate == null || bookingAllocationRequest.ReturnDate == null)
            {
                throw new ArgumentNullException("bookingAllocationRequest.DepartureDate and bookingAllocationRequest.ReturnDate");
            }

            var query = string.Format(@"<fetch version='1.0' output-format='xml-platform' mapping='logical'>
                                                 <entity name='tc_booking'>
                                                    <attribute name='tc_bookingid'/>
                                                    <attribute name='tc_name'/>
                                                    <attribute name='ownerid'/>
                                                    <order attribute='tc_name' descending='false'/>                                                    
                                                    <filter type='and'>
                                                        <filter type='and'>
                                                                <filter type='or'>
                                                                <condition attribute='tc_departuredate' operator='next-x-days' value='{0}'/>
                                                                    <filter type='and'>
                                                                        <condition attribute='tc_departuredate' operator='on-or-before' value='{1}'/>
                                                                        <condition attribute='tc_returndate' operator='on-or-after' value='{2}'/>
                                                                    </filter>
                                                                </filter>
                                                            <condition attribute='tc_destinationgatewayid' operator='in'>
                                                            {3}
                                                            </condition>
                                                        </filter>
                                                    </filter>
                                                    <link-entity name='tc_country' alias='sourcemarket' to='tc_sourcemarketid' from='tc_countryid'>
                                                     <attribute name='tc_sourcemarketbusinessunitid'/>
                                                        <filter type='and'>
                                                            <condition attribute='tc_sourcemarketbusinessunitid' operator='not-null'/>
                                                        </filter>
                                                    </link-entity>
                                                    <link-entity name='tc_bookingaccommodation' alias='accommodation' from='tc_bookingid' to='tc_bookingid'>
                                                        <attribute name='tc_startdateandtime'/>
                                                        <attribute name='tc_enddateandtime'/>
                                                        <order attribute='tc_startdateandtime' descending='false'/>
                                                            <link-entity name='tc_hotel' alias='hotel' from='tc_hotelid' to='tc_hotelid'>
                                                                    <attribute name='tc_name'/>                                                                
                                                                <attribute name='ownerid'/>
                                                                  <link-entity name='team' alias='hotelteam' from='teamid' to='owningteam'/>
                                                            </link-entity>
                                                    </link-entity>
                                                    <link-entity link-type='outer' name='tc_customerbookingrole' alias='role' from='tc_bookingid' to='tc_bookingid'>
                                                      <attribute name='tc_customer'/>
                                                         <link-entity link-type='outer' name='account' alias='account' from='accountid' to='tc_customer'>
                                                            <attribute name='ownerid'/>
                                                         </link-entity>
                                                         <link-entity link-type='outer' name='contact' alias='contact' from='contactid' to='tc_customer'>
                                                            <attribute name='ownerid'/>
                                                         </link-entity>
                                                    </link-entity>
                                                 </entity>
                                                 </fetch>",
                                      new object[] { bookingAllocationRequest.DepartureDateInNextXDays,
                                                     bookingAllocationRequest.DepartureDate.ToString("yyyy-MM-dd"),
                                                     bookingAllocationRequest.ReturnDate.ToString("yyyy-MM-dd"),
                                                     destinationGateWays.ToString() });

            var bookingCollection = crmService.RetrieveMultipleRecordsFetchXml(query);

            var parentHotelTeam = GetHotelTeams(bookingCollection);

            var childTeamCollection = GetChildTeams(parentHotelTeam);

            var childHotelTeam = PrepareChildTeam(childTeamCollection);

            return(PrepareBookingAllocation(bookingCollection, childHotelTeam));
        }