Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Refactoring - changes in mongodb serialization
KrzysztofPajakc1d0edc7b337
diff --git a/src/Business/Grand.Business.System/Utilities/BestsellersReportLine.cs b/src/Business/Grand.Business.System/Utilities/BestsellersReportLine.csindex 7776b780d..0b0326e16 100644--- a/src/Business/Grand.Business.System/Utilities/BestsellersReportLine.cs+++ b/src/Business/Grand.Business.System/Utilities/BestsellersReportLine.cs@@ -1,5 +1,3 @@-using MongoDB.Bson;-using MongoDB.Bson.Serialization.Attributes;using System;namespace Grand.Business.System.Utilities@@ -18,7 +16,6 @@ namespace Grand.Business.System.Utilities/// <summary>/// Gets or sets the total amount/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal TotalAmount { get; set; }/// <summary>diff --git a/src/Core/Grand.Domain/Catalog/CatalogSettings.cs b/src/Core/Grand.Domain/Catalog/CatalogSettings.csindex e52db7e05..80774bd02 100644--- a/src/Core/Grand.Domain/Catalog/CatalogSettings.cs+++ b/src/Core/Grand.Domain/Catalog/CatalogSettings.cs@@ -1,6 +1,4 @@using Grand.Domain.Configuration;-using MongoDB.Bson.Serialization.Attributes;-using MongoDB.Bson.Serialization.Options;using System.Collections.Generic;namespace Grand.Domain.Catalog@@ -10,7 +8,7 @@ namespace Grand.Domain.Catalogpublic CatalogSettings(){ProductSortingEnumDisabled = new List<int>();- ProductSortingEnumDisplayOrder= new Dictionary<int, int>();+ ProductSortingEnumDisplayOrder = new Dictionary<int, int>();}/// <summary>@@ -101,7 +99,7 @@ namespace Grand.Domain.Catalog/// Gets or sets a value indicating whether category breadcrumb is enabled/// </summary>public bool CategoryBreadcrumbEnabled { get; set; }-+/// <summary>/// Gets or sets a value indicating whether a 'Share button' is enabled/// </summary>@@ -204,7 +202,7 @@ namespace Grand.Domain.Catalog/// Gets or sets a value indicating whether "New products" is show on home page/// </summary>public bool NewProductsOnHomePage { get; set; }-+/// <summary>/// Gets or sets a number of products on the "New products" on home page/// </summary>@@ -245,7 +243,7 @@ namespace Grand.Domain.Catalog/// </summary>public bool ShowProductImagesInSearchAutoComplete { get; set; }-+/// <summary>/// Gets or sets a minimum search term length/// </summary>@@ -255,7 +253,7 @@ namespace Grand.Domain.Catalog/// Gets or sets save search autocomplete/// </summary>public bool SaveSearchAutoComplete { get; set; }-+/// <summary>/// Gets or sets a value indicating whether to show bestsellers on home page/// </summary>@@ -333,17 +331,17 @@ namespace Grand.Domain.Catalog/// Gets or sets a value indicating whether to include "Full description" in compare products/// </summary>public bool IncludeFullDescriptionInCompareProducts { get; set; }-+/// <summary>/// An option indicating whether products on category and collection pages should include featured products as well/// </summary>public bool IncludeFeaturedProductsInNormalLists { get; set; }-+/// <summary>/// Gets or sets a value indicating whether tier prices should be displayed with applied discounts (if available)/// </summary>public bool DisplayTierPricesWithDiscounts { get; set; }-+/// <summary>/// Gets or sets a value indicating whether to ignore discounts (side-wide). It can significantly improve performance when enabled./// </summary>@@ -353,7 +351,7 @@ namespace Grand.Domain.Catalog/// Gets or sets a value indicating whether to ignore featured products (side-wide). It can significantly improve performance when enabled./// </summary>public bool IgnoreFeaturedProducts { get; set; }-+/// <summary>/// Gets or sets a value indicating whether to use customer product prices. It can significantly improve performance when disable./// </summary>@@ -405,7 +403,6 @@ namespace Grand.Domain.Catalog/// <summary>/// Gets or sets a display order of ProductSortingEnum values/// </summary>- [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]public Dictionary<int, int> ProductSortingEnumDisplayOrder { get; set; }/// <summary>diff --git a/src/Core/Grand.Domain/Documents/Document.cs b/src/Core/Grand.Domain/Documents/Document.csindex 39eac21a3..b85da4eca 100644--- a/src/Core/Grand.Domain/Documents/Document.cs+++ b/src/Core/Grand.Domain/Documents/Document.cs@@ -1,8 +1,6 @@using Grand.Domain.Common;using Grand.Domain.Permissions;using Grand.Domain.Stores;-using MongoDB.Bson;-using MongoDB.Bson.Serialization.Attributes;using System;using System.Collections.Generic;@@ -129,13 +127,11 @@ namespace Grand.Domain.Documents/// <summary>/// Gets or sets the total amount/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal TotalAmount { get; set; }/// <summary>/// Gets or sets the outstand amount/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OutstandAmount { get; set; }/// <summary>diff --git a/src/Core/Grand.Domain/MongoDB/MongoDBMapperConfiguration.cs b/src/Core/Grand.Domain/MongoDB/MongoDBMapperConfiguration.csindex 1c2a5fd86..ccef26dbb 100644--- a/src/Core/Grand.Domain/MongoDB/MongoDBMapperConfiguration.cs+++ b/src/Core/Grand.Domain/MongoDB/MongoDBMapperConfiguration.cs@@ -1,8 +1,11 @@-using MongoDB.Bson;+using Grand.Domain.Catalog;+using MongoDB.Bson;using MongoDB.Bson.Serialization;using MongoDB.Bson.Serialization.Conventions;+using MongoDB.Bson.Serialization.Options;using MongoDB.Bson.Serialization.Serializers;using System;+using System.Collections.Generic;namespace Grand.Domain.MongoDB{@@ -14,13 +17,17 @@ namespace Grand.Domain.MongoDB/// </summary>public static void RegisterMongoDBMappings(){- BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128));+ BsonSerializer.RegisterSerializer(new DecimalSerializer(BsonType.Decimal128));BsonSerializer.RegisterSerializer(typeof(decimal?), new NullableSerializer<decimal>(new DecimalSerializer(BsonType.Decimal128)));BsonSerializer.RegisterSerializer(typeof(DateTime), new BsonUtcDateTimeSerializer());+ BsonSerializer.RegisterSerializer(typeof(Dictionary<int, int>),+ new DictionaryInterfaceImplementerSerializer<Dictionary<int, int>>(DictionaryRepresentation.ArrayOfArrays));+//global set an equivalent of [BsonIgnoreExtraElements] for every Domain Model- var cp = new ConventionPack();- cp.Add(new IgnoreExtraElementsConvention(true));+ var cp = new ConventionPack {+ new IgnoreExtraElementsConvention(true)+ };ConventionRegistry.Register("ApplicationConventions", cp, t => true);}diff --git a/src/Core/Grand.Domain/Orders/Order.cs b/src/Core/Grand.Domain/Orders/Order.csindex 235b2b900..35a8ee98f 100644--- a/src/Core/Grand.Domain/Orders/Order.cs+++ b/src/Core/Grand.Domain/Orders/Order.cs@@ -2,8 +2,6 @@ using Grand.Domain.Common;using Grand.Domain.Payments;using Grand.Domain.Shipping;using Grand.Domain.Tax;-using MongoDB.Bson;-using MongoDB.Bson.Serialization.Attributes;using System;using System.Collections.Generic;@@ -95,13 +93,11 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets the currency rate/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal CurrencyRate { get; set; }/// <summary>/// Gets or sets the currency rate/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal Rate { get; set; }/// <summary>@@ -142,73 +138,61 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets the order subtotal (incl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderSubtotalInclTax { get; set; }/// <summary>/// Gets or sets the order subtotal (excl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderSubtotalExclTax { get; set; }/// <summary>/// Gets or sets the order subtotal discount (incl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderSubTotalDiscountInclTax { get; set; }/// <summary>/// Gets or sets the order subtotal discount (excl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderSubTotalDiscountExclTax { get; set; }/// <summary>/// Gets or sets the order shipping (incl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderShippingInclTax { get; set; }/// <summary>/// Gets or sets the order shipping (excl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderShippingExclTax { get; set; }/// <summary>/// Gets or sets the payment method additional fee (incl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal PaymentMethodAdditionalFeeInclTax { get; set; }/// <summary>/// Gets or sets the payment method additional fee (excl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal PaymentMethodAdditionalFeeExclTax { get; set; }/// <summary>/// Gets or sets the order tax/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderTax { get; set; }/// <summary>/// Gets or sets the order discount (applied to order total)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderDiscount { get; set; }/// <summary>/// Gets or sets the order total/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OrderTotal { get; set; }/// <summary>/// Gets or sets the paid amount/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal PaidAmount { get; set; }/// <summary>@@ -219,7 +203,6 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets the refunded amount/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal RefundedAmount { get; set; }/// <summary>@@ -229,7 +212,6 @@ namespace Grand.Domain.Orderspublic int RedeemedLoyaltyPoints { get; set; }- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal RedeemedLoyaltyPointsAmount { get; set; }/// Gets or sets the value indicating for calculated loyalty points@@ -319,8 +301,7 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets order items/// </summary>- public virtual ICollection<OrderItem> OrderItems- {+ public virtual ICollection<OrderItem> OrderItems {get { return _orderItems ??= new List<OrderItem>(); }protected set { _orderItems = value; }}@@ -328,8 +309,7 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets order taxes/// </summary>- public virtual ICollection<OrderTax> OrderTaxes- {+ public virtual ICollection<OrderTax> OrderTaxes {get { return _orderTaxes ??= new List<OrderTax>(); }protected set { _orderTaxes = value; }}@@ -337,8 +317,7 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets the order's tags/// </summary>- public virtual ICollection<string> OrderTags- {+ public virtual ICollection<string> OrderTags {get { return _orderTags ??= new List<string>(); }protected set { _orderTags = value; }}diff --git a/src/Core/Grand.Domain/Orders/OrderItem.cs b/src/Core/Grand.Domain/Orders/OrderItem.csindex 5d6610070..9b57c5abc 100644--- a/src/Core/Grand.Domain/Orders/OrderItem.cs+++ b/src/Core/Grand.Domain/Orders/OrderItem.cs@@ -1,6 +1,4 @@using Grand.Domain.Common;-using MongoDB.Bson;-using MongoDB.Bson.Serialization.Attributes;using System;using System.Collections.Generic;@@ -69,7 +67,6 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets the cancel amount/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal CancelAmount { get; set; }/// <summary>@@ -85,61 +82,51 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets the tax rate/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal TaxRate { get; set; }/// <summary>/// Gets or sets the unit price without discount in primary store currency (incl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal UnitPriceWithoutDiscInclTax { get; set; }/// <summary>/// Gets or sets the unit price without discount in primary store currency (excl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal UnitPriceWithoutDiscExclTax { get; set; }/// <summary>/// Gets or sets the unit price in primary store currency (incl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal UnitPriceInclTax { get; set; }/// <summary>/// Gets or sets the unit price in primary store currency (excl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal UnitPriceExclTax { get; set; }/// <summary>/// Gets or sets the price in primary store currency (incl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal PriceInclTax { get; set; }/// <summary>/// Gets or sets the price in primary store currency (excl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal PriceExclTax { get; set; }/// <summary>/// Gets or sets the discount amount (incl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal DiscountAmountInclTax { get; set; }/// <summary>/// Gets or sets the discount amount (excl tax)/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal DiscountAmountExclTax { get; set; }/// <summary>/// Gets or sets the original cost of this order item (when an order was placed), qty 1/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal OriginalProductCost { get; set; }/// <summary>@@ -167,7 +154,6 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets the total weight of one item/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal? ItemWeight { get; set; }/// <summary>@@ -188,7 +174,6 @@ namespace Grand.Domain.Orders/// <summary>/// Gets or sets the vendor`s commission/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal Commission { get; set; }}diff --git a/src/Core/Grand.Domain/Orders/OrderTax.cs b/src/Core/Grand.Domain/Orders/OrderTax.csindex 971332e60..c034802e7 100644--- a/src/Core/Grand.Domain/Orders/OrderTax.cs+++ b/src/Core/Grand.Domain/Orders/OrderTax.cs@@ -1,14 +1,9 @@-using MongoDB.Bson;-using MongoDB.Bson.Serialization.Attributes;--namespace Grand.Domain.Orders+namespace Grand.Domain.Orders{public class OrderTax : SubBaseEntity{- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal Percent { get; set; }- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal Amount { get; set; }}}diff --git a/src/Core/Grand.Domain/Payments/PaymentTransaction.cs b/src/Core/Grand.Domain/Payments/PaymentTransaction.csindex f7301825f..fa76e8c59 100644--- a/src/Core/Grand.Domain/Payments/PaymentTransaction.cs+++ b/src/Core/Grand.Domain/Payments/PaymentTransaction.cs@@ -1,6 +1,4 @@-using MongoDB.Bson;-using MongoDB.Bson.Serialization.Attributes;-using System;+using System;using System.Collections.Generic;namespace Grand.Domain.Payments@@ -48,22 +46,19 @@ namespace Grand.Domain.Payments/// Gets or sets currency code/// </summary>public string CurrencyCode { get; set; }- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]+public decimal CurrencyRate { get; set; }/// <summary>/// Gets or sets amount/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal TransactionAmount { get; set; }- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal PaidAmount { get; set; }/// <summary>/// Gets or sets the refunded amount/// </summary>- [BsonRepresentation(BsonType.Decimal128, AllowTruncation = true)]public decimal RefundedAmount { get; set; }/// <summary>