/// <summary> /// Gets the customer account by external identity. /// </summary> /// <param name="request">The data service request.</param> /// <returns>The data service response.</returns> private SingleEntityDataServiceResponse <CommerceIdentityProvider> GetCommerceIdentityProviderByIssuer(GetCommerceIdentityProviderByIssuerDataRequest request) { CommerceIdentityProviderL2CacheDataStoreAccessor levelL2CacheDataAccessor = this.GetCommerceIdentityProviderL2CacheDataStoreAccessor(request.RequestContext); bool foundInCache; bool updateCache; CommerceIdentityProvider commerceIdentityProvider = DataManager.GetDataFromCache(() => levelL2CacheDataAccessor.GetCommerceIdentityProviderByIssuer(request.CommerceIdentityProviderIssuer), out foundInCache, out updateCache); if (!foundInCache) { var getIdentityProviderParameters = new ParameterSet(); PagedResult <CommerceRelyingParty> identityProviderRelyingParties; getIdentityProviderParameters["@nvc_Issuer"] = request.CommerceIdentityProviderIssuer; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { commerceIdentityProvider = sqlServerDatabaseContext.ExecuteStoredProcedure <CommerceIdentityProvider>(GetIdentityProviderSprocName, getIdentityProviderParameters).Results.FirstOrDefault(); if (commerceIdentityProvider != null) { var getRelyingPartiesParameters = new ParameterSet(); getRelyingPartiesParameters["@bi_ProviderId"] = commerceIdentityProvider.RecordId; identityProviderRelyingParties = sqlServerDatabaseContext.ExecuteStoredProcedure <CommerceRelyingParty>(GetRelyingPartiesByIdentityProviderSprocName, getRelyingPartiesParameters); commerceIdentityProvider.CommerceRelyingParties = identityProviderRelyingParties.Results.ToList(); } } } if (updateCache && commerceIdentityProvider != null) { levelL2CacheDataAccessor.CacheCommerceIdentityProviderByIssuer(request.CommerceIdentityProviderIssuer, commerceIdentityProvider); } return(new SingleEntityDataServiceResponse <CommerceIdentityProvider>(commerceIdentityProvider)); }
/// <summary> /// The data service method to get tax code intervals. /// </summary> /// <param name="request">The data service request.</param> /// <returns>The data service response.</returns> private EntityDataServiceResponse <TaxCodeInterval> GetTaxCodeIntervals(GetTaxCodeIntervalsDataRequest request) { ThrowIf.Null(request.ItemTaxGroupId, "itemTaxGroupId"); var taxDataManager = this.GetDataManagerInstance(request.RequestContext); TaxL2CacheDataStoreAccessor level2CacheDataAccessor = (TaxL2CacheDataStoreAccessor)taxDataManager.DataStoreManagerInstance.RegisteredAccessors[DataStoreType.L2Cache]; bool found; bool updateL2Cache; ReadOnlyCollection <TaxCodeInterval> result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetTaxCodeIntervals(request.SalesTaxGroupId, request.ItemTaxGroupId), out found, out updateL2Cache); if (!found) { ParameterSet parameters = new ParameterSet(); parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId; parameters["@nvc_SalesTaxGroup"] = request.SalesTaxGroupId ?? string.Empty; parameters["@nvc_ItemTaxGroup"] = request.ItemTaxGroupId ?? string.Empty; parameters["@dt_TransactionDate"] = request.TransactionDate.DateTime; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(request)) { result = databaseContext.ExecuteStoredProcedure <TaxCodeInterval>(GetTaxCodeIntervalsSprocName, parameters).Results; } updateL2Cache &= result != null && result.Count < MaxCachedCollectionSize; } if (updateL2Cache) { level2CacheDataAccessor.PutTaxCodeIntervals(request.SalesTaxGroupId, request.ItemTaxGroupId, request.TransactionDate, result); } return(new EntityDataServiceResponse <TaxCodeInterval>(result.AsPagedResult())); }
/// <summary> /// Gets the setting that shows whether to apply inter-state tax for India or not. /// </summary> /// <param name="request">The get apply interstate tax India data request.</param> /// <returns>The setting that shows whether to apply inter-state tax for India or not.</returns> private SingleEntityDataServiceResponse <ApplyInterStateTaxIndia> GetApplyInterstateTaxIndia(GetApplyInterstateTaxIndiaDataRequest request) { ThrowIf.Null(request, "request"); IndiaTaxL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetIndiaTaxL2CacheDataStoreAccessor(request.RequestContext); bool found; bool updateL2Cache; ApplyInterStateTaxIndia result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetApplyInterStateTaxIndia(request.QueryResultSettings.ColumnSet), out found, out updateL2Cache); if (!found) { // Fetches it from database if no setting was cached. // Input parameters ParameterSet parameters = new ParameterSet(); parameters["@bi_ChannelId"] = request.RequestContext.GetPrincipal().ChannelId; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { result = sqlServerDatabaseContext.ExecuteStoredProcedure <ApplyInterStateTaxIndia>(GetApplyInterStateTaxIndiaName, parameters).SingleOrDefault(); } updateL2Cache &= result != null; } if (updateL2Cache) { // Caches the result if it is fetched from database. level2CacheDataAccessor.PutApplyInterStateTaxIndia(request.QueryResultSettings.ColumnSet, result); } return(new SingleEntityDataServiceResponse <ApplyInterStateTaxIndia>(result)); }
private EntityDataServiceResponse <NonSalesTransaction> GetCurrentShiftNonSalesTransactions(GetCurrentShiftNonSalesTransactionsDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.NonSalesTransaction, "request.NonSalesTransaction"); string transactionId = request.NonSalesTransactionId; if (string.IsNullOrWhiteSpace(request.NonSalesTransactionId)) { transactionId = string.Empty; } var transaction = request.NonSalesTransaction; var parameters = new ParameterSet(); parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId; parameters["@nvc_TRANSACTIONTYPE"] = transaction.TransactionTypeValue; parameters["@nvc_TENDERTYPE"] = transaction.TenderTypeId; parameters["@nvc_BATCHTERMINALID"] = transaction.ShiftTerminalId; parameters["@bi_BATCHID"] = transaction.ShiftId; parameters["@nvc_TransactionId"] = transactionId; PagedResult <NonSalesTransaction> results; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { results = sqlServerDatabaseContext.ExecuteStoredProcedure <NonSalesTransaction>("GETCURRENTSHIFTNONSALETENDERS", parameters); } return(new EntityDataServiceResponse <NonSalesTransaction>(results)); }
private GetCountryRegionDataResponse GetCountryRegion(GetCountryRegionDataRequest request) { ThrowIf.Null(request.QueryResultSettings, "settings"); string languageId = request.LanguageId; if (string.IsNullOrWhiteSpace(languageId)) { var getDefaultLanguageIdDataRequest = new GetDefaultLanguageIdDataRequest(); languageId = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <string> >(getDefaultLanguageIdDataRequest, request.RequestContext).Entity; } var parameterSet = new ParameterSet(); parameterSet["nvc_LanguageId"] = languageId; Tuple <PagedResult <CountryRegionInfo>, ReadOnlyCollection <AddressFormattingInfo> > countryRegions; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { countryRegions = sqlServerDatabaseContext.ExecuteStoredProcedure <CountryRegionInfo, AddressFormattingInfo>(GetCountryRegionInfoSprocName, parameterSet); } return(new GetCountryRegionDataResponse(countryRegions.Item1, countryRegions.Item2)); }
private EntityDataServiceResponse <ZipCodeInfo> GetZipCodes(GetZipPostalCodeDataRequest request) { ThrowIf.Null(request.CountryRegionCode, "countryRegionCode"); ThrowIf.Null(request.StateId, "stateId"); ThrowIf.Null(request.CountyId, "countyId"); ThrowIf.Null(request.City, "city"); ThrowIf.Null(request.District, "districtId"); ParameterSet filters = new ParameterSet(); filters[AddressServiceConstants.CountryRegionId] = request.CountryRegionCode; filters[AddressServiceConstants.StateProvinceId] = request.StateId; filters[AddressServiceConstants.CountyId] = request.CountyId; filters[AddressServiceConstants.CityComponentName] = request.City; filters[AddressServiceConstants.DistrictId] = request.District; PagedResult <ZipCodeInfo> zipCodes; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { zipCodes = sqlServerDatabaseContext.ExecuteStoredProcedure <ZipCodeInfo>(GetZipCodesInfoSprocName, filters); } return(new EntityDataServiceResponse <ZipCodeInfo>(zipCodes)); }
/// <summary> /// Gets a default logistics postal address for India. /// </summary> /// <param name="request">The get warehouse address India data request.</param> /// <returns>Matching address.</returns> /// <remarks> /// Search address as warehouse -> site -> legal entity. /// </remarks> private SingleEntityDataServiceResponse <Address> GetWarehouseAddressIndia(GetWarehouseAddressIndiaDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.NullOrWhiteSpace(request.WarehouseId, "request.WarehouseId"); IndiaTaxL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetIndiaTaxL2CacheDataStoreAccessor(request.RequestContext); bool found; bool updateL2Cache; Address result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetWarehouseAddressIndia(request.WarehouseId), out found, out updateL2Cache); if (!found) { ParameterSet parameters = new ParameterSet(); parameters["@nv_InventLocationId"] = request.WarehouseId; parameters["@nv_InventLocationDataAreaId"] = request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { result = sqlServerDatabaseContext.ExecuteStoredProcedure <Address>(GetWarehouseAddressIndiaName, parameters).SingleOrDefault(); } updateL2Cache &= result != null; } if (updateL2Cache) { level2CacheDataAccessor.PutWarehouseAddressIndia(request.WarehouseId, result); } return(new SingleEntityDataServiceResponse <Address>(result)); }
/// <summary> /// Gets Receipt Header tax information for India. /// </summary> /// <param name="request">The get receipt header tax info India data request.</param> /// <returns>Receipt Header tax info.</returns> private SingleEntityDataServiceResponse <ReceiptHeaderTaxInfoIndia> GetReceiptHeaderTaxInfoIndia(GetReceiptHeaderTaxInfoIndiaDataRequest request) { ThrowIf.Null(request, "request"); IndiaTaxL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetIndiaTaxL2CacheDataStoreAccessor(request.RequestContext); bool found; bool updateL2Cache; ReceiptHeaderTaxInfoIndia result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetReceiptHeaderTaxInfoIndia(request.QueryResultSettings.ColumnSet), out found, out updateL2Cache); if (!found) { ParameterSet parameters = new ParameterSet(); parameters["@bi_ChannelId"] = request.RequestContext.GetPrincipal().ChannelId; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { result = sqlServerDatabaseContext.ExecuteStoredProcedure <ReceiptHeaderTaxInfoIndia>(GetReceiptHeaderTaxInfoIndiaName, parameters).SingleOrDefault(); } updateL2Cache &= result != null; } if (updateL2Cache) { level2CacheDataAccessor.PutReceiptHeaderTaxInfoIndia(request.QueryResultSettings.ColumnSet, result); } return(new SingleEntityDataServiceResponse <ReceiptHeaderTaxInfoIndia>(result)); }
private EntityDataServiceResponse <HardwareStationProfile> GetHardwareStationProfile(GetHardwareStationDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.RequestContext, "request.RequestContext"); ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings"); ParameterSet parameters = new ParameterSet(); Tuple <PagedResult <HardwareStationProfile>, ReadOnlyCollection <HardwareConfiguration>, ReadOnlyCollection <HardwareConfiguration>, ReadOnlyCollection <HardwareConfiguration> > dataSets = null; parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(request.RequestContext, request.QueryResultSettings)) { dataSets = databaseContext.ExecuteStoredProcedure <HardwareStationProfile, HardwareConfiguration, HardwareConfiguration, HardwareConfiguration>(GetHardwareStationsSprocName, parameters); } PagedResult <HardwareStationProfile> hardwareStationProfiles = dataSets.Item1; ReadOnlyCollection <HardwareConfiguration> drawers = dataSets.Item2; ReadOnlyCollection <HardwareConfiguration> printers = dataSets.Item3; ReadOnlyCollection <HardwareConfiguration> pinpads = dataSets.Item4; foreach (var hardwareStationProfile in hardwareStationProfiles.Results) { if (hardwareStationProfile != null) { hardwareStationProfile.HardwareConfigurations = new HardwareConfigurations(); if (drawers != null) { hardwareStationProfile.HardwareConfigurations.CashDrawerConfigurations.AddRange( from d in drawers where d.HardwareStationRecordId == hardwareStationProfile.RecordId && !string.IsNullOrEmpty(d.DeviceName) select d); } if (printers != null) { hardwareStationProfile.HardwareConfigurations.PrinterConfigurations.AddRange( from p in printers where p.HardwareStationRecordId == hardwareStationProfile.RecordId && !string.IsNullOrEmpty(p.DeviceName) select p); } if (pinpads != null) { hardwareStationProfile.HardwareConfigurations.PinPadConfiguration = (from p in pinpads where p.HardwareStationRecordId == hardwareStationProfile.RecordId && !string.IsNullOrEmpty(p.DeviceName) select p).SingleOrDefault(); } } } return(new EntityDataServiceResponse <HardwareStationProfile>(hardwareStationProfiles)); }
/// <summary> /// The data service method to execute the data manager to get the device configuration. /// </summary> /// <param name="request">The data service request.</param> /// <returns>The data service response.</returns> private SingleEntityDataServiceResponse <DeviceConfiguration> GetDeviceConfiguration(GetDeviceConfigurationDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.RequestContext, "request.RequestContext"); ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings"); ICommercePrincipal principal = request.RequestContext.GetPrincipal(); if (principal.IsChannelAgnostic || principal.IsTerminalAgnostic || string.IsNullOrWhiteSpace(principal.DeviceNumber)) { throw new InvalidOperationException("Current request context is not associated to a device."); } Terminal terminal = request.RequestContext.GetTerminal(); ParameterSet parameters = new ParameterSet(); Tuple <PagedResult <DeviceConfiguration>, ReadOnlyCollection <HardwareConfiguration>, ReadOnlyCollection <HardwareConfiguration>, ReadOnlyCollection <HardwareConfiguration> > dataSets = null; parameters[DatabaseAccessor.ChannelIdVariableName] = terminal.ChannelId; parameters[TerminalIdVariableName] = terminal.TerminalId; parameters[IncludeImagesVariableName] = request.IncludeImages; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(request.RequestContext, request.QueryResultSettings)) { dataSets = databaseContext.ExecuteStoredProcedure <DeviceConfiguration, HardwareConfiguration, HardwareConfiguration, HardwareConfiguration>(GetDeviceConfigurationSprocName, parameters); } DeviceConfiguration deviceConfiguration = dataSets.Item1.SingleOrDefault(); ReadOnlyCollection <HardwareConfiguration> drawers = dataSets.Item2; ReadOnlyCollection <HardwareConfiguration> printers = dataSets.Item3; ReadOnlyCollection <HardwareConfiguration> pinpads = dataSets.Item4; if (deviceConfiguration != null) { deviceConfiguration.HardwareConfigurations = new HardwareConfigurations(); deviceConfiguration.HardwareConfigurations.CashDrawerConfigurations.AddRange(drawers); deviceConfiguration.HardwareConfigurations.PrinterConfigurations.AddRange(printers); deviceConfiguration.HardwareConfigurations.PinPadConfiguration = pinpads.SingleOrDefault(); } GetDeviceDataRequest getDeviceRequest = new GetDeviceDataRequest(principal.DeviceNumber); Device device = request.RequestContext.Execute <SingleEntityDataServiceResponse <Device> >(getDeviceRequest).Entity; if (deviceConfiguration != null && device != null) { deviceConfiguration.UseInMemoryDeviceDataStorage = device.UseInMemoryDeviceDataStorage; } return(new SingleEntityDataServiceResponse <DeviceConfiguration>(deviceConfiguration)); }
/// <summary> /// Save non sales transaction. /// </summary> /// <param name="request">Non sales transaction data service request.</param> /// <returns>A SingleEntityDataServiceResponse containing the saved NonSalesTransaction object.</returns> private SingleEntityDataServiceResponse <NonSalesTransaction> SaveNonSalesTransaction(SaveNonSalesTransactionDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.NonSalesTransaction, "request.NonSalesTransaction"); var nonSalesTransaction = request.NonSalesTransaction; NonSalesTransaction savedTransaction = null; using (var transactionTable = new DataTable(RetailTransactionTableType)) using (var paymentTable = new DataTable(RetailTransactionPaymentTransTableType)) using (var reasonCodeTable = new DataTable(RetailTransactionInfoCodeTransTableType)) { TransactionLog transaction = this.Convert(nonSalesTransaction); RetailTransactionTableSchema.PopulateSchema(transactionTable); TransactionLogDataManager.FillData(request.RequestContext, transaction, transactionTable); var parameters = new ParameterSet(); parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId; parameters["@tvp_Transaction"] = transactionTable; if (!nonSalesTransaction.TransactionType.Equals(Microsoft.Dynamics.Commerce.Runtime.DataModel.TransactionType.OpenDrawer)) { RetailTransactionPaymentSchema.PopulatePaymentSchema(paymentTable); this.FillPaymentDataTable(nonSalesTransaction.Id, nonSalesTransaction, paymentTable, request.RequestContext); parameters["@tvp_PaymentTrans"] = paymentTable; } else { RetailTransactionPaymentSchema.PopulateReasonCodeSchema(reasonCodeTable); // Populate reason code schema this.FillReasonCodeLines(transaction.Id, nonSalesTransaction, reasonCodeTable, -1m, request.RequestContext); // Fill captured reason code details parameters["@tvp_ReasoncodeLine"] = reasonCodeTable; // Reason code parameter for [Open Drawer] store operation } int errorCode; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { savedTransaction = sqlServerDatabaseContext.ExecuteStoredProcedure <NonSalesTransaction>(InsertNonSaleTenderSprocName, parameters, out errorCode).FirstOrDefault(); } if (errorCode != (int)DatabaseErrorCodes.Success) { throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, errorCode, "Unable to save non sale tender operation."); } } return(new SingleEntityDataServiceResponse <NonSalesTransaction>(savedTransaction)); }
private CustomerExternalIdentityMap GetCustomerAccountByExternalIdentityFromDb(RequestContext requestContext, string externalIdentityId, string externalIdentityIssuer) { CustomerExternalIdentityMap customerExternalIdentityMap; ParameterSet parameters = new ParameterSet(); parameters["@nvc_ExternalIdentityId"] = externalIdentityId; parameters["@nvc_Issuer"] = externalIdentityIssuer; parameters[DataAreaIdVariableName] = requestContext.GetChannelConfiguration().InventLocationDataAreaId; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(requestContext)) { customerExternalIdentityMap = sqlServerDatabaseContext.ExecuteStoredProcedure <CustomerExternalIdentityMap>(GetCustomerByExternalIdentitySprocName, parameters).Results.FirstOrDefault(); } return(customerExternalIdentityMap); }
private EntityDataServiceResponse <AddressFormattingInfo> GetAddressFormatting(GetAddressFormattingDataRequest request) { ThrowIf.Null(request.CountryRegionCode, "countryRegionCode"); ParameterSet parameters = new ParameterSet(); parameters[AddressServiceConstants.CountryRegionId] = request.CountryRegionCode; PagedResult <AddressFormattingInfo> results; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { results = sqlServerDatabaseContext.ExecuteStoredProcedure <AddressFormattingInfo>(GetAddressFormattingInfoSprocName, parameters); } return(new EntityDataServiceResponse <AddressFormattingInfo>(results)); }
private EntityDataServiceResponse <StateProvinceInfo> GetStateProvinces(GetStateProvincesDataRequest request) { ThrowIf.Null(request.QueryResultSettings, "settings"); ThrowIf.Null(request.CountryRegionCode, "countryRegionCode"); ParameterSet filters = new ParameterSet(); filters[AddressServiceConstants.CountryRegionId] = request.CountryRegionCode; PagedResult <StateProvinceInfo> stateProvinces; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { stateProvinces = sqlServerDatabaseContext.ExecuteStoredProcedure <StateProvinceInfo>(GetStateProvincesInfoSprocName, filters); } return(new EntityDataServiceResponse <StateProvinceInfo>(stateProvinces)); }
/// <summary> /// The data service method to get the sales tax group for the given predicates. /// </summary> /// <param name="request">The data service request.</param> /// <returns>The data service response.</returns> private SingleEntityDataServiceResponse <string> GetSalesTaxGroup(GetSalesTaxGroupDataRequest request) { ThrowIf.NullOrEmpty(request.Predicates, "predicates"); var taxDataManager = this.GetDataManagerInstance(request.RequestContext); TaxL2CacheDataStoreAccessor level2CacheDataAccessor = (TaxL2CacheDataStoreAccessor)taxDataManager.DataStoreManagerInstance.RegisteredAccessors[DataStoreType.L2Cache]; bool found; bool updateL2Cache; string result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetSalesTaxGroup(request.Predicates), out found, out updateL2Cache); if (!found) { result = string.Empty; ParameterSet parameters = new ParameterSet(); foreach (var predicate in request.Predicates) { parameters["nvc_" + predicate.Key] = predicate.Value; } SalesTaxGroup group; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(request)) { group = databaseContext.ExecuteStoredProcedure <SalesTaxGroup>(GetTaxRegimeSprocName, parameters).FirstOrDefault(); } if (group != null) { result = group.TaxGroupName; } updateL2Cache &= result != null; } if (updateL2Cache) { level2CacheDataAccessor.PutSalesTaxGroup(request.Predicates, result); } return(new SingleEntityDataServiceResponse <string>(result)); }
private EntityDataServiceResponse <ZipCodeInfo> GetFromZipPostalCodes(GetFromZipPostalCodeDataRequest request) { ThrowIf.Null(request.CountryRegionCode, "countryRegionCode"); ThrowIf.Null(request.ZipPostalCode, "zipPostalCode"); ParameterSet filters = new ParameterSet(); filters[AddressServiceConstants.CountryRegionId] = request.CountryRegionCode; filters[AddressServiceConstants.ZipCode] = request.ZipPostalCode; PagedResult <ZipCodeInfo> fromZipCodes; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { fromZipCodes = sqlServerDatabaseContext.ExecuteStoredProcedure <ZipCodeInfo>(GetFromZipCodesInfoSprocName, filters); } return(new EntityDataServiceResponse <ZipCodeInfo>(fromZipCodes)); }
/// <summary> /// Get shift transactions. /// </summary> /// <param name="request">The get shift transaction counts data request.</param> /// <returns>The Shift collection object.</returns> private SingleEntityDataServiceResponse <Shift> GetShiftTransactionsCounts(GetShiftTransactionsCountDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.TerminalId, "request.TerminalId"); ParameterSet parameters = new ParameterSet(); parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId; parameters[TerminalIdVariableName] = request.TerminalId; parameters[ShiftIdVariableName] = request.ShiftId; Shift shift; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { shift = sqlServerDatabaseContext.ExecuteStoredProcedure <Shift>(GetShiftTransactionsSprocName, parameters).Results.FirstOrDefault(); } return(new SingleEntityDataServiceResponse <Shift>(shift)); }
/// <summary> /// Get tendered amount details of the shift. /// </summary> /// <param name="request">The get shift tendered amount data request.</param> /// <returns>A entity data service response.</returns> private EntityDataServiceResponse <ShiftTenderLine> GetShiftTenderedAmount(GetShiftTenderedAmountDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.TerminalId, "request.TerminalId"); ParameterSet parameters = new ParameterSet(); parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId; parameters[TerminalIdVariableName] = request.TerminalId; parameters[ShiftIdVariableName] = request.ShiftId; PagedResult <ShiftTenderLine> pagedResults; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { pagedResults = sqlServerDatabaseContext.ExecuteStoredProcedure <ShiftTenderLine>(GetShiftTenderedAmountSprocName, parameters); } return(new EntityDataServiceResponse <ShiftTenderLine>(pagedResults)); }
/// <summary> /// Gets affiliations. /// </summary> /// <param name="request">The request with affiliation type and query result settings.</param> /// <returns>The data service response with the collection of affiliations.</returns> public EntityDataServiceResponse <Affiliation> GetAffiliations(GetAffiliationsDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.QueryResultSettings, "settings"); ParameterSet parameters = new ParameterSet(); parameters["@i_affiliationType"] = (int)request.AffiliationType; parameters["@nvc_Locale"] = request.RequestContext.LanguageId; PagedResult <Affiliation> affiliations; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { affiliations = sqlServerDatabaseContext.ExecuteStoredProcedure <Affiliation>(GetAffiliationsByAffiliationTypeSprocName, parameters); } return(new EntityDataServiceResponse <Affiliation>(affiliations)); }
/// <summary> /// Gets the items using the specified item identifiers. /// </summary> /// <param name="context">The request context.</param> /// <param name="itemIds">The list of item identifiers.</param> /// <param name="settings">The query result settings.</param> /// <returns>The collection of items.</returns> private static ReadOnlyCollection <Item> GetItems(RequestContext context, IEnumerable <string> itemIds, QueryResultSettings settings) { ThrowIf.Null(context, "context"); ThrowIf.Null(itemIds, "itemIds"); ThrowIf.Null(settings, "settings"); ItemL2CacheDataStoreAccessor level2CacheDataAccessor = GetCacheAccessor(context); bool found; bool updateL2Cache; ReadOnlyCollection <Item> result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetItems(itemIds, settings), out found, out updateL2Cache); if (!found) { using (StringIdTableType type = new StringIdTableType(itemIds, "ITEMID")) { var parameters = new ParameterSet(); parameters[DatabaseAccessor.ChannelIdVariableName] = context.GetPrincipal().ChannelId; parameters[DatabaseAccessor.ChannelDateVariableName] = context.GetNowInChannelTimeZone().DateTime; parameters[ItemIdsVariableName] = type.DataTable; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(context, settings)) { result = databaseContext.ExecuteStoredProcedure <Item>(GetItemsByItemIdsSprocName, parameters).Results; } } updateL2Cache &= result != null && result.Count < MaxCachedCollectionSize; } if (updateL2Cache) { level2CacheDataAccessor.PutItems(itemIds, settings, result); } return(result); }
/// <summary> /// Gets the Income and expense accounts. /// </summary> /// <param name="request">Get income expense accounts data request.</param> /// <returns>Returns the collection of income expense account.</returns> private EntityDataServiceResponse <IncomeExpenseAccount> GetIncomeExpenseAccounts(GetIncomeExpenseAccountsDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings"); ChannelL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetChannelL2CacheDataStoreAccessor(request.RequestContext); bool found; bool updateL2Cache; PagedResult <IncomeExpenseAccount> result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetIncomeExpenseAccounts(request.IncomeExpenseType, request.QueryResultSettings), out found, out updateL2Cache); if (!found) { string dataAreaId = request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId; string storeNumber = request.RequestContext.GetOrgUnit().OrgUnitNumber; var parameters = new ParameterSet(); parameters["@nvc_StoreId"] = storeNumber; parameters["@nvc_DataAreaId"] = dataAreaId; parameters["@i_AccountType"] = request.IncomeExpenseType; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { result = sqlServerDatabaseContext.ExecuteStoredProcedure <IncomeExpenseAccount>(GetRetailIncomeExpenseAccounts, parameters); } updateL2Cache &= result != null && result.Results.Count < MaxCachedCollectionSize; } if (updateL2Cache) { level2CacheDataAccessor.PutIncomeExpenseAccounts(request.IncomeExpenseType, request.QueryResultSettings, result); } return(new EntityDataServiceResponse <IncomeExpenseAccount>(result)); }
/// <summary> /// Gets inter-state tax group for India. /// </summary> /// <param name="request">The get tax regime India data request.</param> /// <returns>The inter-state tax group.</returns> private SingleEntityDataServiceResponse <string> GetTaxRegimeIndia(GetTaxRegimeIndiaDataRequest request) { ThrowIf.Null(request, "request"); IndiaTaxL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetIndiaTaxL2CacheDataStoreAccessor(request.RequestContext); bool found; bool updateL2Cache; string result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetTaxRegimeIndia(request.QueryResultSettings.ColumnSet), out found, out updateL2Cache); if (!found) { // Input parameters ParameterSet parameters = new ParameterSet(); parameters["@bi_ChannelId"] = request.RequestContext.GetPrincipal().ChannelId; SalesTaxGroup group; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { group = sqlServerDatabaseContext.ExecuteStoredProcedure <SalesTaxGroup>(GetTaxRegimeIndiaName, parameters).SingleOrDefault(); } if (group != null) { result = group.TaxGroupName; } updateL2Cache &= result != null; } if (updateL2Cache) { level2CacheDataAccessor.PutTaxRegimeIndia(request.QueryResultSettings.ColumnSet, result); } return(new SingleEntityDataServiceResponse <string>(result)); }
private EntityDataServiceResponse <DistrictInfo> GetDistricts(GetDistrictsDataRequest request) { ThrowIf.Null(request.QueryResultSettings, "settings"); ThrowIf.Null(request.CountryRegionCode, "countryRegionCode"); ThrowIf.Null(request.StateId, "stateId"); ThrowIf.Null(request.CountyId, "countyId"); ThrowIf.Null(request.City, "city"); ParameterSet filters = new ParameterSet(); filters[AddressServiceConstants.CountryRegionId] = request.CountryRegionCode; filters[AddressServiceConstants.StateProvinceId] = request.StateId; filters[AddressServiceConstants.CountyId] = request.CountyId; filters[AddressServiceConstants.CityComponentName] = request.City; PagedResult <DistrictInfo> districts; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { districts = sqlServerDatabaseContext.ExecuteStoredProcedure <DistrictInfo>(GetDistrictsInfoSprocName, filters); } return(new EntityDataServiceResponse <DistrictInfo>(districts)); }
/// <summary> /// Loads the shift transactions data. /// </summary> /// <param name="request">The request.</param> /// <returns>A single entity data service response.</returns> private SingleEntityDataServiceResponse <Shift> GetEndOfDayshiftDetails(GetEndOfDayShiftDetailsDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.TerminalId, "request.TerminalId"); ParameterSet parameters = new ParameterSet(); parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId; parameters[TerminalIdVariableName] = request.TerminalId; parameters[ShiftIdVariableName] = request.ShiftId; parameters[TaxInclusiveVariableName] = Convert.ToInt32(request.IsTaxInclusive); Shift shift; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { var result = sqlServerDatabaseContext.ExecuteStoredProcedure <Shift, ShiftTenderLine, ShiftAccountLine>(GetShiftSalesDataSprocName, parameters); shift = result.Item1.SingleOrDefault(); shift.TenderLines = result.Item2; shift.AccountLines = result.Item3; } return(new SingleEntityDataServiceResponse <Shift>(shift)); }
/// <summary> /// Save drop and declare transaction. /// </summary> /// <param name="request">Drop and declare transaction data service request.</param> /// <returns>A SingleEntityDataServiceResponse containing the saved DropAndDeclareTransaction object.</returns> private SingleEntityDataServiceResponse <DropAndDeclareTransaction> SaveDropAndDeclareTransaction(SaveDropAndDeclareTransactionDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.DropAndDeclareTransaction, "request.DropAndDeclareTransaction"); DropAndDeclareTransaction dropAndDeclareTransaction = request.DropAndDeclareTransaction; Tuple <PagedResult <DropAndDeclareTransaction>, ReadOnlyCollection <TenderDetail> > results; using (var transactionTable = new DataTable(RetailTransactionTableType)) using (var tenderDeclarationTable = new DataTable(TenderDeclarationTransType)) using (var tenderDropTable = new DataTable(TenderDropTransType)) using (var reasonCodeTable = new DataTable(RetailTransactionInfoCodeTransTableType)) { TransactionLog transaction = this.Convert(dropAndDeclareTransaction); RetailTransactionTableSchema.PopulateSchema(transactionTable); TenderDropAndDeclareTableSchema.PopulateTenderDeclarationSchema(tenderDeclarationTable); TenderDropAndDeclareTableSchema.PopulateBankTenderDropSchema(tenderDropTable); TenderDropAndDeclareTableSchema.PopulateReasonCodeSchema(reasonCodeTable); // Fill the transaction header details. TransactionLogDataManager.FillData(request.RequestContext, transaction, transactionTable); // File the transaction line details. if (dropAndDeclareTransaction.TransactionType == TransactionType.BankDrop || dropAndDeclareTransaction.TransactionType == TransactionType.SafeDrop) { this.FillTenderDataTable(transaction.Id, dropAndDeclareTransaction, tenderDropTable, request.RequestContext); } else if (dropAndDeclareTransaction.TransactionType == TransactionType.TenderDeclaration) { this.FillTenderDataTable(transaction.Id, dropAndDeclareTransaction, tenderDeclarationTable, request.RequestContext); // Fill captured reason code details for [Tender Declaration] store operation this.FillReasonCodeLines(transaction.Id, dropAndDeclareTransaction, reasonCodeTable, -1m, request.RequestContext); } var parameters = new ParameterSet(); parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId; parameters["@tvp_Transaction"] = transactionTable; parameters["@tvp_TenderDeclareTrans"] = tenderDeclarationTable; parameters["@tvp_TenderDropTrans"] = tenderDropTable; parameters["@tvp_ReasoncodeLine"] = reasonCodeTable; int errorCode; using (var sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { results = sqlServerDatabaseContext.ExecuteStoredProcedure <DropAndDeclareTransaction, TenderDetail>(InsertTenderDropAndDeclareSprocName, parameters, null, out errorCode); } if (errorCode != (int)DatabaseErrorCodes.Success) { throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, errorCode, "Unable to save tender drop and declare operation."); } } DropAndDeclareTransaction savedTransaction = results.Item1.FirstOrDefault(); if (savedTransaction == null) { throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, "Unable to retrieve newly created tender drop and declare operation after save."); } savedTransaction.TenderDetails = results.Item2; return(new SingleEntityDataServiceResponse <DropAndDeclareTransaction>(savedTransaction)); }