Sie sind auf Seite 1von 16

// Generated by .

NET Reflector from


C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Dynamics.Commerce.Runtime.DataMana
gers\v4.0_6.3.0.0__31bf3856ad364e35\Microsoft.Dynamics.Commerce.Runtime.DataManagers.dll
namespace Microsoft.Dynamics.Commerce.Runtime.Data
{
using Microsoft.Dynamics.Commerce.Runtime;
using Microsoft.Dynamics.Commerce.Runtime.Data.Types;
using Microsoft.Dynamics.Commerce.Runtime.DataModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;

public sealed class PricingDatabaseAccessor : DatabaseAccessor, IPricingDataManagerV4,


IPricingDataManagerV3, IPricingDataManagerV2, IPricingDataManager
{
private const string AffiliationIdColumn = "AFFILIATIONID";
private const string AffiliationLoyaltyTierTableType = "AFFILIATIONLOYALTYTIERTABLETYPE";
private const string CatalogPriceGroupsViewName = "CATALOGPRICEGROUPSVIEW";
private ChannelDatabaseAccessor channelDatabaseAccessor;
private const string CustomerPriceGroupsViewName = "CUSTOMERPRICEGROUPSVIEW";
private const string DiscountCodeViewName = "DISCOUNTCODEVIEW";
private const string EnablePricingCheckoutCacheColumn = "EnablePricingCheckoutCache";
private const string GetAffiliationLoyaltyTierPriceGroupsSprocName =
"GETAFFILIATIONLOYALTYTIERPRICEGROUPS";
private const string GetAllDiscountTradeAgreementsSprocName =
"GETALLDISCOUNTTRADEAGREEMENTS";
private const string GetAllPriceTradeAgreementsSprocName =
"GETALLPRICETRADEAGREEMENTS";
private const string GetPeriodicDiscountsSprocName = "GETPERIODICDISCOUNTS";
private const string GetPriceAdjustmentsForItemsSprocName =
"GETPRICEADJUSTMENTSFORITEMS";
private const string GetPriceAdjustmentsSprocName = "GETPRICEADJUSTMENTS";
private const string GetRetailDiscountsForItemsSprocName =
"GETRETAILDISCOUNTSFORITEMS";
private const string GetTradeAgreementsSprocName = "GETTRADEAGREEMENTS";
private const string LoyaltyTierIdColumn = "LOYALTYTIERID";
private const string ManualDiscountModeColumn = "ManualDiscountMode";
private const string MixAndMatchLineGroupsViewName =
"RETAILMIXANDMATCHLINEGROUPSVIEW";
private const string MultiBuyDiscountLinesViewName =
"RETAILMULTIBUYDISCOUNTLINESVIEW";
private static readonly DateTime NoDate = new DateTime(0x76c, 1, 1);
private const string PriceGroupsViewName = "PRICEGROUPSVIEW";
private const string PriceParametersViewName = "PRICEPARAMETERSVIEW";
private const string PricingCacheExpirationInMinutesColumn =
"PricingCacheExpirationInMinutes";
private const string PricingItemsViewName = "ITEMSPRICEVIEW";
private const string QuantityDiscountLevelSprocName =
"GETMULTIBUYLINEDISCOUNTBYQUANTITY";
private const string RetailDiscountLinesViewName = "RETAILDISCOUNTLINESVIEW";
private const string RetailDiscountPriceGroupsViewName =
"RETAILDISCOUNTPRICEGROUPSVIEW";
private const string RetailDiscountsViewName = "RETAILDISCOUNTSVIEW";
private const string RetailPricingParametersViewName =
"RETAILPRICINGPARAMETERSVIEW";
private const string ThresholdTiersViewName = "RETAILDISCOUNTTHRESHOLDTIERSVIEW";
private const string ValidationPeriodViewName = "VALIDATIONPERIODVIEW";

private PricingDatabaseAccessor(IDataStore dataStore, RequestContext context) :


base(dataStore, context)
{
this.channelDatabaseAccessor = ChannelDatabaseAccessor.Instantiate(dataStore,
context);
}

public ReadOnlyCollection<PriceAdjustment> FindPriceAdjustments(long productId, long


distinctProductVariantId, IEnumerable<long> priceGroupIds, string currencyCode, string
unitOfMeasure, DateTimeOffset dateToCheck)
{
if (priceGroupIds == null)
{
throw new ArgumentNullException("priceGroupIds");
}
unitOfMeasure = unitOfMeasure ?? string.Empty;
using (RecordIdTableType type = new RecordIdTableType(priceGroupIds))
{
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@bi_ProductId"] = (long) productId;
parameters["@bi_DistinctProductVariantId"] = (long) distinctProductVariantId;
parameters["@tvp_StorePriceGroups"] = type.DataTable;
parameters["@nvc_UnitId"] = unitOfMeasure;
parameters["@nvc_CurrencyCode"] = currencyCode;
parameters["@dt_ActiveDate"] = dateToCheck.get_Date();
return base.ExecuteStoredProcedure<PriceAdjustment>("GETPRICEADJUSTMENTS",
parameters);
}
}

public ReadOnlyCollection<TradeAgreement> FindTradeAgreements(PriceDiscountType


agreementType, PriceDiscountItemCode itemCode, string itemRelation,
PriceDiscountAccountCode accountCode, IEnumerable<string> accountRelations, string unitId,
string currencyCode, decimal quantity, ProductVariant variant, DateTimeOffset activeDate)
{
ThrowIf.Null<IEnumerable<string>>(accountRelations, "accountRelations");
string str = string.Empty;
string str2 = string.Empty;
string str3 = string.Empty;
string str4 = string.Empty;
if (variant != null)
{
str = variant.ColorId ?? string.Empty;
str2 = variant.SizeId ?? string.Empty;
str3 = variant.StyleId ?? string.Empty;
str4 = variant.ConfigId ?? string.Empty;
}
using (DataTable table = new
DataTable("FINDPRICEAGREEMENT_ACCOUNTRELATIONS_TABLETYPE"))
{
table.Columns.Add("ACCOUNTRELATION", typeof(string));
foreach (string str5 in accountRelations)
{
table.Rows.Add(new object[] { str5 });
}
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@Relation"] = agreementType;
parameters["@ItemCode"] = itemCode;
parameters["@ItemRelation"] = itemRelation;
parameters["@AccountCode"] = accountCode;
parameters["@AccountRelations"] = table;
parameters["@UnitId"] = unitId;
parameters["@CurrencyCode"] = currencyCode;
parameters["@Quantity"] = quantity;
parameters["@ColorId"] = str;
parameters["@SizeId"] = str2;
parameters["@StyleId"] = str3;
parameters["@ConfigId"] = str4;
parameters["@ActiveDate"] = activeDate;
return base.ExecuteStoredProcedure<TradeAgreement>("GETTRADEAGREEMENTS",
parameters);
}
}

public ReadOnlyCollection<PriceGroup>
GetAffiliationPriceGroups(IEnumerable<AffiliationLoyaltyTier> affiliationLoyaltyTiers)
{
ThrowIf.Null<IEnumerable<AffiliationLoyaltyTier>>(affiliationLoyaltyTiers,
"affiliationLoyaltyTiers");
using (DataTable table = new DataTable("AFFILIATIONLOYALTYTIERTABLETYPE"))
{
table.Columns.Add("AFFILIATIONID", typeof(long));
table.Columns.Add("LOYALTYTIERID", typeof(long));
foreach (AffiliationLoyaltyTier tier in affiliationLoyaltyTiers)
{
DataRow row = table.NewRow();
row["AFFILIATIONID"] = (long) tier.AffiliationId;
row["LOYALTYTIERID"] = (long) tier.LoyaltyTierId;
table.Rows.Add(row);
}
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@affiliationLoyaltyTiers"] = table;
return
base.ExecuteStoredProcedure<PriceGroup>("GETAFFILIATIONLOYALTYTIERPRICEGROUPS",
parameters);
}
}

public ReadOnlyCollection<DiscountCode> GetAllDiscountCodes()


{
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "DISCOUNTCODEVIEW",
IsQueryByPrimaryKey = false,
Where = "DATAAREAID = @dataAreaId"
};
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<DiscountCode>(query);
}

public ReadOnlyCollection<QuantityDiscountLevel> GetAllQuantityDiscountLevels()


{
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILMULTIBUYDISCOUNTLINESVIEW",
IsQueryByPrimaryKey = false,
Where = "DATAAREAID = @dataAreaId"
};
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<QuantityDiscountLevel>(query);
}

