public override global::System.Data.DataSet Clone() { PromotionUsageDto cln = ((PromotionUsageDto)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
/// <summary> /// Saves the promotion usage. /// </summary> /// <param name="dto">The dto.</param> public static void SavePromotionUsage(PromotionUsageDto dto) { if (dto == null) { throw new ArgumentNullException("dto", String.Format("PromotionUsageDto can not be null")); } PromotionUsageAdmin admin = new PromotionUsageAdmin(dto); admin.Save(); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { PromotionUsageDto ds = new PromotionUsageDto(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
/// <summary> /// Initializes a new instance of the <see cref="PromotionContext"/> class. /// </summary> /// <param name="context">The context.</param> /// /// <param name="sourceEntries">The source entries.</param> /// <param name="targetEntries">The target entries.</param> public PromotionContext(IDictionary <string, object> context, PromotionEntriesSet sourceEntries, PromotionEntriesSet targetEntries) { _Context = context; _SourceEntriesSet = sourceEntries; _TargetEntriesSet = targetEntries; _ExclusiveGroups = new List <string>(); // Retrieve all the coupons customer entered if (context != null && context.ContainsKey(MarketingContext.ContextConstants.Coupons)) { Coupons = (List <string>)context[MarketingContext.ContextConstants.Coupons]; } else { Coupons = new List <string>(); } // Retrieve customer segments, it should be initialized beforehand if (context != null && context.ContainsKey(MarketingContext.ContextConstants.CustomerSegments)) { Segments = (List <int>)context[MarketingContext.ContextConstants.CustomerSegments]; } else { Segments = new List <int>(); } // Retrieve customer id, it should be initialized beforehand if (context != null && context.ContainsKey(MarketingContext.ContextConstants.CustomerId)) { CustomerId = (Guid)context[MarketingContext.ContextConstants.CustomerId]; } else { CustomerId = Guid.Empty; } // Retrieve promotion usage, it should be initialized beforehand if (context != null && context.ContainsKey(MarketingContext.ContextConstants.PromotionUsage)) { _PromotionUsageDto = (PromotionUsageDto)context[MarketingContext.ContextConstants.PromotionUsage]; } else { _PromotionUsageDto = null; } }
/// <summary> /// Inits the marketing context. /// </summary> private void InitMarketingContext() { OrderGroup group = OrderGroup; _currency = group.BillingCurrency; SetContext(MarketingContext.ContextConstants.ShoppingCart, group); // Set customer segment context var principal = PrincipalInfo.CurrentPrincipal; if (principal != null) { CustomerProfileWrapper profile = GetCurrentUserProfile(); if (profile != null) { SetContext(MarketingContext.ContextConstants.CustomerProfile, profile); var contactId = principal.GetContactId(); var customerContact = CustomerContext.Current.GetContactById(contactId); if (contactId != group.CustomerId) { customerContact = CustomerContext.Current.GetContactById(group.CustomerId); } if (customerContact != null) { SetContext(MarketingContext.ContextConstants.CustomerContact, customerContact); Guid accountId = (Guid)customerContact.PrimaryKeyId; Guid organizationId = Guid.Empty; if (customerContact.ContactOrganization != null) { organizationId = (Guid)customerContact.ContactOrganization.PrimaryKeyId; } SetContext(MarketingContext.ContextConstants.CustomerSegments, MarketingContext.Current.GetCustomerSegments(accountId, organizationId)); } } } // Set customer promotion history context SetContext(MarketingContext.ContextConstants.CustomerId, OrderGroup.CustomerId); // Now load current order usage dto, which will help us determine the usage limits // Load existing usage Dto for the current order PromotionUsageDto usageDto = PromotionManager.GetPromotionUsageDto(0, Guid.Empty, group.OrderGroupId); SetContext(MarketingContext.ContextConstants.PromotionUsage, usageDto); }
/// <summary> /// Gets the promotion usage dto. Results are not cached. /// </summary> /// <param name="promotionId">The promotion id.</param> /// <param name="customerId">The customer id.</param> /// <param name="orderGroupId">The order group id.</param> /// <returns></returns> public static PromotionUsageDto GetPromotionUsageDto(int promotionId, Guid customerId, int orderGroupId) { PromotionUsageDto dto = null; // Load the object if (dto == null) { PromotionUsageAdmin admin = new PromotionUsageAdmin(); admin.Load(promotionId, customerId, orderGroupId); dto = admin.CurrentDto; } dto.AcceptChanges(); return(dto); }
/// <summary> /// Inits the marketing context. /// </summary> private void InitMarketingContext() { OrderGroup group = this.OrderGroup; SetContext(MarketingContext.ContextConstants.ShoppingCart, group); // Set customer segment context MembershipUser user = SecurityContext.Current.CurrentUser; if (user != null) { CustomerProfileWrapper profile = SecurityContext.Current.CurrentUserProfile as CustomerProfileWrapper; if (profile != null) { SetContext(MarketingContext.ContextConstants.CustomerProfile, profile); CustomerContact customerContact = CustomerContext.Current.GetContactForUser(user); if ((Guid)customerContact.PrimaryKeyId != group.CustomerId) { customerContact = CustomerContext.Current.GetContactById(group.CustomerId); } if (customerContact != null) { SetContext(MarketingContext.ContextConstants.CustomerContact, customerContact); Guid accountId = (Guid)customerContact.PrimaryKeyId; Guid organizationId = Guid.Empty; if (customerContact.ContactOrganization != null) { organizationId = (Guid)customerContact.ContactOrganization.PrimaryKeyId; } SetContext(MarketingContext.ContextConstants.CustomerSegments, MarketingContext.Current.GetCustomerSegments(accountId, organizationId)); } } } // Set customer promotion history context SetContext(MarketingContext.ContextConstants.CustomerId, this.OrderGroup.CustomerId); // Now load current order usage dto, which will help us determine the usage limits // Load existing usage Dto for the current order PromotionUsageDto usageDto = PromotionManager.GetPromotionUsageDto(0, Guid.Empty, group.OrderGroupId); SetContext(MarketingContext.ContextConstants.PromotionUsage, usageDto); }
/// <summary> /// Inits the marketing context. /// </summary> private void InitMarketingContext() { OrderGroup group = this.OrderGroup; SetContext(MarketingContext.ContextConstants.ShoppingCart, group); // Set customer segment context MembershipUser user = ProfileContext.Current.User; if (user != null) { CustomerProfile profile = ProfileContext.Current.Profile; if (profile != null) { SetContext(MarketingContext.ContextConstants.CustomerProfile, profile); Account account = profile.Account; if (account != null) { SetContext(MarketingContext.ContextConstants.CustomerAccount, account); Guid accountId = account.PrincipalId; Guid organizationId = Guid.Empty; if (account.Organization != null) { organizationId = account.Organization.PrincipalId; } SetContext(MarketingContext.ContextConstants.CustomerSegments, MarketingContext.Current.GetCustomerSegments(accountId, organizationId)); } } } // Set customer promotion history context SetContext(MarketingContext.ContextConstants.CustomerId, ProfileContext.Current.UserId); // Now load current order usage dto, which will help us determine the usage limits // Load existing usage Dto for the current order PromotionUsageDto usageDto = PromotionManager.GetPromotionUsageDto(0, Guid.Empty, group.OrderGroupId); SetContext(MarketingContext.ContextConstants.PromotionUsage, usageDto); }
/// <summary> /// Deletes the current basket instance from the database. /// </summary> public virtual void Delete() { // Remove any reservations // Load existing usage Dto for the current order PromotionUsageDto usageDto = PromotionManager.GetPromotionUsageDto(0, Guid.Empty, this.Cart.OrderGroupId); // Clear all old items first if (usageDto.PromotionUsage.Count > 0) { foreach (PromotionUsageDto.PromotionUsageRow row in usageDto.PromotionUsage) { row.Delete(); } } // Save the promotion usage PromotionManager.SavePromotionUsage(usageDto); // Delete the cart this.Cart.Delete(); }
/// <summary> /// Initializes a new instance of the <see cref="PromotionUsageAdmin"/> class. /// </summary> /// <param name="dto">The dto.</param> internal PromotionUsageAdmin(PromotionUsageDto dto) { _DataSet = dto; }
/// <summary> /// Initializes a new instance of the <see cref="PromotionAdmin"/> class. /// </summary> internal PromotionUsageAdmin() { _DataSet = new PromotionUsageDto(); }
/// <summary> /// Records the promotions. /// /// Step 1: Load the existing usage that is related to the current order (if any). /// Step 2: Record/update the usage of lineitem, order and shipment level discounts. /// /// The CustomerId can be taken from the Current Order.CustomerId. /// </summary> private void RecordPromotions() { List <Discount> discounts = new List <Discount>(); OrderGroup group = this.OrderGroup; // if the order has been just added, skip recording the discounts if (group.ObjectState == Mediachase.MetaDataPlus.MetaObjectState.Added) { return; } PromotionUsageStatus status = this.UsageStatus; foreach (OrderForm form in group.OrderForms) { // Add order level discounts foreach (Discount discount in form.Discounts) { discounts.Add(discount); } // Add lineitem discounts foreach (LineItem item in form.LineItems) { foreach (Discount discount in item.Discounts) { discounts.Add(discount); } } // Add shipping discounts foreach (Shipment shipment in form.Shipments) { foreach (Discount discount in shipment.Discounts) { discounts.Add(discount); } } } // Load existing usage Dto for the current order PromotionUsageDto usageDto = PromotionManager.GetPromotionUsageDto(0, Guid.Empty, group.OrderGroupId); // Clear all old items first if (usageDto.PromotionUsage.Count > 0) { foreach (PromotionUsageDto.PromotionUsageRow row in usageDto.PromotionUsage) { row.Delete(); } } // Now process the discounts foreach (Discount discount in discounts) { // we only record real discounts that exist in our database if (discount.DiscountId <= 0) { continue; } PromotionUsageDto.PromotionUsageRow row = usageDto.PromotionUsage.NewPromotionUsageRow(); row.CustomerId = group.CustomerId; row.LastUpdated = DateTime.UtcNow; row.OrderGroupId = group.OrderGroupId; row.PromotionId = discount.DiscountId; row.Status = status.GetHashCode(); row.Version = 1; // for now version is always 1 usageDto.PromotionUsage.AddPromotionUsageRow(row); } // Save the promotion usage PromotionManager.SavePromotionUsage(usageDto); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); PromotionUsageDto ds = new PromotionUsageDto(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "PromotionUsageDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }