ExternalEntityLinkHandlers.cs
3.75 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using DirRX.LongTermArchive.ExternalEntityLink;
namespace DirRX.LongTermArchive
{
partial class ExternalEntityLinkCreatingFromServerHandler
{
public override void CreatingFrom(Sungero.Domain.CreatingFromEventArgs e)
{
if (CallContext.CalledFrom(Storage.ExternalEntities.Info) &&
Storage.PublicFunctions.Module.Remote.GetMappingMode(CallContext.GetCallerEntityId(Storage.ExternalEntities.Info)) == Storage.ExternalEntity.MappingMode.Auto)
{
throw AppliedCodeException.Create("Нельзя копировать записи в режиме авто-сопоставления");
}
else
base.CreatingFrom(e);
}
}
partial class ExternalEntityLinkUiFilteringServerHandler<T>
{
public override IQueryable<T> Filtering(IQueryable<T> query, Sungero.Domain.UiFilteringEventArgs e)
{
query = base.Filtering(query, e);
if (CallContext.CalledDirectlyFrom(Storage.ExternalEntities.Info))
{
var parent = Storage.ExternalEntities.Get(CallContext.GetCallerEntityId(Storage.ExternalEntities.Info));
query = query.Where(x => x.ExtSystemId == parent.ExternalSystem.SourceUid &&
x.ExtEntityType == parent.Uid &&
x.EntityType == parent.EntityType);
}
return query;
}
}
partial class ExternalEntityLinkServerHandlers
{
public override void BeforeSave(Sungero.Domain.BeforeSaveEventArgs e)
{
if (e.Params.Contains("ViewMode"))
throw AppliedCodeException.Create("Нельзя сохранить запись в режиме просмотра.");
else
base.BeforeSave(e);
}
public override void BeforeDelete(Sungero.Domain.BeforeDeleteEventArgs e)
{
if (e.Params.Contains("ViewMode"))
throw AppliedCodeException.Create("Нельзя удалить запись в режиме просмотра.");
else if (CallContext.CalledFrom(Storage.ExternalEntities.Info) &&
Storage.PublicFunctions.Module.Remote.GetMappingMode(CallContext.GetCallerEntityId(Storage.ExternalEntities.Info)) == Storage.ExternalEntity.MappingMode.Auto)
throw AppliedCodeException.Create("Нельзя удалять записи в режиме авто-сопоставления.");
else
base.BeforeDelete(e);
}
public override void Saving(Sungero.Domain.SavingEventArgs e)
{
base.Saving(e);
_obj.SyncDate = Calendar.Now;
}
public override void Created(Sungero.Domain.CreatedEventArgs e)
{
// Если запись создается из Справочника системы-источника, заполнить значения из контекста.
if (CallContext.CalledFrom(Storage.ExternalEntities.Info))
{
// В режиме автосопоставления создавать записи запрещено.
if (Storage.PublicFunctions.Module.Remote.GetMappingMode(CallContext.GetCallerEntityId(Storage.ExternalEntities.Info)) == Storage.ExternalEntity.MappingMode.Auto)
{
throw AppliedCodeException.Create("Нельзя создавать записи в режиме авто-сопоставления");
}
else
{
base.Created(e);
var parent = Storage.ExternalEntities.Get(CallContext.GetCallerEntityId(Storage.ExternalEntities.Info));
_obj.ExtSystemId = parent.ExternalSystem.SourceUid;
_obj.ExtEntityType = parent.Uid;
_obj.EntityType = parent.EntityType;
_obj.SyncDate = Calendar.Now;
}
}
else
base.Created(e);
}
}
}