public ReadOnlyCollection<RetailDiscountLine> GetAllRetailDiscountLines()


{
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILDISCOUNTLINESVIEW",
IsQueryByPrimaryKey = false,
Where = "DATAAREAID = @dataAreaId"
};
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<RetailDiscountLine>(query);
}

public ReadOnlyCollection<RetailDiscountPriceGroup> GetAllRetailDiscountPriceGroups()


{
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILDISCOUNTPRICEGROUPSVIEW",
IsQueryByPrimaryKey = false,
Where = "DATAAREAID = @dataAreaId"
};
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<RetailDiscountPriceGroup>(query);
}

public ReadOnlyCollection<RetailDiscount> GetAllRetailDiscounts()


{
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILDISCOUNTSVIEW",
IsQueryByPrimaryKey = false,
Where = "DATAAREAID = @dataAreaId"
};
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<RetailDiscount>(query);
}
public ReadOnlyCollection<ThresholdDiscountTier> GetAllThresholdDiscountTiers()
{
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILDISCOUNTTHRESHOLDTIERSVIEW",
IsQueryByPrimaryKey = false,
Where = "DATAAREAID = @dataAreaId"
};
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<ThresholdDiscountTier>(query);
}

public ReadOnlyCollection<CatalogPriceGroup> GetCatalogPriceGroups(ISet<long>


catalogIds)
{
ThrowIf.Null<ISet<long>>(catalogIds, "catalogIds");
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(new string[] {
CatalogPriceGroup.CatalogIdColumn,
PriceGroup.GroupIdColumn,
PriceGroup.PriceGroupColumn
}),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "CATALOGPRICEGROUPSVIEW",
Where = "CHANNELID = @channelId",
OrderBy = string.Format((IFormatProvider) CultureInfo.get_InvariantCulture(), "{0}.
{1}", new object[] {
"CATALOGPRICEGROUPSVIEW",
PriceGroup.RecordIdColumn
}),
IsQueryByPrimaryKey = false
};
using (RecordIdTableType type = new RecordIdTableType((IEnumerable<long>)
catalogIds, CatalogPriceGroup.CatalogIdColumn))
{
query.Parameters.set_Item("@TVP_RECORDIDTABLETYPE", type);
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
return base.ExecuteSelect<CatalogPriceGroup>(query);
}
}

