Repository navigation
Expand file tree
/
Copy pathNewsletterController.cs
More file actions
63 lines (57 loc) · 2.12 KB
/
Copy pathNewsletterController.cs
File metadata and controls
63 lines (57 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Grand.SharedKernel.Attributes;
using Grand.Web.Commands.Models.Newsletter;
using Grand.Web.Common.Controllers;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Startup;
using Grand.Web.Models.Newsletter;
using Grand.Mediator;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
namespace Grand.Web.Controllers;
[DenySystemAccount]
[ApiGroup(SharedKernel.Extensions.ApiConstants.ApiGroupNameV2)]
public class NewsletterController : BasePublicController
{
private readonly IMediator _mediator;
public NewsletterController(IMediator mediator)
{
_mediator = mediator;
}
[EnableRateLimiting(GrandCommonStartup.StorefrontFormRateLimitPolicy)]
[HttpPost]
public virtual async Task<IActionResult> SubscribeNewsletter(string email, bool subscribe)
{
var model = await _mediator.Send(new SubscribeNewsletterCommand { Email = email, Subscribe = subscribe });
if (model.NewsletterCategory == null)
return Json(new {
model.Success,
model.Result,
Showcategories = model.ShowCategories,
model.ResultCategory
});
model.ShowCategories = true;
model.ResultCategory =
await this.RenderPartialViewToString("NewsletterCategory", model.NewsletterCategory, true);
return Json(new {
model.Success,
model.Result,
Showcategories = model.ShowCategories,
model.ResultCategory
});
}
[HttpPost]
public virtual async Task<IActionResult> SaveCategories(NewsletterCategoryModel model)
{
var result = await _mediator.Send(new SubscriptionCategoryCommand { Model = model });
return Json(new {
Success = result.success,
Message = result.message
});
}
[HttpGet]
public virtual async Task<IActionResult> SubscriptionActivation(Guid token, bool active)
{
var model = await _mediator.Send(new SubscriptionActivationCommand { Active = active, Token = token });
return model == null ? RedirectToRoute("HomePage") : View(model);
}
}