private EntityDataServiceResponse <SalesAffiliationLoyaltyTier> GetLoyaltyCardAffiliations(GetLoyaltyCardAffiliationsDataRequest request)
            {
                ThrowIf.Null(request.LoyaltyCardNumber, "loyaltyCardNumber");

                ParameterSet parameters = new ParameterSet();

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

                ReadOnlyCollection <AffiliationLoyaltyTier> affiliations;

                using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    affiliations = sqlServerDatabaseContext.ExecuteNonPagedStoredProcedure <AffiliationLoyaltyTier>(LoyaltySqlServerDataService.GetActiveLoyaltyCardTiersSprocName, parameters);
                }

                ReadOnlyCollection <SalesAffiliationLoyaltyTier> salesAffiliations = affiliations.Select(loyaltyAffiliation =>
                                                                                                         new SalesAffiliationLoyaltyTier()
                {
                    AffiliationId   = loyaltyAffiliation.AffiliationId,
                    LoyaltyTierId   = loyaltyAffiliation.LoyaltyTierId,
                    AffiliationType = RetailAffiliationType.Loyalty,
                    ChannelId       = request.RequestContext.GetPrincipal().ChannelId,
                    ReceiptId       = request.Transaction.ReceiptId,
                    StaffId         = request.Transaction.StaffId,
                    TerminalId      = request.Transaction.TerminalId,
                    TransactionId   = request.Transaction.Id
                }).AsReadOnly();

                return(new EntityDataServiceResponse <SalesAffiliationLoyaltyTier>(salesAffiliations.AsPagedResult()));
            }
            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()));
            }
            /// <summary>
            /// Gets all the loyalty tiers of the given loyalty group.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <param name="loyaltyGroupRecordId">The record identifier of the loyalty group.</param>
            /// <returns>The collection of the loyalty tiers.</returns>
            private ReadOnlyCollection <LoyaltyTier> GetLoyaltyTiers(Request request, long loyaltyGroupRecordId)
            {
                ParameterSet parameters = new ParameterSet();

                parameters["@bi_loyaltyGroupRecordId"] = loyaltyGroupRecordId;
                parameters["@nvc_Locale"] = request.RequestContext.LanguageId;

                ReadOnlyCollection <LoyaltyTier> loyaltyTiers;

                // Get all loyalty tiers of the given loyalty group.
                using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    loyaltyTiers = sqlServerDatabaseContext.ExecuteNonPagedStoredProcedure <LoyaltyTier>(LoyaltySqlServerDataService.GetLoyaltyTiersSprocName, parameters);
                }

                return(loyaltyTiers);
            }
            private SingleEntityDataServiceResponse <LoyaltyCard> GetLoyaltyCard(GetLoyaltyCardDataRequest request)
            {
                ThrowIf.NullOrWhiteSpace(request.LoyaltyCardNumber, "loyaltyCardNumber");

                ParameterSet parameters = new ParameterSet();

                parameters["@nvc_LoyaltyCardNumber"]  = request.LoyaltyCardNumber;
                parameters["@nvc_CustomerDataAreaId"] = request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId;

                LoyaltyCard loyaltyCard;

                using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    loyaltyCard = sqlServerDatabaseContext.ExecuteNonPagedStoredProcedure <LoyaltyCard>(LoyaltySqlServerDataService.GetLoyaltyCardSprocName, parameters).SingleOrDefault();
                }

                return(new SingleEntityDataServiceResponse <LoyaltyCard>(loyaltyCard));
            }
            private EntityDataServiceResponse <LoyaltyCard> GetCustomerLoyaltyCards(GetCustomerLoyaltyCardsDataRequest request)
            {
                ThrowIf.NullOrWhiteSpace(request.CustomerAccountNumber, "customerAccountNumber");

                ParameterSet parameters = new ParameterSet();

                parameters["@nvc_CustomerAccountNumber"] = request.CustomerAccountNumber;
                parameters["@nvc_CustomerDataAreaId"]    = request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId;

                ReadOnlyCollection <LoyaltyCard> loyaltyCards;

                using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    loyaltyCards = sqlServerDatabaseContext.ExecuteNonPagedStoredProcedure <LoyaltyCard>(LoyaltySqlServerDataService.GetCustomerLoyaltyCardsSprocName, parameters);
                }

                return(new EntityDataServiceResponse <LoyaltyCard>(loyaltyCards.AsPagedResult()));
            }
            private EntityDataServiceResponse <LoyaltySchemeLineEarn> GetLoyaltySchemeLineEarn(GetLoyaltySchemeLineEarnDataRequest request)
            {
                ThrowIf.Null(request.LoyaltyCardNumber, "loyaltyCardNumber");

                ParameterSet parameters = new ParameterSet();

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

                ReadOnlyCollection <LoyaltySchemeLineEarn> schemeLines;

                using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    schemeLines = sqlServerDatabaseContext.ExecuteNonPagedStoredProcedure <LoyaltySchemeLineEarn>(LoyaltySqlServerDataService.GetLoyaltyEarnSchemeLinesSprocName, parameters);
                }

                return(new EntityDataServiceResponse <LoyaltySchemeLineEarn>(schemeLines.AsPagedResult()));
            }
Exemple #7
0
            /// <summary>
            /// Gets the exchange rate active on given date between these currencies on this channel.
            /// </summary>
            /// <param name="request">The data service request with the to and from currencies and active date.</param>
            /// <returns>The data service response with up to two exchange rates, which are forward and backward rates between the currencies.</returns>
            public EntityDataServiceResponse <ExchangeRate> GetExchangeRates(GetExchangeRatesDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.NullOrWhiteSpace(request.FromCurrency, "fromCurrency");
                ThrowIf.NullOrWhiteSpace(request.ToCurrency, "toCurrency");

                ReadOnlyCollection <ExchangeRate> result;

                CurrencyDataManager manager = new CurrencyDataManager(request.RequestContext);

                CurrencyL2CacheDataStoreAccessor level2CacheDataAccessor = (CurrencyL2CacheDataStoreAccessor)manager.DataStoreManagerInstance.RegisteredAccessors[DataStoreType.L2Cache];

                bool updateL2Cache = DataStoreManager.DataStores[DataStoreType.L2Cache].Policy.MustUpdateOnMiss;

                result         = level2CacheDataAccessor.GetExchangeRates(request.FromCurrency, request.ToCurrency, request.ActiveDate);
                updateL2Cache &= result == null;

                if (result == null)
                {
                    ParameterSet parameters = new ParameterSet();

                    parameters[FromCurrencyVariable] = request.FromCurrency;
                    parameters[ToCurrencyVariable]   = request.ToCurrency;
                    parameters[ActiveDateVariable]   = request.ActiveDate;

                    using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                    {
                        result = sqlServerDatabaseContext.ExecuteNonPagedStoredProcedure <ExchangeRate>(GetExchangeRateProcedureName, parameters);
                    }

                    updateL2Cache &= result != null;
                }

                if (updateL2Cache)
                {
                    level2CacheDataAccessor.PutExchangeRates(request.FromCurrency, request.ToCurrency, request.ActiveDate, result);
                }

                return(new EntityDataServiceResponse <ExchangeRate>(result.AsPagedResult()));
            }
            /// <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);
            }