ExternalEntityHandlers.cs
2.72 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using DirRX.Storage.ExternalEntity;
namespace DirRX.Storage
{
partial class ExternalEntityServerHandlers
{
public override void Saving(Sungero.Domain.SavingEventArgs e)
{
if (_obj.MappingMode.Value != MappingMode.Auto && _obj.AcceptWithoutConfirmation == true)
_obj.AcceptWithoutConfirmation = false;
}
public override void Created(Sungero.Domain.CreatedEventArgs e)
{
// Если запись создается из Внешнего справочника, заполнить значения из контекста.
if (CallContext.CalledFrom(Storage.ExternalSystems.Info))
{
_obj.ExternalSystem = Storage.ExternalSystems.GetCached(CallContext.GetCallerEntityId(Storage.ExternalSystems.Info));
}
_obj.MappingMode = MappingMode.NoMapping;
}
public override void AfterDelete(Sungero.Domain.AfterDeleteEventArgs e)
{
// Удалить внешние ссылки, используя ассинхронный обработчик.
if (Functions.ExternalEntity.GetEntityMapping(_obj).Any())
{
var asyncHandler = AsyncHandlers.DeleteExternalEntityLinks.Create();
asyncHandler.ExtSystemId = _obj.ExternalSystem.SourceUid;
asyncHandler.EntityType = _obj.EntityType;
asyncHandler.ExecuteAsync();
}
}
}
partial class ExternalEntityUiFilteringServerHandler<T>
{
public override IQueryable<T> Filtering(IQueryable<T> query, Sungero.Domain.UiFilteringEventArgs e)
{
query = base.Filtering(query, e);
if (CallContext.CalledDirectlyFrom(Storage.ExternalSystems.Info))
{
var parentId = CallContext.GetCallerEntityId(Storage.ExternalSystems.Info);
query = query.Where(x => x.ExternalSystem.Id == parentId);
}
return query;
}
}
partial class ExternalEntityFilteringServerHandler<T>
{
public override IQueryable<T> Filtering(IQueryable<T> query, Sungero.Domain.FilteringEventArgs e)
{
var filter = _filter;
if (filter == null)
return query;
// Фильтр по состоянию.
if (filter.Active || filter.Closed)
query = query.Where(f => (filter.Active && f.Status.Value == Sungero.CoreEntities.DatabookEntry.Status.Active) ||
(filter.Closed && f.Status.Value == Sungero.CoreEntities.DatabookEntry.Status.Closed));
// Фильтр по системе-источнику.
if (filter.SourceSystem != null)
query = query.Where(f => f.ExternalSystem == filter.SourceSystem);
return query;
}
}
}