-
Notifications
You must be signed in to change notification settings - Fork 4
/
Events.cs
52 lines (43 loc) · 1.58 KB
/
Events.cs
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
using System.Threading.Tasks;
using MyOrg.DomainTutorial.Models;
using Smartstore;
using Smartstore.Core.Data;
using Smartstore.Events;
using Smartstore.Web.Modelling;
using Smartstore.Web.Rendering.Events;
namespace MyOrg.DomainTutorial
{
public class Events : IConsumer
{
private readonly SmartDbContext _db;
public Events(SmartDbContext db)
{
_db = db;
}
public async Task HandleEventAsync(TabStripCreated eventMessage)
{
var tabStripName = eventMessage.TabStripName;
if (tabStripName == "product-edit")
{
var entityId = ((TabbableModel)eventMessage.Model).Id;
await eventMessage.TabFactory.AppendAsync(builder => builder
.Text("My Tab")
.Name("tab-MyTab")
.Icon("star", "bi")
.LinkHtmlAttributes(new { data_tab_name = "MyTab" })
.Action("AdminEditTab", "DomainTutorialAdmin", new { entityId })
.Ajax());
}
}
public async Task HandleEventAsync(ModelBoundEvent message)
{
if (!message.BoundModel.CustomProperties.ContainsKey("MyTab"))
return;
if (message.BoundModel.CustomProperties["MyTab"] is not AdminEditTabModel model)
return;
var product = await _db.Products.FindByIdAsync(model.EntityId);
product.GenericAttributes.Set("DomainTutorialMyTabValue", model.MyTabValue);
await _db.SaveChangesAsync();
}
}
}