public PriceGroup GetCustomerPriceGroup(string customerPriceGroupId)


{
ThrowIf.Null<string>(customerPriceGroupId, "customerPriceGroupId");
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
From = "CUSTOMERPRICEGROUPSVIEW",
IsQueryByPrimaryKey = true,
Where = "CHANNELID = @channelId AND GROUPID = @priceGroupId"
};
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
query.Parameters.set_Item("@priceGroupId", customerPriceGroupId);
return (Enumerable.FirstOrDefault<PriceGroup>((IEnumerable<PriceGroup>)
base.ExecuteSelect<PriceGroup>(query)) ?? new PriceGroup());
}
public ReadOnlyCollection<DiscountCode> GetDiscountCodes(string offerId, string
discountCode, string keyword, DateTime activeDate, QueryResultSettings resultSettings)
{
ThrowIf.Null<QueryResultSettings>(resultSettings, "resultSettings");
SqlPagedQuery query = new SqlPagedQuery {
Select = resultSettings.ColumnSet,
Paging = resultSettings.Paging,
From = "DISCOUNTCODEVIEW",
IsQueryByPrimaryKey = false
};
List<string> list = new List<string> { "DATAAREAID = @dataAreaId" };
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
if (activeDate > NoDate)
{
list.Add("(VALIDFROM <= @ActiveDate OR VALIDFROM <= @NoDate) AND (VALIDTO
>= @ActiveDate OR VALIDTO <= @NoDate)");
query.Parameters.set_Item("@ActiveDate", activeDate);
query.Parameters.set_Item("@NoDate", NoDate);
}
if (!string.IsNullOrWhiteSpace(offerId))
{
list.Add("DISCOUNTOFFERID = @OfferId");
query.Parameters.set_Item("@OfferId", offerId);
}
if (!string.IsNullOrWhiteSpace(discountCode))
{
list.Add("DISCOUNTCODE = @DiscountCode");
query.Parameters.set_Item("@DiscountCode", discountCode);
}
if (!string.IsNullOrWhiteSpace(keyword))
{
list.Add("(DISCOUNTOFFERID like @keyword OR NAME like @keyword)");
query.Parameters.set_Item("@keyword", string.Format((IFormatProvider)
CultureInfo.get_InvariantCulture(), "%{0}%", new object[] { keyword }));
}
if (list.get_Count() != 0)
{
query.Where = string.Join(" AND ", (IEnumerable<string>) list);
}
return base.ExecuteSelect<DiscountCode>(query);
}

