forked from Avanade/Beef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactData.cs
146 lines (129 loc) · 6.86 KB
/
ContactData.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* This file is automatically generated; any changes will be lost.
*/
#nullable enable
#pragma warning disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Beef;
using Beef.Business;
using Beef.Data.Database;
using Beef.Data.EntityFrameworkCore;
using Beef.Entities;
using Beef.Events;
using Beef.Mapper;
using Beef.Mapper.Converters;
using Beef.Demo.Business.Entities;
using RefDataNamespace = Beef.Demo.Common.Entities;
namespace Beef.Demo.Business.Data
{
/// <summary>
/// Provides the <see cref="Contact"/> data access.
/// </summary>
public partial class ContactData : IContactData
{
private readonly IEfDb _ef;
private readonly AutoMapper.IMapper _mapper;
private readonly IEventPublisher _evtPub;
private Func<IQueryable<EfModel.Contact>, EfDbArgs, IQueryable<EfModel.Contact>>? _getAllOnQuery;
/// <summary>
/// Initializes a new instance of the <see cref="ContactData"/> class.
/// </summary>
/// <param name="ef">The <see cref="IEfDb"/>.</param>
/// <param name="mapper">The <see cref="AutoMapper.IMapper"/>.</param>
/// <param name="evtPub">The <see cref="IEventPublisher"/>.</param>
public ContactData(IEfDb ef, AutoMapper.IMapper mapper, IEventPublisher evtPub)
{ _ef = Check.NotNull(ef, nameof(ef)); _mapper = Check.NotNull(mapper, nameof(mapper)); _evtPub = Check.NotNull(evtPub, nameof(evtPub)); ContactDataCtor(); }
partial void ContactDataCtor(); // Enables additional functionality to be added to the constructor.
/// <summary>
/// Gets the <see cref="ContactCollectionResult"/> that contains the items that match the selection criteria.
/// </summary>
/// <returns>The <see cref="ContactCollectionResult"/>.</returns>
public Task<ContactCollectionResult> GetAllAsync() => DataInvoker.Current.InvokeAsync(this, async () =>
{
ContactCollectionResult __result = new ContactCollectionResult();
var __dataArgs = EfDbArgs.Create(_mapper);
__result.Result = _ef.Query<Contact, EfModel.Contact>(__dataArgs, q => _getAllOnQuery?.Invoke(q, __dataArgs) ?? q).SelectQuery<ContactCollection>();
return await Task.FromResult(__result).ConfigureAwait(false);
});
/// <summary>
/// Gets the specified <see cref="Contact"/>.
/// </summary>
/// <param name="id">The <see cref="Contact"/> identifier.</param>
/// <returns>The selected <see cref="Contact"/> where found.</returns>
public Task<Contact?> GetAsync(Guid id) => DataInvoker.Current.InvokeAsync(this, async () =>
{
var __dataArgs = EfDbArgs.Create(_mapper);
return await _ef.GetAsync<Contact, EfModel.Contact>(__dataArgs, id).ConfigureAwait(false);
});
/// <summary>
/// Creates a new <see cref="Contact"/>.
/// </summary>
/// <param name="value">The <see cref="Contact"/>.</param>
/// <returns>The created <see cref="Contact"/>.</returns>
public Task<Contact> CreateAsync(Contact value) => _ef.EventOutboxInvoker.InvokeAsync(this, async () =>
{
var __dataArgs = EfDbArgs.Create(_mapper);
var __result = await _ef.CreateAsync<Contact, EfModel.Contact>(__dataArgs, Check.NotNull(value, nameof(value))).ConfigureAwait(false);
_evtPub.PublishValue(__result, new Uri($"/contact/{_evtPub.FormatKey(__result)}", UriKind.Relative), $"Demo.Contact.{_evtPub.FormatKey(__result)}", "Create");
return __result;
});
/// <summary>
/// Updates an existing <see cref="Contact"/>.
/// </summary>
/// <param name="value">The <see cref="Contact"/>.</param>
/// <returns>The updated <see cref="Contact"/>.</returns>
public Task<Contact> UpdateAsync(Contact value) => _ef.EventOutboxInvoker.InvokeAsync(this, async () =>
{
var __dataArgs = EfDbArgs.Create(_mapper);
var __result = await _ef.UpdateAsync<Contact, EfModel.Contact>(__dataArgs, Check.NotNull(value, nameof(value))).ConfigureAwait(false);
_evtPub.PublishValue(__result, new Uri($"/contact/{_evtPub.FormatKey(__result)}", UriKind.Relative), $"Demo.Contact.{_evtPub.FormatKey(__result)}", "Update");
return __result;
});
/// <summary>
/// Deletes the specified <see cref="Contact"/>.
/// </summary>
/// <param name="id">The <see cref="Contact"/> identifier.</param>
public Task DeleteAsync(Guid id) => _ef.EventOutboxInvoker.InvokeAsync(this, async () =>
{
var __dataArgs = EfDbArgs.Create(_mapper);
await _ef.DeleteAsync<Contact, EfModel.Contact>(__dataArgs, id).ConfigureAwait(false);
_evtPub.PublishValue(new Contact { Id = id }, new Uri($"/contact/{_evtPub.FormatKey(id)}", UriKind.Relative), $"Demo.Contact.{_evtPub.FormatKey(id)}", "Delete", id);
});
/// <summary>
/// Raise Event.
/// </summary>
/// <param name="throwError">Indicates whether throw a DivideByZero exception.</param>
public Task RaiseEventAsync(bool throwError) => _ef.EventOutboxInvoker.InvokeAsync(this, () => RaiseEventOnImplementationAsync(throwError));
/// <summary>
/// Provides the <see cref="Contact"/> and Entity Framework <see cref="EfModel.Contact"/> <i>AutoMapper</i> mapping.
/// </summary>
public partial class EfMapperProfile : AutoMapper.Profile
{
/// <summary>
/// Initializes a new instance of the <see cref="EfMapperProfile"/> class.
/// </summary>
public EfMapperProfile()
{
var s2d = CreateMap<Contact, EfModel.Contact>();
s2d.ForMember(d => d.ContactId, o => o.MapFrom(s => s.Id));
s2d.ForMember(d => d.FirstName, o => o.MapFrom(s => s.FirstName));
s2d.ForMember(d => d.LastName, o => o.MapFrom(s => s.LastName));
s2d.ForMember(d => d.StatusCode, o => o.MapFrom(s => s.StatusSid));
var d2s = CreateMap<EfModel.Contact, Contact>();
d2s.ForMember(s => s.Id, o => o.MapFrom(d => d.ContactId));
d2s.ForMember(s => s.FirstName, o => o.MapFrom(d => d.FirstName));
d2s.ForMember(s => s.LastName, o => o.MapFrom(d => d.LastName));
d2s.ForMember(s => s.StatusSid, o => o.MapFrom(d => d.StatusCode));
d2s.ForMember(s => s.InternalCode, o => o.Ignore());
EfMapperProfileCtor(s2d, d2s);
}
partial void EfMapperProfileCtor(AutoMapper.IMappingExpression<Contact, EfModel.Contact> s2d, AutoMapper.IMappingExpression<EfModel.Contact, Contact> d2s); // Enables the constructor to be extended.
}
}
}
#pragma warning restore
#nullable restore