-
Notifications
You must be signed in to change notification settings - Fork 39
/
RobotDataSvc.cs
62 lines (51 loc) · 2.66 KB
/
RobotDataSvc.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
/*
* This file is automatically generated; any changes will be lost.
*/
#nullable enable
#pragma warning disable
namespace Beef.Demo.Business.DataSvc;
/// <summary>
/// Provides the <see cref="Robot"/> data repository services.
/// </summary>
public partial class RobotDataSvc : IRobotDataSvc
{
private readonly IRobotData _data;
private readonly IEventPublisher _events;
private readonly IRequestCache _cache;
/// <summary>
/// Initializes a new instance of the <see cref="RobotDataSvc"/> class.
/// </summary>
/// <param name="data">The <see cref="IRobotData"/>.</param>
/// <param name="events">The <see cref="IEventPublisher"/>.</param>
/// <param name="cache">The <see cref="IRequestCache"/>.</param>
public RobotDataSvc(IRobotData data, IEventPublisher events, IRequestCache cache)
{ _data = data.ThrowIfNull(); _events = events.ThrowIfNull(); _cache = cache.ThrowIfNull(); RobotDataSvcCtor(); }
partial void RobotDataSvcCtor(); // Enables additional functionality to be added to the constructor.
/// <inheritdoc/>
public Task<Result<Robot?>> GetAsync(Guid id) => Result.Go().CacheGetOrAddAsync(_cache, id, () => GetOnImplementationAsync(id));
/// <inheritdoc/>
public Task<Result<Robot>> CreateAsync(Robot value) => DataSvcInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.GoAsync(_data.CreateAsync(value))
.Then(r => _events.PublishValueEvent(r, new Uri($"/robots/{r.Id}", UriKind.Relative), $"Demo.Robot", "Create"))
.CacheSet(_cache);
}, new InvokerArgs { EventPublisher = _events });
/// <inheritdoc/>
public Task<Result<Robot>> UpdateAsync(Robot value) => DataSvcInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.GoAsync(_data.UpdateAsync(value))
.Then(r => _events.PublishValueEvent(r, new Uri($"/robots/{r.Id}", UriKind.Relative), $"Demo.Robot", "Update"))
.CacheSet(_cache);
}, new InvokerArgs { EventPublisher = _events });
/// <inheritdoc/>
public Task<Result> DeleteAsync(Guid id) => DataSvcInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.Go().CacheRemove<Robot>(_cache, id)
.ThenAsync(() => _data.DeleteAsync(id))
.Then(() => _events.PublishValueEvent(new Robot { Id = id }, new Uri($"/robots/{id}", UriKind.Relative), $"Demo.Robot", "Delete"));
}, new InvokerArgs { EventPublisher = _events });
/// <inheritdoc/>
public Task<Result<RobotCollectionResult>> GetByArgsAsync(RobotArgs? args, PagingArgs? paging) => _data.GetByArgsAsync(args, paging);
}
#pragma warning restore
#nullable restore