public ReadOnlyCollection<DiscountCode>
GetDiscountCodesByOfferId(IEnumerable<string> offerIds, ColumnSet columns)
{
ThrowIf.Null<IEnumerable<string>>(offerIds, "offerIds");
ThrowIf.Null<ColumnSet>(columns, "columns");
SqlPagedQuery query = new SqlPagedQuery {
Select = columns,
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "DISCOUNTCODEVIEW",
Where = "DATAAREAID = @dataAreaId",
IsQueryByPrimaryKey = false
};
using (StringIdTableType type = new StringIdTableType(offerIds, "DISCOUNTOFFERID"))
{
query.Parameters.set_Item("@TVP_OFFERIDTABLETYPE", type);
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<DiscountCode>(query);
}
}

public ReadOnlyCollection<Item> GetItems(IEnumerable<string> itemIds)


{
ThrowIf.Null<IEnumerable<string>>(itemIds, "itemIds");
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "ITEMSPRICEVIEW",
Where = "DATAAREAID = @dataAreaId",
IsQueryByPrimaryKey = false
};
using (StringIdTableType type = new StringIdTableType(itemIds, "ITEMID"))
{
query.Parameters.set_Item("@tvp_ItemIds", type);
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<Item>(query);
}
}

public ReadOnlyCollection<MixAndMatchLineGroup>
GetMixAndMatchLineGroupsByOffer(string offerId, QueryResultSettings settings)
{
ThrowIf.NullOrWhiteSpace(offerId, "offerId");
ThrowIf.Null<QueryResultSettings>(settings, "settings");
SqlPagedQuery query = new SqlPagedQuery {
Select = settings.ColumnSet,
Paging = settings.Paging,
From = "RETAILMIXANDMATCHLINEGROUPSVIEW",
Where = "OFFERID = @offerId AND CHANNELID = @channelId",
IsQueryByPrimaryKey = false
};
query.Parameters.set_Item("@offerId", offerId);
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
return base.ExecuteSelect<MixAndMatchLineGroup>(query);
}

public ReadOnlyCollection<MixAndMatchLineGroup>
GetMixAndMatchLineGroupsByOfferIds(IEnumerable<string> offerIds)
{
ThrowIf.Null<IEnumerable<string>>(offerIds, "offerIds");
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILMIXANDMATCHLINEGROUPSVIEW",
Where = "CHANNELID = @channelId",
IsQueryByPrimaryKey = false
};
using (StringIdTableType type = new StringIdTableType(offerIds, "OFFERID"))
{
query.Parameters.set_Item("@TVP_STRINGIDTABLETYPE", type);
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
return base.ExecuteSelect<MixAndMatchLineGroup>(query);
}
}

public ReadOnlyCollection<QuantityDiscountLevel>
GetMultipleBuyDiscountLinesByOfferIds(IEnumerable<string> offerIds)
{
ThrowIf.Null<IEnumerable<string>>(offerIds, "offerIds");
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILMULTIBUYDISCOUNTLINESVIEW",
Where = "DATAAREAID = @dataAreaId",
IsQueryByPrimaryKey = false
};
using (StringIdTableType type = new StringIdTableType(offerIds, "MULTIBUYID"))
{
query.Parameters.set_Item("@TVP_STRINGIDTABLETYPE", type);
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<QuantityDiscountLevel>(query);
}
}

public ReadOnlyCollection<PeriodicDiscount> GetPeriodicDiscounts(long productId, long


variantId, IEnumerable<long> priceGroupIds, string currencyCode, DateTimeOffset activeDate)
{
ThrowIf.Null<IEnumerable<long>>(priceGroupIds, "priceGroupIds");
using (RecordIdTableType type = new RecordIdTableType(priceGroupIds))
{
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@bi_ProductId"] = (long) productId;
parameters["@bi_DistinctProductVariantId"] = (long) variantId;
parameters["@tvp_StorePriceGroups"] = type.DataTable;
parameters["@nvc_CurrencyCode"] = currencyCode;
parameters["@dt_ActiveDate"] = activeDate;
return base.ExecuteStoredProcedure<PeriodicDiscount>("GETPERIODICDISCOUNTS",
parameters);
}
}

