-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathRobotManager.cs
83 lines (71 loc) · 3.79 KB
/
RobotManager.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
/*
* This file is automatically generated; any changes will be lost.
*/
#nullable enable
#pragma warning disable
namespace Beef.Demo.Business;
/// <summary>
/// Provides the <see cref="Robot"/> business functionality.
/// </summary>
public partial class RobotManager : IRobotManager
{
private readonly IRobotDataSvc _dataService;
private readonly IEventPublisher _eventPublisher;
private readonly IIdentifierGenerator _identifierGenerator;
/// <summary>
/// Initializes a new instance of the <see cref="RobotManager"/> class.
/// </summary>
/// <param name="dataService">The <see cref="IRobotDataSvc"/>.</param>
/// <param name="eventPublisher">The <see cref="IEventPublisher"/>.</param>
/// <param name="identifierGenerator">The <see cref="IIdentifierGenerator"/>.</param>
public RobotManager(IRobotDataSvc dataService, IEventPublisher eventPublisher, IIdentifierGenerator identifierGenerator)
{ _dataService = dataService.ThrowIfNull(); _eventPublisher = eventPublisher.ThrowIfNull(); _identifierGenerator = identifierGenerator.ThrowIfNull(); RobotManagerCtor(); }
partial void RobotManagerCtor(); // Enables additional functionality to be added to the constructor.
/// <inheritdoc/>
public Task<Result<Robot?>> GetAsync(Guid id) => ManagerInvoker.Current.InvokeAsync(this, (_, ct) =>
{
return Result.Go().Requires(id)
.Then(() => Cleaner.CleanUp(id))
.ThenAsAsync(() => _dataService.GetAsync(id));
}, InvokerArgs.Read);
/// <inheritdoc/>
public Task<Result<Robot>> CreateAsync(Robot value) => ManagerInvoker.Current.InvokeAsync(this, (_, ct) =>
{
return Result.Go(value).Required()
.AdjustsAsync(async v => v.Id = await _identifierGenerator.GenerateIdentifierAsync<Guid, Robot>().ConfigureAwait(false))
.Then(v => Cleaner.CleanUp(v))
.ValidateAsync(vc => vc.Interop(() => FluentValidator.Create<RobotValidator>().Wrap()), cancellationToken: ct)
.ThenAsAsync(v => _dataService.CreateAsync(v));
}, InvokerArgs.Create);
/// <inheritdoc/>
public Task<Result<Robot>> UpdateAsync(Robot value, Guid id) => ManagerInvoker.Current.InvokeAsync(this, (_, ct) =>
{
return Result.Go(value).Required().Requires(id).Adjusts(v => v.Id = id)
.Then(v => Cleaner.CleanUp(v))
.ValidateAsync(vc => vc.Interop(() => FluentValidator.Create<RobotValidator>().Wrap()), cancellationToken: ct)
.ThenAsAsync(v => _dataService.UpdateAsync(v));
}, InvokerArgs.Update);
/// <inheritdoc/>
public Task<Result> DeleteAsync(Guid id) => ManagerInvoker.Current.InvokeAsync(this, (_, ct) =>
{
return Result.Go().Requires(id)
.Then(() => Cleaner.CleanUp(id))
.ThenAsync(() => _dataService.DeleteAsync(id));
}, InvokerArgs.Delete);
/// <inheritdoc/>
public Task<Result<RobotCollectionResult>> GetByArgsAsync(RobotArgs? args, PagingArgs? paging) => ManagerInvoker.Current.InvokeAsync(this, (_, ct) =>
{
return Result.Go()
.Then(() => Cleaner.CleanUp(args))
.ValidatesAsync(args, vc => vc.Entity().With<RobotArgsValidator>(), cancellationToken: ct)
.ThenAsAsync(() => _dataService.GetByArgsAsync(args, paging));
}, InvokerArgs.Read);
/// <inheritdoc/>
public Task<Result> RaisePowerSourceChangeAsync(Guid id, RefDataNamespace.PowerSource? powerSource) => ManagerInvoker.Current.InvokeAsync(this, (_, ct) =>
{
return Result.Go().Requires(id)
.ThenAsync(() => RaisePowerSourceChangeOnImplementationAsync(id, powerSource));
}, InvokerArgs.Unspecified);
}
#pragma warning restore
#nullable restore