-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathEmployeeDataSvc.cs
64 lines (54 loc) · 3.25 KB
/
EmployeeDataSvc.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
53
54
55
56
57
58
59
60
61
62
63
64
/*
* This file is automatically generated; any changes will be lost.
*/
namespace MyEf.Hr.Business.DataSvc;
/// <summary>
/// Provides the <see cref="Employee"/> data repository services.
/// </summary>
public partial class EmployeeDataSvc : IEmployeeDataSvc
{
private readonly IEmployeeData _data;
private readonly IEventPublisher _events;
private readonly IRequestCache _cache;
/// <summary>
/// Initializes a new instance of the <see cref="EmployeeDataSvc"/> class.
/// </summary>
/// <param name="data">The <see cref="IEmployeeData"/>.</param>
/// <param name="events">The <see cref="IEventPublisher"/>.</param>
/// <param name="cache">The <see cref="IRequestCache"/>.</param>
public EmployeeDataSvc(IEmployeeData data, IEventPublisher events, IRequestCache cache)
{ _data = data.ThrowIfNull(); _events = events.ThrowIfNull(); _cache = cache.ThrowIfNull(); EmployeeDataSvcCtor(); }
partial void EmployeeDataSvcCtor(); // Enables additional functionality to be added to the constructor.
/// <inheritdoc/>
public Task<Result<Employee?>> GetAsync(Guid id) => Result.Go().CacheGetOrAddAsync(_cache, id, () => _data.GetAsync(id));
/// <inheritdoc/>
public Task<Result<Employee>> CreateAsync(Employee value) => DataSvcInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.GoAsync(_data.CreateAsync(value))
.Then(r => _events.PublishValueEvent(r, new Uri($"myef/hr/employee/{r.Id}", UriKind.Relative), $"MyEf.Hr.Employee", "Created"))
.CacheSet(_cache);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Result<Employee>> UpdateAsync(Employee value) => DataSvcInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.GoAsync(_data.UpdateAsync(value))
.Then(r => _events.PublishValueEvent(r, new Uri($"myef/hr/employee/{r.Id}", UriKind.Relative), $"MyEf.Hr.Employee", "Updated"))
.CacheSet(_cache);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Result> DeleteAsync(Guid id) => DataSvcInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.Go().CacheRemove<Employee>(_cache, id)
.ThenAsync(() => _data.DeleteAsync(id))
.Then(() => _events.PublishValueEvent(new { Id = id }, new Uri($"myef/hr/employee/{id}", UriKind.Relative), $"MyEf.Hr.Employee", "Deleted"));
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Result<EmployeeBaseCollectionResult>> GetByArgsAsync(EmployeeArgs? args, PagingArgs? paging) => _data.GetByArgsAsync(args, paging);
/// <inheritdoc/>
public Task<Result<Employee>> TerminateAsync(TerminationDetail value, Guid id) => DataSvcInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.GoAsync(_data.TerminateAsync(value, id))
.Then(r => _events.PublishValueEvent(r, new Uri($"myef/hr/employee/{r.Id}", UriKind.Relative), $"MyEf.Hr.Employee", "Terminated"))
.CacheSet(_cache);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
}