public ReadOnlyCollection<PriceGroup> GetPriceGroups(QueryResultSettings settings)


{
ThrowIf.Null<QueryResultSettings>(settings, "settings");
SqlPagedQuery query = new SqlPagedQuery {
Select = settings.ColumnSet,
Paging = settings.Paging,
From = "PRICEGROUPSVIEW",
IsQueryByPrimaryKey = false,
Where = "CHANNELID = @channelId"
};
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
return base.ExecuteSelect<PriceGroup>(query);
}

public PriceParameters GetPriceParameters(ColumnSet columns)


{
ThrowIf.Null<ColumnSet>(columns, "columns");
SqlPagedQuery query = new SqlPagedQuery {
Select = columns,
From = "PRICEPARAMETERSVIEW",
Where = "CHANNELID = @channelId",
IsQueryByPrimaryKey = true
};
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
return (Enumerable.FirstOrDefault<PriceParameters>((IEnumerable<PriceParameters>)
base.ExecuteSelect<PriceParameters>(query)) ?? new PriceParameters());
}

public QuantityDiscountLevel GetQuantityDiscountLevelByQuantity(string offerId, decimal


quantity)
{
ThrowIf.NullOrWhiteSpace(offerId, "offerId");
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@OfferId"] = offerId;
parameters["@Quantity"] = quantity;
return
Enumerable.FirstOrDefault<QuantityDiscountLevel>((IEnumerable<QuantityDiscountLevel>)
base.ExecuteStoredProcedure<QuantityDiscountLevel>("GETMULTIBUYLINEDISCOUNTBYQUANTIT
Y", parameters));
}

public ReadOnlyCollection<RetailCategoryMember>
GetRetailCategoryMembersForItems(ISet<long> productOrVariantIds)
{
throw new NotImplementedException("unauthorized direct call to a data store accessor");
}

public ReadOnlyCollection<RetailDiscountPriceGroup>
GetRetailDiscountPriceGroups(ISet<string> offerIds)
{
ThrowIf.Null<ISet<string>>(offerIds, "offerIds");
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILDISCOUNTPRICEGROUPSVIEW",
Where = "DATAAREAID = @dataAreaId",
IsQueryByPrimaryKey = false
};
using (StringIdTableType type = new StringIdTableType((IEnumerable<string>) offerIds,
RetailDiscountPriceGroup.OfferIdColumn))
{
query.Parameters.set_Item("@TVP_STRINGIDTABLETYPE", type);
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<RetailDiscountPriceGroup>(query);
}
}

public ReadOnlyCollection<ThresholdDiscountTier>
GetThresholdTiersByOfferIds(IEnumerable<string> offerIds)
{
ThrowIf.Null<IEnumerable<string>>(offerIds, "offerIds");
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "RETAILDISCOUNTTHRESHOLDTIERSVIEW",
Where = "DATAAREAID = @dataAreaId",
IsQueryByPrimaryKey = false
};
using (StringIdTableType type = new StringIdTableType(offerIds, "OFFERID"))
{
query.Parameters.set_Item("@TVP_STRINGIDTABLETYPE", type);
query.Parameters.set_Item("@dataAreaId",
base.Context.GetChannelConfiguration().InventLocationDataAreaId);
return base.ExecuteSelect<ThresholdDiscountTier>(query);
}
}

public ValidationPeriod GetValidationPeriodById(string periodId, ColumnSet columns)


{
ThrowIf.NullOrWhiteSpace(periodId, "periodId");
ThrowIf.Null<ColumnSet>(columns, "columns");
SqlPagedQuery query = new SqlPagedQuery {
Select = columns,
From = "VALIDATIONPERIODVIEW",
Where = "PERIODID = @periodId AND CHANNELID = @channelId",
IsQueryByPrimaryKey = true
};
query.Parameters.set_Item("@periodId", periodId);
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
return Enumerable.FirstOrDefault<ValidationPeriod>((IEnumerable<ValidationPeriod>)
base.ExecuteSelect<ValidationPeriod>(query));
}

