-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandRepository.cs
More file actions
112 lines (94 loc) · 3.71 KB
/
CommandRepository.cs
File metadata and controls
112 lines (94 loc) · 3.71 KB
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
using SharedCode.Models;
namespace SharedCode.Data;
/// <summary>
/// The command repository class. Implements the <see cref="ICommandRepository{TEntity}"/>.
/// </summary>
/// <typeparam name="TEntity">The type of the t entity.</typeparam>
/// <seealso cref="ICommandRepository{TEntity}"/>
public abstract class CommandRepository<TEntity> : ICommandRepository<TEntity> where TEntity : Entity
{
/// <inheritdoc/>
public abstract int Add(TEntity entity);
/// <inheritdoc/>
public abstract IEnumerable<int> Add(IEnumerable<TEntity> entities);
/// <inheritdoc/>
int ICommandRepository.Add(Entity entity)
{
return entity is TEntity typed
? this.Add(typed)
: throw new ArgumentException($"The type \"{entity.GetType()}\" does not match the type \"{typeof(TEntity)}\"");
}
/// <inheritdoc/>
IEnumerable<int> ICommandRepository.Add(IEnumerable<Entity> entities)
{
return entities is IEnumerable<TEntity> typed
? this.Add(typed)
: throw new ArgumentException($"The type \"{entities.GetType()}\" does not match the type \"{typeof(IEnumerable<TEntity>)}\"");
}
/// <inheritdoc/>
public abstract IAddOrUpdateDescriptor AddOrUpdate(TEntity entity);
/// <inheritdoc/>
public abstract IEnumerable<IAddOrUpdateDescriptor> AddOrUpdate(IEnumerable<TEntity> entities);
/// <inheritdoc/>
IAddOrUpdateDescriptor ICommandRepository.AddOrUpdate(Entity entity)
{
return entity is TEntity typed
? this.AddOrUpdate(typed)
: throw new ArgumentException($"The type \"{entity.GetType()}\" does not match the type \"{typeof(TEntity)}\"");
}
/// <inheritdoc/>
IEnumerable<IAddOrUpdateDescriptor> ICommandRepository.AddOrUpdate(IEnumerable<Entity> entities)
{
return entities is IEnumerable<TEntity> typed
? this.AddOrUpdate(typed)
: throw new ArgumentException($"The type \"{entities.GetType()}\" does not match the type \"{typeof(IEnumerable<TEntity>)}\"");
}
/// <inheritdoc/>
public abstract bool Remove(int id);
/// <inheritdoc/>
public abstract bool Remove(TEntity entity);
/// <inheritdoc/>
public abstract IDictionary<int, bool> Remove(IEnumerable<TEntity> entities);
/// <inheritdoc/>
bool ICommandRepository.Remove(Entity entity)
{
return entity is TEntity typed
? this.Remove(typed)
: throw new ArgumentException($"The type \"{entity.GetType()}\" does not match the type \"{typeof(TEntity)}\"");
}
/// <inheritdoc/>
IDictionary<int, bool> ICommandRepository.Remove(IEnumerable<Entity> entities)
{
return entities is IEnumerable<TEntity> typed
? this.Remove(typed)
: throw new ArgumentException($"The type \"{entities.GetType()}\" does not match the type \"{typeof(IEnumerable<TEntity>)}\"");
}
/// <inheritdoc/>
public abstract void Update(TEntity entity);
/// <inheritdoc/>
public abstract void Update(IEnumerable<TEntity> entities);
/// <inheritdoc/>
void ICommandRepository.Update(Entity entity)
{
if (entity is TEntity typed)
{
this.Update(typed);
}
else
{
throw new ArgumentException($"The type \"{entity.GetType()}\" does not match the type \"{typeof(TEntity)}\"");
}
}
/// <inheritdoc/>
void ICommandRepository.Update(IEnumerable<Entity> entities)
{
if (entities is IEnumerable<TEntity> typed)
{
this.Update(typed);
}
else
{
throw new ArgumentException($"The type \"{entities.GetType()}\" does not match the type \"{typeof(IEnumerable<TEntity>)}\"");
}
}
}