-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathEmployeeData.cs
94 lines (80 loc) · 5.32 KB
/
EmployeeData.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
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
/*
* This file is automatically generated; any changes will be lost.
*/
namespace My.Hr.Business.Data;
/// <summary>
/// Provides the <see cref="Employee"/> data access.
/// </summary>
public partial class EmployeeData : IEmployeeData
{
private readonly IDatabase _db;
private readonly HrEfDb _ef;
private readonly IEventPublisher _events;
private Func<IQueryable<EfModel.Employee>, EmployeeArgs?, IQueryable<EfModel.Employee>>? _getByArgsOnQuery;
/// <summary>
/// Initializes a new instance of the <see cref="EmployeeData"/> class.
/// </summary>
/// <param name="db">The <see cref="IDatabase"/>.</param>
/// <param name="ef">The <see cref="HrEfDb"/>.</param>
/// <param name="events">The <see cref="IEventPublisher"/>.</param>
public EmployeeData(IDatabase db, HrEfDb ef, IEventPublisher events)
{ _db = db.ThrowIfNull(); _ef = ef.ThrowIfNull(); _events = events.ThrowIfNull(); EmployeeDataCtor(); }
partial void EmployeeDataCtor(); // Enables additional functionality to be added to the constructor.
/// <inheritdoc/>
public Task<Result<Employee?>> GetAsync(Guid id) => GetOnImplementationAsync(id);
/// <inheritdoc/>
public Task<Result<Employee>> CreateAsync(Employee value) => DataInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.Go(value).ThenAsync(v => CreateOnImplementationAsync(v))
.Then(r => _events.PublishValueEvent(r, new Uri($"my/hr/employee/{r.Id}", UriKind.Relative), $"My.Hr.Employee", "Created"));
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Result<Employee>> UpdateAsync(Employee value) => DataInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.Go(value).ThenAsync(v => UpdateOnImplementationAsync(v))
.Then(r => _events.PublishValueEvent(r, new Uri($"my/hr/employee/{r.Id}", UriKind.Relative), $"My.Hr.Employee", "Updated"));
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Result> DeleteAsync(Guid id) => DataInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.Go().ThenAsync(() => _db.StoredProcedure("[Hr].[spEmployeeDelete]").DeleteWithResultAsync(DbMapper.Default, id))
.Then(() => _events.PublishValueEvent(new Employee { Id = id }, new Uri($"my/hr/employee/{id}", UriKind.Relative), $"My.Hr.Employee", "Deleted"));
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Result<EmployeeBaseCollectionResult>> GetByArgsAsync(EmployeeArgs? args, PagingArgs? paging)
=> _ef.Query<EmployeeBase, EfModel.Employee>(q => _getByArgsOnQuery?.Invoke(q, args) ?? q).WithPaging(paging).SelectResultWithResultAsync<EmployeeBaseCollectionResult, EmployeeBaseCollection>();
/// <inheritdoc/>
public Task<Result<Employee>> TerminateAsync(TerminationDetail value, Guid id) => DataInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.Go(value).ThenAsAsync(v => TerminateOnImplementationAsync(v, id))
.Then(r => _events.PublishValueEvent(r, new Uri($"my/hr/employee/{r.Id}", UriKind.Relative), $"My.Hr.Employee", "Terminated"));
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <summary>
/// Provides the <see cref="Employee"/> property and database column mapping.
/// </summary>
public partial class DbMapper : DatabaseMapperEx<Employee, DbMapper>
{
/// <summary>
/// Initializes a new instance of the <see cref="DbMapper"/> class.
/// </summary>
public DbMapper() => InheritMapper(EmployeeBaseData.DbMapper.Default);
/// <inheritdoc />
protected override void OnMapToDb(Employee value, DatabaseParameterCollection parameters, OperationTypes operationType)
{
parameters.AddParameter("AddressJson", ObjectToJsonConverter<Address>.Default.ConvertToDestination(value.Address));
WhenAnyExceptCreate(operationType, () => parameters.AddParameter(parameters.Database.DatabaseColumns.RowVersionName, StringToBase64Converter.Default.ConvertToDestination(value.ETag)));
ChangeLogExDatabaseMapper.Default.MapToDb(value.ChangeLog, parameters, operationType);
OnMapToDbEx(value, parameters, operationType);
}
/// <inheritdoc />
protected override void OnMapFromDb(DatabaseRecord record, Employee value, OperationTypes operationType)
{
value.Address = (Address?)ObjectToJsonConverter<Address>.Default.ConvertToSource(record.GetValue("AddressJson"));
WhenAnyExceptCreate(operationType, () => value.ETag = (string?)StringToBase64Converter.Default.ConvertToSource(record.GetValue(record.Database.DatabaseColumns.RowVersionName)));
value.ChangeLog = ChangeLogExDatabaseMapper.Default.MapFromDb(record, operationType);
OnMapFromDbEx(record, value, operationType);
}
partial void OnMapToDbEx(Employee value, DatabaseParameterCollection parameters, OperationTypes operationType); // Enables the DbMapper.OnMapToDb to be extended.
partial void OnMapFromDbEx(DatabaseRecord record, Employee value, OperationTypes operationType); // Enables the DbMapper.OnMapFromDb to be extended.
}
}