public ReadOnlyCollection<ValidationPeriod>
GetValidationPeriodsByIds(IEnumerable<string> periodIds, ColumnSet columns)
{
ThrowIf.Null<IEnumerable<string>>(periodIds, "periodIds");
ThrowIf.Null<ColumnSet>(columns, "columns");
SqlPagedQuery query = new SqlPagedQuery {
Select = columns,
Paging = new PagingInfo(PagingInfo.MaximumPageSize, 0),
From = "VALIDATIONPERIODVIEW",
Where = "CHANNELID = @channelId",
IsQueryByPrimaryKey = false
};
using (StringIdTableType type = new StringIdTableType(periodIds, "PERIODID"))
{
query.Parameters.set_Item("@TVP_STRINGIDTABLETYPE", type);
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
return base.ExecuteSelect<ValidationPeriod>(query);
}
}

public ProductVariant GetVariantByItemIdAndInventDimId(string itemId, string inventDimId,


ColumnSet columnSet)
{
throw new NotImplementedException("unauthorized direct call to a data store accessor");
}
public ReadOnlyCollection<ProductVariant>
GetVariantDimensionsByItemIds(IEnumerable<string> inventoryDimensionIds)
{
throw new NotImplementedException("unauthorized direct call to a data store accessor");
}

public ReadOnlyCollection<ProductVariant>
GetVariants(IEnumerable<ItemVariantInventoryDimension> itemVariants, ColumnSet columnSet)
{
throw new NotImplementedException("unauthorized direct call to a data store accessor");
}

internal static PricingDatabaseAccessor Instantiate(IDataStore dataStore, RequestContext


context)
{
return new PricingDatabaseAccessor(dataStore, context);
}

