Exemplo n.º 1
0
            /// <summary>
            /// Gets the loyalty card status including the loyalty groups and the reward points status.
            /// </summary>
            /// <param name="request">The request containing the card number.</param>
            /// <returns>The response containing the loyalty card status.</returns>
            private static GetLoyaltyCardStatusServiceResponse GetLoyaltyCardStatus(GetLoyaltyCardStatusServiceRequest request)
            {
                // Get loyalty card basic information
                var         getLoyaltyCardDataRequest = new GetLoyaltyCardDataRequest(request.LoyaltyCardNumber);
                LoyaltyCard loyaltyCard = request.RequestContext.Execute <SingleEntityDataServiceResponse <LoyaltyCard> >(getLoyaltyCardDataRequest).Entity;

                if (loyaltyCard == null)
                {
                    return(new GetLoyaltyCardStatusServiceResponse());
                }

                var validateCustomerAccountRequest = new GetValidatedCustomerAccountNumberServiceRequest(loyaltyCard.CustomerAccount, throwOnValidationFailure: true);

                request.RequestContext.Execute <GetValidatedCustomerAccountNumberServiceResponse>(validateCustomerAccountRequest);

                // Get loyalty groups and loyalty tiers
                DateTimeOffset channelDateTime = request.RequestContext.GetNowInChannelTimeZone();
                var            getLoyaltyGroupsAndTiersDataRequest = new GetLoyaltyGroupsAndTiersDataRequest(request.LoyaltyCardNumber, request.RetrieveRewardPointStatus);

                getLoyaltyGroupsAndTiersDataRequest.QueryResultSettings = QueryResultSettings.AllRecords;
                loyaltyCard.LoyaltyGroups = request.RequestContext.Execute <EntityDataServiceResponse <LoyaltyGroup> >(getLoyaltyGroupsAndTiersDataRequest).PagedEntityCollection.Results;

                // Get reward points status
                if (request.RetrieveRewardPointStatus)
                {
                    var serviceRequest = new GetLoyaltyCardRewardPointsStatusRealtimeRequest(
                        channelDateTime,
                        request.LoyaltyCardNumber,
                        excludeBlocked: false,
                        excludeNoTender: false,
                        includeRelatedCardsForContactTender: false,
                        includeNonRedeemablePoints: false,
                        includeActivePointsOnly: false);

                    EntityDataServiceResponse <LoyaltyCard> serviceResponse = request.RequestContext.Execute <EntityDataServiceResponse <LoyaltyCard> >(serviceRequest);
                    LoyaltyCard loyaltyCardWithPoints = serviceResponse.PagedEntityCollection.FirstOrDefault();

                    if (loyaltyCardWithPoints != null)
                    {
                        loyaltyCard.RewardPoints = loyaltyCardWithPoints.RewardPoints;
                    }
                }

                var response = new GetLoyaltyCardStatusServiceResponse(loyaltyCard);

                return(response);
            }
            /// <summary>
            /// Gets all the loyalty card tiers that the given card is currently and will be qualified for.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <param name="loyaltyGroupRecordId">The record identifier of the loyalty group.</param>
            /// <returns>The collection of the loyalty card tiers.</returns>
            private ReadOnlyCollection <LoyaltyCardTier> GetActiveOrFutureLoyaltyCardTiers(GetLoyaltyGroupsAndTiersDataRequest request, long loyaltyGroupRecordId)
            {
                ThrowIf.Null(request.LoyaltyCardNumber, "cardNumber");

                ParameterSet parameters = new ParameterSet();

                parameters["@nvc_LoyaltyCardNumber"]   = request.LoyaltyCardNumber;
                parameters["@bi_LoyaltyGroupRecordId"] = loyaltyGroupRecordId;
                parameters["@dt_ChannelLocalDate"]     = request.RequestContext.GetNowInChannelTimeZone().Date;

                // The flag indicating whether to retrieve the loyalty card tiers that take effect in the future.
                parameters["@b_retrieveFutureCardTiers"] = request.RetrieveFutureLoyaltyCardTiers;

                // Get the active or future loyalty card tiers
                ReadOnlyCollection <LoyaltyCardTier> loyaltyCardTiers;

                using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    loyaltyCardTiers = sqlServerDatabaseContext.ExecuteNonPagedStoredProcedure <LoyaltyCardTier>(LoyaltySqlServerDataService.GetActiveOrFutureLoyaltyCardTierSprocName, parameters);
                }

                return(loyaltyCardTiers);
            }
            private EntityDataServiceResponse <LoyaltyGroup> GetLoyaltyGroupsAndTiersByCardNumber(GetLoyaltyGroupsAndTiersDataRequest request)
            {
                ThrowIf.Null(request.LoyaltyCardNumber, "loyaltyCardNumber");

                ParameterSet parameters = new ParameterSet();

                parameters["@nvc_LoyaltyCardNumber"] = request.LoyaltyCardNumber;
                parameters["@nvc_Locale"]            = request.RequestContext.LanguageId;

                // Get all loyalty groups of the loyalty cards.
                ReadOnlyCollection <LoyaltyGroup> loyaltyGroups;

                using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    loyaltyGroups = sqlServerDatabaseContext.ExecuteNonPagedStoredProcedure <LoyaltyGroup>(LoyaltySqlServerDataService.GetLoyaltyGroupsByLoyaltyCardSprocName, parameters);
                }

                // Get all loyalty tiers of each loyalty group
                foreach (var loyaltyGroup in loyaltyGroups)
                {
                    loyaltyGroup.LoyaltyTiers     = this.GetLoyaltyTiers(request, loyaltyGroup.RecordId);
                    loyaltyGroup.LoyaltyCardTiers = this.GetActiveOrFutureLoyaltyCardTiers(request, loyaltyGroup.RecordId);
                }

                return(new EntityDataServiceResponse <LoyaltyGroup>(loyaltyGroups.AsPagedResult()));
            }