Skip to content

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.

Further improvements with captcha validator + add new converter InterfaceConverter / add new JsonConverterAttribute

support5337d7ed796a
diff --git a/src/Core/Grand.Infrastructure/ModelBinding/JsonBodyModelBinder.cs b/src/Core/Grand.Infrastructure/ModelBinding/JsonBodyModelBinder.cs
index 68b29a3c2..5aa5a154a 100644
--- a/src/Core/Grand.Infrastructure/ModelBinding/JsonBodyModelBinder.cs
+++ b/src/Core/Grand.Infrastructure/ModelBinding/JsonBodyModelBinder.cs
@@ -35,9 +35,9 @@ public class JsonBodyModelBinder : IModelBinder
bindingContext.Result =
ModelBindingResult.Success(JsonSerializer.Deserialize(jsonPayload, bindingContext.ModelType, options));
}
- catch(Exception)
+ catch(Exception ex)
{
- bindingContext.Result = ModelBindingResult.Success(Activator.CreateInstance(bindingContext.ModelType));
+ throw ex;
}
}
else
diff --git a/src/Web/Grand.Web/Models/Common/CaptchaModel.cs b/src/Core/Grand.Infrastructure/Models/CaptchaModel.cs
similarity index 78%
rename from src/Web/Grand.Web/Models/Common/CaptchaModel.cs
rename to src/Core/Grand.Infrastructure/Models/CaptchaModel.cs
index d062ea39d..8733b22d9 100644
--- a/src/Web/Grand.Web/Models/Common/CaptchaModel.cs
+++ b/src/Core/Grand.Infrastructure/Models/CaptchaModel.cs
@@ -1,6 +1,4 @@
-using Grand.Infrastructure.Models;
-
-namespace Grand.Web.Models.Common;
+namespace Grand.Infrastructure.Models;
public record CaptchaModel : ICaptchaValidModel
{
diff --git a/src/Core/Grand.Infrastructure/Models/ICaptchaValidModel.cs b/src/Core/Grand.Infrastructure/Models/ICaptchaValidModel.cs
index c1c6b3c93..ed30e5471 100644
--- a/src/Core/Grand.Infrastructure/Models/ICaptchaValidModel.cs
+++ b/src/Core/Grand.Infrastructure/Models/ICaptchaValidModel.cs
@@ -1,13 +1,13 @@
-namespace Grand.Infrastructure.Models;
+using Grand.Infrastructure.TypeConverters.JsonConverters;
+using Grand.SharedKernel.Attributes;
+namespace Grand.Infrastructure.Models;
+
+[InterfaceConverter(typeof(InterfaceConverter<ICaptchaValidModel, CaptchaModel>))]
public interface ICaptchaValidModel
{
-
public string ReCaptchaChallengeField { get; set; }
-
public string ReCaptchaResponseField { get; set; }
-
public string ReCaptchaResponseValue { get; set; }
-
public string ReCaptchaResponse { get; set; }
}
diff --git a/src/Core/Grand.Infrastructure/TypeConverters/JsonConverters/InterfaceConverter.cs b/src/Core/Grand.Infrastructure/TypeConverters/JsonConverters/InterfaceConverter.cs
new file mode 100644
index 000000000..c5c2a35b4
--- /dev/null
+++ b/src/Core/Grand.Infrastructure/TypeConverters/JsonConverters/InterfaceConverter.cs
@@ -0,0 +1,63 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace Grand.Infrastructure.TypeConverters.JsonConverters;
+
+public class InterfaceConverter<TInterface, TConcrete> : JsonConverter<TInterface> where TConcrete : TInterface, new()
+{
+ public override TInterface Read(
+ ref Utf8JsonReader reader,
+ Type typeToConvert,
+ JsonSerializerOptions options)
+ {
+ return JsonSerializer.Deserialize<TConcrete>(ref reader, options);
+ }
+ public override void Write(
+ Utf8JsonWriter writer,
+ TInterface value,
+ JsonSerializerOptions options)
+ {
+ switch (value)
+ {
+ case null:
+ JsonSerializer.Serialize(writer, null, options);
+ break;
+ default:
+ {
+ var type = value.GetType();
+ JsonSerializer.Serialize(writer, value, type, options);
+ break;
+ }
+ }
+ }
+}
+/*
+public class CaptchaConverter : JsonConverter<ICaptchaValidModel>
+{
+ public override ICaptchaValidModel Read(
+ ref Utf8JsonReader reader,
+ Type typeToConvert,
+ JsonSerializerOptions options)
+ {
+ return JsonSerializer.Deserialize<CaptchaModel>(ref reader, options);
+ }
+ public override void Write(
+ Utf8JsonWriter writer,
+ ICaptchaValidModel value,
+ JsonSerializerOptions options)
+ {
+ switch (value)
+ {
+ case null:
+ JsonSerializer.Serialize(writer, (ICaptchaValidModel) null, options);
+ break;
+ default:
+ {
+ var type = value.GetType();
+ JsonSerializer.Serialize(writer, value, type, options);
+ break;
+ }
+ }
+ }
+}
+*/
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/Attributes/InterfaceConverterAttribute.cs b/src/Core/Grand.SharedKernel/Attributes/InterfaceConverterAttribute.cs
new file mode 100644
index 000000000..56ca2a7eb
--- /dev/null
+++ b/src/Core/Grand.SharedKernel/Attributes/InterfaceConverterAttribute.cs
@@ -0,0 +1,12 @@
+using System.Text.Json.Serialization;
+
+namespace Grand.SharedKernel.Attributes;
+
+[AttributeUsage(AttributeTargets.Interface)]
+public class InterfaceConverterAttribute : JsonConverterAttribute
+{
+ public InterfaceConverterAttribute(Type converterType)
+ : base(converterType)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Infrastructure.Tests/TypeConverters/Converter/CaptchaInterfaceConverter.cs b/src/Tests/Grand.Infrastructure.Tests/TypeConverters/Converter/CaptchaInterfaceConverter.cs
new file mode 100644
index 000000000..98b762110
--- /dev/null
+++ b/src/Tests/Grand.Infrastructure.Tests/TypeConverters/Converter/CaptchaInterfaceConverter.cs
@@ -0,0 +1,81 @@
+using Grand.Infrastructure.Models;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Text.Json;
+
+namespace Grand.Infrastructure.TypeConverters.Converter.Tests;
+
+[TestClass()]
+public class CaptchaInterfaceConverter
+{
+ [TestMethod()]
+ public void ConvertFrom_CaptchaObject_To_Json()
+ {
+ //Arrange
+ var sample = new SampleClass();
+ sample.CaptchaValidModel = new CaptchaModel() {
+ ReCaptchaResponse = "xxx",
+ ReCaptchaResponseField = "yyy",
+ ReCaptchaChallengeField = "zzz",
+ ReCaptchaResponseValue = "uuu"
+ };
+ //Act
+ var jsonString = JsonSerializer.Serialize(sample);
+ //Assert
+ var expJson = "{\"CaptchaValidModel\":{\"ReCaptchaChallengeField\":\"zzz\",\"ReCaptchaResponseField\":\"yyy\",\"ReCaptchaResponseValue\":\"uuu\",\"ReCaptchaResponse\":\"xxx\"}}";
+
+ Assert.AreEqual(expJson, jsonString);
+ }
+ [TestMethod()]
+ public void ConvertFrom_CaptchaNullObject_To_Json()
+ {
+ //Arrange
+ var sample = new SampleClass();
+ //Act
+ var jsonString = JsonSerializer.Serialize(sample);
+ //Assert
+ var expJson = "{\"CaptchaValidModel\":{\"ReCaptchaChallengeField\":null,\"ReCaptchaResponseField\":null,\"ReCaptchaResponseValue\":null,\"ReCaptchaResponse\":null}}";
+ Assert.AreEqual(expJson, jsonString);
+
+ }
+
+ [TestMethod()]
+ public void ConvertFrom_Json_To_CaptchaObject()
+ {
+ //Arrange
+ var json = "{\"CaptchaValidModel\":{\"ReCaptchaChallengeField\":\"zzz\",\"ReCaptchaResponseField\":\"yyy\",\"ReCaptchaResponseValue\":\"uuu\",\"ReCaptchaResponse\":\"xxx\"}}";
+
+ //Act
+ var sample = JsonSerializer.Deserialize<SampleClass>(json);
+ //Assert
+ Assert.IsNotNull(sample);
+ Assert.AreEqual("zzz",sample.CaptchaValidModel.ReCaptchaChallengeField);
+ Assert.AreEqual("yyy",sample.CaptchaValidModel.ReCaptchaResponseField);
+ Assert.AreEqual("uuu",sample.CaptchaValidModel.ReCaptchaResponseValue);
+ Assert.AreEqual("xxx",sample.CaptchaValidModel.ReCaptchaResponse);
+ }
+ [TestMethod()]
+ public void ConvertFrom_JsonEmptyCaptcha_To_CaptchaObject()
+ {
+ //Arrange
+ var json = "{}";
+
+ //Act
+ var sample = JsonSerializer.Deserialize<SampleClass>(json);
+ //Assert
+ Assert.IsNotNull(sample);
+ Assert.IsNull(sample.CaptchaValidModel.ReCaptchaChallengeField);
+ Assert.IsNull(sample.CaptchaValidModel.ReCaptchaResponseField);
+ Assert.IsNull(sample.CaptchaValidModel.ReCaptchaResponseValue);
+ Assert.IsNull(sample.CaptchaValidModel.ReCaptchaResponse);
+ }
+
+ public class SampleClass
+ {
+ public SampleClass()
+ {
+ CaptchaValidModel = new CaptchaModel();
+ }
+
+ public ICaptchaValidModel CaptchaValidModel { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Models/Common/CaptchaModel.cs b/src/Web/Grand.Web.Admin/Models/Common/CaptchaModel.cs
deleted file mode 100644
index 658ff6e76..000000000
--- a/src/Web/Grand.Web.Admin/Models/Common/CaptchaModel.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Grand.Infrastructure.Models;
-
-namespace Grand.Web.Admin.Models.Common;
-
-public record CaptchaModel : ICaptchaValidModel
-{
- public string ReCaptchaChallengeField { get; set; }
- public string ReCaptchaResponseField { get; set; }
- public string ReCaptchaResponseValue { get; set; }
- public string ReCaptchaResponse { get; set; }
-}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Models/Common/LoginModel.cs b/src/Web/Grand.Web.Admin/Models/Common/LoginModel.cs
index 19dc0e485..3707c1da4 100644
--- a/src/Web/Grand.Web.Admin/Models/Common/LoginModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Common/LoginModel.cs
@@ -6,7 +6,10 @@ namespace Grand.Web.Admin.Models.Common
{
public partial class LoginModel : BaseModel
{
-
+ public LoginModel()
+ {
+ Captcha = new CaptchaModel();
+ }
[DataType(DataType.EmailAddress)]
[GrandResourceDisplayName("Account.Login.Fields.Email")]
public string Email { get; set; }
@@ -23,6 +26,6 @@ namespace Grand.Web.Admin.Models.Common
public bool RememberMe { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Blogs/AddBlogCommentModel.cs b/src/Web/Grand.Web/Models/Blogs/AddBlogCommentModel.cs
index 91926d1a3..183ef5e60 100644
--- a/src/Web/Grand.Web/Models/Blogs/AddBlogCommentModel.cs
+++ b/src/Web/Grand.Web/Models/Blogs/AddBlogCommentModel.cs
@@ -1,16 +1,19 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
namespace Grand.Web.Models.Blogs
{
public class AddBlogCommentModel : BaseEntityModel
{
+ public AddBlogCommentModel()
+ {
+ Captcha = new CaptchaModel();
+ }
[GrandResourceDisplayName("Blog.Comments.CommentText")]
public string CommentText { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Catalog/ProductAskQuestionSimpleModel.cs b/src/Web/Grand.Web/Models/Catalog/ProductAskQuestionSimpleModel.cs
index fe6aca608..98b46f95b 100644
--- a/src/Web/Grand.Web/Models/Catalog/ProductAskQuestionSimpleModel.cs
+++ b/src/Web/Grand.Web/Models/Catalog/ProductAskQuestionSimpleModel.cs
@@ -1,12 +1,14 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
namespace Grand.Web.Models.Catalog
{
public class ProductAskQuestionSimpleModel : BaseEntityModel
{
-
+ public ProductAskQuestionSimpleModel()
+ {
+ Captcha = new CaptchaModel();
+ }
[GrandResourceDisplayName("Products.AskQuestion.Email")]
public string AskQuestionEmail { get; set; }
@@ -20,7 +22,7 @@ namespace Grand.Web.Models.Catalog
public string AskQuestionMessage { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Catalog/ProductEmailAFriendModel.cs b/src/Web/Grand.Web/Models/Catalog/ProductEmailAFriendModel.cs
index 6af046816..1908cfdde 100644
--- a/src/Web/Grand.Web/Models/Catalog/ProductEmailAFriendModel.cs
+++ b/src/Web/Grand.Web/Models/Catalog/ProductEmailAFriendModel.cs
@@ -1,11 +1,14 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
namespace Grand.Web.Models.Catalog
{
public class ProductEmailAFriendModel : BaseModel
{
+ public ProductEmailAFriendModel()
+ {
+ Captcha = new CaptchaModel();
+ }
public string ProductId { get; set; }
public string ProductName { get; set; }
@@ -23,8 +26,7 @@ namespace Grand.Web.Models.Catalog
public bool SuccessfullySent { get; set; }
public string Result { get; set; }
-
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Catalog/ProductReviewModel.cs b/src/Web/Grand.Web/Models/Catalog/ProductReviewModel.cs
index 4f1646a94..6f23bbab3 100644
--- a/src/Web/Grand.Web/Models/Catalog/ProductReviewModel.cs
+++ b/src/Web/Grand.Web/Models/Catalog/ProductReviewModel.cs
@@ -1,6 +1,5 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
namespace Grand.Web.Models.Catalog
{
@@ -21,11 +20,12 @@ namespace Grand.Web.Models.Catalog
{
Items = new List<ProductReviewModel>();
AddProductReview = new AddProductReviewModel();
+ Captcha = new CaptchaModel();
}
public string ProductId { get; set; }
public bool CaptchaValid { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
public string ProductName { get; set; }
public string ProductSeName { get; set; }
diff --git a/src/Web/Grand.Web/Models/Contact/ContactUsModel.cs b/src/Web/Grand.Web/Models/Contact/ContactUsModel.cs
index f4473203d..d0d7635df 100644
--- a/src/Web/Grand.Web/Models/Contact/ContactUsModel.cs
+++ b/src/Web/Grand.Web/Models/Contact/ContactUsModel.cs
@@ -4,7 +4,6 @@ using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
using Grand.Web.Common.Binders;
using Grand.Web.Common.Models;
-using Grand.Web.Models.Common;
using Microsoft.AspNetCore.Mvc;
namespace Grand.Web.Models.Contact
@@ -16,6 +15,7 @@ namespace Grand.Web.Models.Contact
ContactAttributes = new List<ContactAttributeModel>();
ContactAttribute = new List<CustomAttribute>();
Attributes = new List<CustomAttributeModel>();
+ Captcha = new CaptchaModel();
}
[GrandResourceDisplayName("ContactUs.Email")]
public string Email { get; set; }
@@ -29,7 +29,7 @@ namespace Grand.Web.Models.Contact
public bool SuccessfullySent { get; set; }
public string Result { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
[ModelBinder(BinderType = typeof(CustomAttributesBinder))]
public IList<CustomAttributeModel> Attributes { get; set; }
public string ContactAttributeInfo { get; set; }
diff --git a/src/Web/Grand.Web/Models/Customer/LoginModel.cs b/src/Web/Grand.Web/Models/Customer/LoginModel.cs
index 2c529dda6..216965068 100644
--- a/src/Web/Grand.Web/Models/Customer/LoginModel.cs
+++ b/src/Web/Grand.Web/Models/Customer/LoginModel.cs
@@ -1,12 +1,15 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
using System.ComponentModel.DataAnnotations;
namespace Grand.Web.Models.Customer
{
public class LoginModel : BaseModel
{
+ public LoginModel()
+ {
+ Captcha = new CaptchaModel();
+ }
public bool CheckoutAsGuest { get; set; }
[DataType(DataType.EmailAddress)]
@@ -24,6 +27,6 @@ namespace Grand.Web.Models.Customer
[GrandResourceDisplayName("Account.Login.Fields.RememberMe")]
public bool RememberMe { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Customer/PaswordRecoveryModel.cs b/src/Web/Grand.Web/Models/Customer/PaswordRecoveryModel.cs
index 5ced658fd..e89259726 100644
--- a/src/Web/Grand.Web/Models/Customer/PaswordRecoveryModel.cs
+++ b/src/Web/Grand.Web/Models/Customer/PaswordRecoveryModel.cs
@@ -1,18 +1,21 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
using System.ComponentModel.DataAnnotations;
namespace Grand.Web.Models.Customer
{
public class PasswordRecoveryModel : BaseModel
{
+ public PasswordRecoveryModel()
+ {
+ Captcha = new CaptchaModel();
+ }
[DataType(DataType.EmailAddress)]
[GrandResourceDisplayName("Account.PasswordRecovery.Email")]
public string Email { get; set; }
public string Result { get; set; }
public bool Send { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Customer/RegisterModel.cs b/src/Web/Grand.Web/Models/Customer/RegisterModel.cs
index a2b6d62b6..e316191de 100644
--- a/src/Web/Grand.Web/Models/Customer/RegisterModel.cs
+++ b/src/Web/Grand.Web/Models/Customer/RegisterModel.cs
@@ -2,7 +2,6 @@
using Grand.Infrastructure.Models;
using Grand.Web.Common.Binders;
using Grand.Web.Common.Models;
-using Grand.Web.Models.Common;
using Grand.Web.Models.Newsletter;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
@@ -19,6 +18,7 @@ namespace Grand.Web.Models.Customer
CustomerAttributes = new List<CustomerAttributeModel>();
SelectedAttributes = new List<CustomAttributeModel>();
NewsletterCategories = new List<NewsletterSimpleCategory>();
+ Captcha = new CaptchaModel();
}
[DataType(DataType.EmailAddress)]
[GrandResourceDisplayName("Account.Fields.Email")]
@@ -134,7 +134,7 @@ namespace Grand.Web.Models.Customer
public bool DisplayVatNumber { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
[ModelBinder(BinderType = typeof(CustomAttributesBinder))]
public IList<CustomAttributeModel> SelectedAttributes { get; set; }
diff --git a/src/Web/Grand.Web/Models/Knowledgebase/KnowledgebaseArticleModel.cs b/src/Web/Grand.Web/Models/Knowledgebase/KnowledgebaseArticleModel.cs
index 0d3689a8e..cfa32accf 100644
--- a/src/Web/Grand.Web/Models/Knowledgebase/KnowledgebaseArticleModel.cs
+++ b/src/Web/Grand.Web/Models/Knowledgebase/KnowledgebaseArticleModel.cs
@@ -1,5 +1,4 @@
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
namespace Grand.Web.Models.Knowledgebase
{
@@ -11,6 +10,7 @@ namespace Grand.Web.Models.Knowledgebase
CategoryBreadcrumb = new List<KnowledgebaseCategoryModel>();
Comments = new List<KnowledgebaseArticleCommentModel>();
AddNewComment = new AddKnowledgebaseArticleCommentModel();
+ Captcha = new CaptchaModel();
}
public string ArticleId { get; set; }
public string Name { get; set; }
@@ -29,7 +29,7 @@ namespace Grand.Web.Models.Knowledgebase
public bool AllowComments { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
public IList<KnowledgebaseArticleModel> RelatedArticles { get; set; }
diff --git a/src/Web/Grand.Web/Models/News/NewsItemModel.cs b/src/Web/Grand.Web/Models/News/NewsItemModel.cs
index 783928995..165445d1a 100644
--- a/src/Web/Grand.Web/Models/News/NewsItemModel.cs
+++ b/src/Web/Grand.Web/Models/News/NewsItemModel.cs
@@ -1,5 +1,4 @@
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
using Grand.Web.Models.Media;
namespace Grand.Web.Models.News
@@ -11,6 +10,7 @@ namespace Grand.Web.Models.News
Comments = new List<NewsCommentModel>();
AddNewComment = new AddNewsCommentModel();
PictureModel = new PictureModel();
+ Captcha = new CaptchaModel();
}
public string NewsItemId { get; set; }
public string MetaKeywords { get; set; }
@@ -26,6 +26,6 @@ namespace Grand.Web.Models.News
public DateTime CreatedOn { get; set; }
public IList<NewsCommentModel> Comments { get; set; }
public AddNewsCommentModel AddNewComment { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/ShoppingCart/WishlistEmailAFriendModel.cs b/src/Web/Grand.Web/Models/ShoppingCart/WishlistEmailAFriendModel.cs
index e9dabdba0..c509ad350 100644
--- a/src/Web/Grand.Web/Models/ShoppingCart/WishlistEmailAFriendModel.cs
+++ b/src/Web/Grand.Web/Models/ShoppingCart/WishlistEmailAFriendModel.cs
@@ -1,11 +1,15 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
namespace Grand.Web.Models.ShoppingCart
{
public class WishlistEmailAFriendModel : BaseModel
{
+ public WishlistEmailAFriendModel()
+ {
+ Captcha = new CaptchaModel();
+ }
+
[GrandResourceDisplayName("Wishlist.EmailAFriend.FriendEmail")]
public string FriendEmail { get; set; }
@@ -17,9 +21,7 @@ namespace Grand.Web.Models.ShoppingCart
public bool SuccessfullySent { get; set; }
public string Result { get; set; }
-
public bool DisplayCaptcha { get; set; }
-
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Vendors/ApplyVendorModel.cs b/src/Web/Grand.Web/Models/Vendors/ApplyVendorModel.cs
index e5ecab015..5d0bb707c 100644
--- a/src/Web/Grand.Web/Models/Vendors/ApplyVendorModel.cs
+++ b/src/Web/Grand.Web/Models/Vendors/ApplyVendorModel.cs
@@ -1,6 +1,5 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
using System.ComponentModel.DataAnnotations;
namespace Grand.Web.Models.Vendors
@@ -11,6 +10,7 @@ namespace Grand.Web.Models.Vendors
public ApplyVendorModel()
{
Address = new VendorAddressModel();
+ Captcha = new CaptchaModel();
}
public VendorAddressModel Address { get; set; }
@@ -23,7 +23,7 @@ namespace Grand.Web.Models.Vendors
[GrandResourceDisplayName("Vendors.ApplyAccount.Description")]
public string Description { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
public bool TermsOfServiceEnabled { get; set; }
public bool TermsOfServicePopup { get; set; }
public bool DisableFormInput { get; set; }
diff --git a/src/Web/Grand.Web/Models/Vendors/ContactVendorModel.cs b/src/Web/Grand.Web/Models/Vendors/ContactVendorModel.cs
index e69682141..04f3d5eea 100644
--- a/src/Web/Grand.Web/Models/Vendors/ContactVendorModel.cs
+++ b/src/Web/Grand.Web/Models/Vendors/ContactVendorModel.cs
@@ -1,12 +1,15 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
-using Grand.Web.Models.Common;
using System.ComponentModel.DataAnnotations;
namespace Grand.Web.Models.Vendors
{
public class ContactVendorModel : BaseModel
{
+ public ContactVendorModel()
+ {
+ Captcha = new CaptchaModel();
+ }
public string VendorId { get; set; }
public string VendorName { get; set; }
@@ -28,6 +31,6 @@ namespace Grand.Web.Models.Vendors
public string Result { get; set; }
public bool DisplayCaptcha { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Vendors/VendorReviewOverviewModel.cs b/src/Web/Grand.Web/Models/Vendors/VendorReviewOverviewModel.cs
index c493ba4b4..97f7fc389 100644
--- a/src/Web/Grand.Web/Models/Vendors/VendorReviewOverviewModel.cs
+++ b/src/Web/Grand.Web/Models/Vendors/VendorReviewOverviewModel.cs
@@ -21,6 +21,7 @@ namespace Grand.Web.Models.Vendors
{
Items = new List<VendorReviewModel>();
AddVendorReview = new AddVendorReviewModel();
+ Captcha = new CaptchaModel();
}
public string VendorId { get; set; }
@@ -31,7 +32,7 @@ namespace Grand.Web.Models.Vendors
public IList<VendorReviewModel> Items { get; set; }
public AddVendorReviewModel AddVendorReview { get; set; }
public VendorReviewOverviewModel VendorReviewOverview { get; set; }
- public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();
+ public ICaptchaValidModel Captcha { get; set; }
}
public class VendorReviewModel : BaseEntityModel