public ReadOnlyCollection<TradeAgreement> ReadDiscountTradeAgreements(ISet<string>


itemIds, string customerAccount, DateTimeOffset minActiveDate, DateTimeOffset maxActiveDate,
string currencyCode)
{
ThrowIf.Null<ISet<string>>(itemIds, "itemIds");
if (minActiveDate > maxActiveDate)
{
throw new ArgumentException("minActiveDate must be less than or equal to
maxActiveDate.");
}
using (DataTable table = new DataTable("STRINGIDTABLETYPE"))
{
table.Columns.Add("STRINGID", typeof(string));
foreach (string str in itemIds)
{
table.Rows.Add(new object[] { str });
}
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@ItemIds"] = table;
parameters["@Customer"] = customerAccount ?? string.Empty;
parameters["@MinDate"] = minActiveDate.get_Date();
parameters["@MaxDate"] = maxActiveDate.get_Date();
parameters["@nvc_CurrencyCode"] = currencyCode;
return
base.ExecuteStoredProcedure<TradeAgreement>("GETALLDISCOUNTTRADEAGREEMENTS",
parameters);
}
}

public ReadOnlyCollection<TradeAgreement> ReadDiscountTradeAgreements(ISet<string>


itemIds, string customerAccount, string lineDiscGroup, string multilineDiscountGroup, string
totalDiscountGroup, DateTimeOffset minActiveDate, DateTimeOffset maxActiveDate, string
currencyCode)
{
return this.ReadDiscountTradeAgreements(itemIds, customerAccount, minActiveDate,
maxActiveDate, currencyCode);
}
public ReadOnlyCollection<PriceAdjustment>
ReadPriceAdjustments(IEnumerable<ItemUnit> items, ISet<string> priceGroups, DateTimeOffset
minActiveDate, DateTimeOffset maxActiveDate, out ReadOnlyCollection<ValidationPeriod>
validationPeriods)
{
ReadOnlyCollection<PriceAdjustment> onlys2;
ThrowIf.Null<IEnumerable<ItemUnit>>(items, "items");
ThrowIf.Null<ISet<string>>(priceGroups, "priceGroups");
if (minActiveDate > maxActiveDate)
{
throw new ArgumentException("minActiveDate must be less than or equal to
maxActiveDate.");
}
using (DataTable table = new DataTable("ITEMVARIANTINVENTDIMTABLETYPE"))
{
using (DataTable table2 = new DataTable("PRICEGROUPTABLETYPE"))
{
table.Columns.Add("ITEMID", typeof(string)).DefaultValue = string.Empty;
table.Columns.Add("VARIANTINVENTDIMID", typeof(string)).DefaultValue =
string.Empty;
foreach (ItemUnit unit in items)
{
DataRow row = table.NewRow();
row["ITEMID"] = unit.ItemId;
row["VARIANTINVENTDIMID"] = unit.VariantInventoryDimensionId;
table.Rows.Add(row);
}
table2.Columns.Add("RECID", typeof(long)).DefaultValue = 0;
table2.Columns.Add("PRICEGROUP", typeof(long)).DefaultValue = 0;
table2.Columns.Add("GROUPID", typeof(string)).DefaultValue = string.Empty;
foreach (string str in priceGroups)
{
table2.Rows.Add(new object[] { (int) 0, (int) 0, str });
}
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@items"] = table;
parameters["@priceGroups"] = table2;
parameters["@fromDate"] = minActiveDate;
parameters["@toDate"] = maxActiveDate;
ReadOnlyCollection<PriceAdjustment> onlys =
base.ExecuteStoredProcedure<PriceAdjustment>("GETPRICEADJUSTMENTSFORITEMS",
parameters);
IEnumerable<string> periodIds =
Enumerable.Distinct<string>(Enumerable.Select<PriceAdjustment, string>(from p in
(IEnumerable<PriceAdjustment>) onlys select p, delegate (PriceAdjustment p) {
return p.ValidationPeriodId;
}));
if (Enumerable.Any<string>(periodIds))
{
validationPeriods = this.GetValidationPeriodsByIds(periodIds, new ColumnSet());
}
else
{
validationPeriods = new ReadOnlyCollection<ValidationPeriod>(new
ValidationPeriod[0]);
}
onlys2 = onlys;
}
}
return onlys2;
}

public ReadOnlyCollection<TradeAgreement> ReadPriceTradeAgreements(ISet<string>


itemIds, ISet<string> priceGroups, string customerAccount, DateTimeOffset minActiveDate,
DateTimeOffset maxActiveDate, string currencyCode)
{
ReadOnlyCollection<TradeAgreement> onlys2;
ThrowIf.Null<ISet<string>>(itemIds, "itemIds");
ThrowIf.Null<ISet<string>>(priceGroups, "priceGroups");
if (minActiveDate > maxActiveDate)
{
throw new ArgumentException("minActiveDate must be less than or equal to
maxActiveDate.");
}
using (DataTable table = new DataTable("PRICEACCOUNTRELATIONSTABLETYPE"))
{
using (DataTable table2 = new DataTable("STRINGIDTABLETYPE"))
{
table.Columns.Add("ACCOUNTRELATION", typeof(string));
foreach (string str in priceGroups)
{
table.Rows.Add(new object[] { str });
}
table2.Columns.Add("STRINGID", typeof(string));
foreach (string str2 in itemIds)
{
table2.Rows.Add(new object[] { str2 });
}
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@PriceGroups"] = table;
parameters["@ItemIds"] = table2;
parameters["@Customer"] = customerAccount ?? string.Empty;
parameters["@MinDate"] = minActiveDate.get_Date();
parameters["@MaxDate"] = maxActiveDate.get_Date();
parameters["@nvc_CurrencyCode"] = currencyCode;
onlys2 =
base.ExecuteStoredProcedure<TradeAgreement>("GETALLPRICETRADEAGREEMENTS",
parameters);
}
}
return onlys2;
}

public ReadOnlyCollection<PeriodicDiscount> ReadRetailDiscounts(IEnumerable<ItemUnit>


items, ISet<string> priceGroups, DateTimeOffset minActiveDate, DateTimeOffset maxActiveDate,
string currencyCode, out ReadOnlyCollection<ValidationPeriod> validationPeriods)
{
ReadOnlyCollection<PeriodicDiscount> onlys2;
ThrowIf.Null<IEnumerable<ItemUnit>>(items, "items");
ThrowIf.Null<ISet<string>>(priceGroups, "priceGroups");
ThrowIf.Null<string>(currencyCode, "currencyCode");
using (DataTable table = new DataTable("ITEMVARIANTINVENTDIMTABLETYPE"))
{
using (DataTable table2 = new DataTable("PRICEGROUPTABLETYPE"))
{
table.Columns.Add("ITEMID", typeof(string)).DefaultValue = string.Empty;
table.Columns.Add("VARIANTINVENTDIMID", typeof(string)).DefaultValue =
string.Empty;
HashSet<string> set = new HashSet<string>((IEqualityComparer<string>)
StringComparer.get_OrdinalIgnoreCase());
foreach (ItemUnit unit in items)
{
string str = string.Format("{0}.{1}", new object[] { unit.ItemId,
unit.VariantInventoryDimensionId ?? string.Empty });
if (!set.Contains(str))
{
set.Add(str);
DataRow row = table.NewRow();
row["ITEMID"] = unit.ItemId;
row["VARIANTINVENTDIMID"] = unit.VariantInventoryDimensionId ??
string.Empty;
table.Rows.Add(row);
}
}
table2.Columns.Add("RECID", typeof(long)).DefaultValue = 0;
table2.Columns.Add("PRICEGROUP", typeof(long)).DefaultValue = 0;
table2.Columns.Add("GROUPID", typeof(string)).DefaultValue = string.Empty;
foreach (string str2 in priceGroups)
{
table2.Rows.Add(new object[] { (int) 0, (int) 0, str2 });
}
ParameterSet parameters = new ParameterSet();
parameters["@bi_ChannelId"] = (long) base.ChannelId;
parameters["@items"] = table;
parameters["@priceGroups"] = table2;
parameters["@MinDate"] = minActiveDate.get_Date();
parameters["@MaxDate"] = maxActiveDate.get_Date();
parameters["@nvc_CurrencyCode"] = currencyCode;
ReadOnlyCollection<PeriodicDiscount> onlys =
base.ExecuteStoredProcedure<PeriodicDiscount>("GETRETAILDISCOUNTSFORITEMS",
parameters);
IEnumerable<string> periodIds =
Enumerable.Distinct<string>(Enumerable.Select<PeriodicDiscount, string>(from p in
(IEnumerable<PeriodicDiscount>) onlys select p, delegate (PeriodicDiscount p) {
return p.ValidationPeriodId;
}));
if (Enumerable.Any<string>(periodIds))
{
validationPeriods = this.GetValidationPeriodsByIds(periodIds, new ColumnSet());
}
else
{
validationPeriods = new ReadOnlyCollection<ValidationPeriod>(new
ValidationPeriod[0]);
}
onlys2 = onlys;
}
}
return onlys2;
}
public Microsoft.Dynamics.Commerce.Runtime.DataModel.ChannelPriceConfiguration
ChannelPriceConfiguration
{
get
{
SqlPagedQuery query = new SqlPagedQuery {
Select = new ColumnSet(),
From = "RETAILPRICINGPARAMETERSVIEW",
Where = "CHANNELID = @channelId",
IsQueryByPrimaryKey = true
};
query.Parameters.set_Item("@channelId", (long) base.ChannelId);
Microsoft.Dynamics.Commerce.Runtime.DataModel.ChannelPriceConfiguration
configuration =
Enumerable.FirstOrDefault<Microsoft.Dynamics.Commerce.Runtime.DataModel.ChannelPriceCon
figuration>((IEnumerable<Microsoft.Dynamics.Commerce.Runtime.DataModel.ChannelPriceConfi
guration>)
base.ExecuteSelect<Microsoft.Dynamics.Commerce.Runtime.DataModel.ChannelPriceConfigurati
on>(query));
if (configuration == null)
{
configuration = new
Microsoft.Dynamics.Commerce.Runtime.DataModel.ChannelPriceConfiguration();
}
configuration.Company =
base.Context.GetChannelConfiguration().InventLocationDataAreaId;
configuration.CompanyCurrency =
base.Context.GetChannelConfiguration().CompanyCurrency;
configuration.ChannelTimeZoneId =
base.Context.GetChannelConfiguration().TimeZoneInfoId;
ManualDiscountMode add = ManualDiscountMode.Add;
bool flag = false;
int num = 0;
try
{
foreach (RetailConfigurationParameter parameter in
this.channelDatabaseAccessor.GetRetailConfigurationParameters())
{
if (string.Equals("ManualDiscountMode", parameter.Name, (StringComparison)
StringComparison.OrdinalIgnoreCase))
{
int num2;
if (int.TryParse(parameter.Value, ref num2))
{
add = (ManualDiscountMode) num2;
}
}
else if (string.Equals("EnablePricingCheckoutCache", parameter.Name,
(StringComparison) StringComparison.OrdinalIgnoreCase))
{
int num3;
if (int.TryParse(parameter.Value, ref num3))
{
flag = num3 == 1;
}
}
else if (string.Equals("PricingCacheExpirationInMinutes", parameter.Name,
(StringComparison) StringComparison.OrdinalIgnoreCase))
{
int.TryParse(parameter.Value, ref num);
}
}
}
catch
{
}
configuration.ManualDiscountMode = add;
configuration.EnablePricingCheckoutCache = flag;
configuration.PricingCheckoutCacheExpirationInMinutes = num;
return configuration;
}
}
}
}

Das könnte Ihnen auch gefallen