Skip to content

Commit dbaba31

Browse files
committed
Issue rsm-hcd#34 and rsm-hcd#17: Adding Update async methods
1 parent 38cb2c8 commit dbaba31

File tree

11 files changed

+388
-84
lines changed

11 files changed

+388
-84
lines changed

src/Conductors/RepositoryConductor.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -418,29 +418,20 @@ public virtual IResult<IList<T>> FindAllCommitted(
418418

419419
#region Update
420420

421-
/// <summary>
422-
/// Ability to update a list of entities in a single bulk operation.
423-
/// </summary>
424-
/// <param name="items">List of items to update</param>
425-
/// <param name="updatedBy">Id of user updating the entity</param>
426-
/// <returns></returns>
427-
public virtual IResult<bool> BulkUpdate(IEnumerable<T> items, long? updatedBy = default(long?)) => _updateConductor.BulkUpdate(items, updatedBy);
421+
/// <inheritdoc />
422+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
423+
public virtual IResult<bool> BulkUpdate(IEnumerable<T> items, long? updatedBy = default(long?)) =>
424+
_updateConductor.BulkUpdate(items, updatedBy);
428425

429-
/// <summary>
430-
/// Ability to update an entity
431-
/// </summary>
432-
/// <param name="item">Item to update</param>
433-
/// <param name="updatedBy">Id of user updating the entity</param>
434-
/// <returns></returns>
435-
public virtual IResult<bool> Update(T item, long? updatedBy = default(long?)) => _updateConductor.Update(item, updatedBy);
426+
/// <inheritdoc />
427+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
428+
public virtual IResult<bool> Update(T item, long? updatedBy = default(long?)) =>
429+
_updateConductor.Update(item, updatedBy);
436430

437-
/// <summary>
438-
/// Ability to update a list of items but each item is updated individually.
439-
/// </summary>
440-
/// <param name="items">List of items to update</param>
441-
/// <param name="updatedBy">Id of user updating the entity</param>
442-
/// <returns></returns>
443-
public virtual IResult<bool> Update(IEnumerable<T> items, long? updatedBy = default(long?)) => _updateConductor.Update(items, updatedBy);
431+
/// <inheritdoc />
432+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
433+
public virtual IResult<bool> Update(IEnumerable<T> items, long? updatedBy = default(long?)) =>
434+
_updateConductor.Update(items, updatedBy);
444435

445436
#endregion Update
446437

src/Conductors/RepositoryConductorAsync.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,21 @@ public Task<IResult<bool>> RestoreAsync(long id, CancellationToken cancellationT
122122
_deleteConductor.RestoreAsync(id, cancellationToken);
123123

124124
#endregion Delete
125+
126+
#region Update
127+
128+
/// <inheritdoc />
129+
public Task<IResult<bool>> BulkUpdateAsync(IEnumerable<T> items, long? updatedBy = default(long?), CancellationToken cancellationToken = default) =>
130+
_updateConductor.BulkUpdateAsync(items, updatedBy, cancellationToken);
131+
132+
/// <inheritdoc />
133+
public Task<IResult<bool>> UpdateAsync(T item, long? updatedBy = default(long?), CancellationToken cancellationToken = default) =>
134+
_updateConductor.UpdateAsync(item, updatedBy, cancellationToken);
135+
136+
/// <inheritdoc />
137+
public Task<IResult<bool>> UpdateAsync(IEnumerable<T> items, long? updatedBy = default(long?), CancellationToken cancellationToken = default) =>
138+
_updateConductor.UpdateAsync(items, updatedBy, cancellationToken);
139+
140+
#endregion Update
125141
}
126142
}

src/Conductors/RepositoryUpdateConductor.cs

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
using System;
12
using System.Collections.Generic;
23
using AndcultureCode.CSharp.Core.Interfaces;
34
using AndcultureCode.CSharp.Core.Interfaces.Conductors;
4-
using AndcultureCode.CSharp.Core.Interfaces.Data;
55
using AndcultureCode.CSharp.Core.Interfaces.Entity;
66

77
namespace AndcultureCode.CSharp.Conductors
@@ -10,69 +10,27 @@ namespace AndcultureCode.CSharp.Conductors
1010
/// Ability to update an entity or a list of entities
1111
/// </summary>
1212
/// <typeparam name="T"></typeparam>
13-
public class RepositoryUpdateConductor<T> : Conductor, IRepositoryUpdateConductor<T>
13+
public partial class RepositoryUpdateConductor<T> : Conductor, IRepositoryUpdateConductor<T>
1414
where T : class, IEntity
1515
{
16-
#region Properties
17-
18-
/// <summary>
19-
/// Ability to set and get the underlying DbContext's command timeout
20-
/// </summary>
21-
public int? CommandTimeout
22-
{
23-
get => _repository.CommandTimeout;
24-
set => _repository.CommandTimeout = value;
25-
}
26-
27-
readonly IRepository<T> _repository;
28-
29-
#endregion Properties
30-
31-
#region Constructor
32-
33-
/// <summary>
34-
/// Constructor
35-
/// </summary>
36-
/// <param name="repository"></param>
37-
public RepositoryUpdateConductor(
38-
IRepository<T> repository
39-
)
40-
{
41-
_repository = repository;
42-
}
43-
44-
#endregion Constructor
45-
4616
#region IRepositoryUpdateConductor Implementation
4717

48-
/// <summary>
49-
/// Ability to update a list of entities in a single bulk operation.
50-
/// </summary>
51-
/// <param name="items">List of items to update</param>
52-
/// <param name="updatedBy">Id of user updating the entity</param>
53-
/// <returns></returns>
18+
/// <inheritdoc />
19+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
5420
public virtual IResult<bool> BulkUpdate(IEnumerable<T> items, long? updatedBy = default(long?))
5521
{
5622
return _repository.BulkUpdate(items, updatedBy);
5723
}
5824

59-
/// <summary>
60-
/// Ability to update an entity
61-
/// </summary>
62-
/// <param name="item">Item to update</param>
63-
/// <param name="updatedBy">Id of user updating the entity</param>
64-
/// <returns></returns>
25+
/// <inheritdoc />
26+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
6527
public virtual IResult<bool> Update(T item, long? updatedBy = default(long?))
6628
{
6729
return _repository.Update(item, updatedBy);
6830
}
6931

70-
/// <summary>
71-
/// Ability to update a list of items but each item is updated individually.
72-
/// </summary>
73-
/// <param name="items">List of items to update</param>
74-
/// <param name="updatedBy">Id of user updating the entity</param>
75-
/// <returns></returns>
32+
/// <inheritdoc />
33+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
7634
public virtual IResult<bool> Update(IEnumerable<T> items, long? updatedBy = default(long?))
7735
{
7836
return _repository.Update(items, updatedBy);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using AndcultureCode.CSharp.Core.Interfaces;
5+
using AndcultureCode.CSharp.Core.Interfaces.Conductors;
6+
using AndcultureCode.CSharp.Core.Interfaces.Data;
7+
using AndcultureCode.CSharp.Core.Interfaces.Entity;
8+
9+
namespace AndcultureCode.CSharp.Conductors
10+
{
11+
public partial class RepositoryUpdateConductor<T> : Conductor, IRepositoryUpdateConductor<T>
12+
where T : class, IEntity
13+
{
14+
/// <summary>
15+
/// Ability to set and get the underlying DbContext's command timeout
16+
/// </summary>
17+
public int? CommandTimeout
18+
{
19+
get => _repository.CommandTimeout;
20+
set => _repository.CommandTimeout = value;
21+
}
22+
23+
readonly IRepository<T> _repository;
24+
25+
/// <summary>
26+
/// Constructor
27+
/// </summary>
28+
/// <param name="repository"></param>
29+
public RepositoryUpdateConductor(
30+
IRepository<T> repository
31+
)
32+
{
33+
_repository = repository;
34+
}
35+
36+
/// <summary>
37+
/// Ability to update a list of entities in a single bulk operation.
38+
/// </summary>
39+
/// <param name="items">List of items to update</param>
40+
/// <param name="updatedBy">Id of user updating the entity</param>
41+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
42+
/// <returns></returns>
43+
public Task<IResult<bool>> BulkUpdateAsync(IEnumerable<T> items, long? updatedBy = default(long?), CancellationToken cancellationToken = default)
44+
{
45+
cancellationToken.ThrowIfCancellationRequested();
46+
return _repository.BulkUpdateAsync(items, updatedBy, cancellationToken);
47+
}
48+
49+
/// <summary>
50+
/// Ability to update an entity
51+
/// </summary>
52+
/// <param name="item">Item to update</param>
53+
/// <param name="updatedBy">Id of user updating the entity</param>
54+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
55+
/// <returns></returns>
56+
public Task<IResult<bool>> UpdateAsync(T item, long? updatedBy = default(long?), CancellationToken cancellationToken = default)
57+
{
58+
cancellationToken.ThrowIfCancellationRequested();
59+
return _repository.UpdateAsync(item, updatedBy, cancellationToken);
60+
}
61+
62+
/// <summary>
63+
/// Ability to update a list of items but each item is updated individually.
64+
/// </summary>
65+
/// <param name="items">List of items to update</param>
66+
/// <param name="updatedBy">Id of user updating the entity</param>
67+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
68+
/// <returns></returns>
69+
public Task<IResult<bool>> UpdateAsync(IEnumerable<T> items, long? updatedBy = default(long?), CancellationToken cancellationToken = default)
70+
{
71+
cancellationToken.ThrowIfCancellationRequested();
72+
return _repository.UpdateAsync(items, updatedBy, cancellationToken);
73+
}
74+
}
75+
}
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1+
using System;
12
using System.Collections.Generic;
23
using AndcultureCode.CSharp.Core.Interfaces.Entity;
34

45
namespace AndcultureCode.CSharp.Core.Interfaces.Conductors
56
{
6-
public interface IRepositoryUpdateConductor<T>
7+
public partial interface IRepositoryUpdateConductor<T>
78
where T : class, IEntity
89
{
9-
#region Properties
10-
1110
/// <summary>
12-
/// Ability to set and get the underlying DbContext's command timeout
11+
/// Ability to update a list of entities in a single bulk operation.
1312
/// </summary>
14-
int? CommandTimeout { get; set; }
15-
16-
#endregion Properties
17-
18-
19-
#region Methods
20-
13+
/// <param name="items">List of items to update</param>
14+
/// <param name="updatedBy">Id of user updating the entity</param>
15+
/// <returns></returns>
16+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
2117
IResult<bool> BulkUpdate(IEnumerable<T> items, long? updatedBy = null);
18+
19+
/// <summary>
20+
/// Ability to update an entity
21+
/// </summary>
22+
/// <param name="item">Item to update</param>
23+
/// <param name="updatedBy">Id of user updating the entity</param>
24+
/// <returns></returns>
25+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
2226
IResult<bool> Update(T item, long? updatedBy = null);
23-
IResult<bool> Update(IEnumerable<T> items, long? updatedBy = default(long?));
2427

25-
#endregion Methods
28+
/// <summary>
29+
/// Ability to update a list of items but each item is updated individually.
30+
/// </summary>
31+
/// <param name="items">List of items to update</param>
32+
/// <param name="updatedBy">Id of user updating the entity</param>
33+
/// <returns></returns>
34+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
35+
IResult<bool> Update(IEnumerable<T> items, long? updatedBy = default(long?));
2636
}
2737
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using AndcultureCode.CSharp.Core.Interfaces.Entity;
5+
6+
namespace AndcultureCode.CSharp.Core.Interfaces.Conductors
7+
{
8+
public partial interface IRepositoryUpdateConductor<T>
9+
where T : class, IEntity
10+
{
11+
/// <summary>
12+
/// Ability to set and get the underlying DbContext's command timeout
13+
/// </summary>
14+
int? CommandTimeout { get; set; }
15+
16+
/// <summary>
17+
/// Ability to update a list of entities in a single bulk operation.
18+
/// </summary>
19+
/// <param name="items">List of items to update</param>
20+
/// <param name="updatedBy">Id of user updating the entity</param>
21+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
22+
/// <returns></returns>
23+
Task<IResult<bool>> BulkUpdateAsync(IEnumerable<T> items, long? updatedBy = null, CancellationToken cancellationToken = default);
24+
25+
/// <summary>
26+
/// Ability to update an entity
27+
/// </summary>
28+
/// <param name="item">Item to update</param>
29+
/// <param name="updatedBy">Id of user updating the entity</param>
30+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
31+
/// <returns></returns>
32+
Task<IResult<bool>> UpdateAsync(T item, long? updatedBy = null, CancellationToken cancellationToken = default);
33+
34+
/// <summary>
35+
/// Ability to update a list of items but each item is updated individually.
36+
/// </summary>
37+
/// <param name="items">List of items to update</param>
38+
/// <param name="updatedBy">Id of user updating the entity</param>
39+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
40+
/// <returns></returns>
41+
Task<IResult<bool>> UpdateAsync(IEnumerable<T> items, long? updatedBy = default(long?), CancellationToken cancellationToken = default);
42+
}
43+
}

src/Core/Interfaces/Data/IRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public partial interface IRepository<T>
6464
/// <param name="entities">List of items to update</param>
6565
/// <param name="updatedBy">Id of user updating the entity</param>
6666
/// <returns></returns>
67+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
6768
IResult<bool> BulkUpdate(IEnumerable<T> entities, long? updatedBy = default(long?));
6869

6970
/// <summary>
@@ -274,6 +275,7 @@ IResult<IQueryable<TResult>> FindAll<TKey, TResult>(
274275
/// <param name="item">Item to create or update</param>
275276
/// <param name="updatedBy">Id of user creating or updating the entity</param>
276277
/// <returns></returns>
278+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
277279
IResult<bool> Update(T item, long? updatedBy = null);
278280

279281
/// <summary>
@@ -283,6 +285,7 @@ IResult<IQueryable<TResult>> FindAll<TKey, TResult>(
283285
/// <param name="entities"></param>
284286
/// <param name="updatedBy"></param>
285287
/// <returns>True if entities updated without any exceptions. False if an exception was thrown.</returns>
288+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
286289
IResult<bool> Update(IEnumerable<T> entities, long? updatedBy = default(long?));
287290

288291
#endregion Methods

src/Core/Interfaces/Data/IRepositoryAsync.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,37 @@ public partial interface IRepository<T>
127127

128128
#endregion Delete
129129

130+
#region Update
131+
132+
/// <summary>
133+
/// Ability to update a list of entities in a single bulk operation.
134+
/// </summary>
135+
/// <param name="entities">List of items to update</param>
136+
/// <param name="updatedBy">Id of user updating the entity</param>
137+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
138+
/// <returns></returns>
139+
Task<IResult<bool>> BulkUpdateAsync(IEnumerable<T> entities, long? updatedBy = default(long?), CancellationToken cancellationToken = default);
140+
141+
/// <summary>
142+
/// Ability to create or update an entity
143+
/// </summary>
144+
/// <param name="item">Item to create or update</param>
145+
/// <param name="updatedBy">Id of user creating or updating the entity</param>
146+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
147+
/// <returns></returns>
148+
Task<IResult<bool>> UpdateAsync(T item, long? updatedBy = null, CancellationToken cancellationToken = default);
149+
150+
/// <summary>
151+
/// Calls Update one-by-one for each item in the enumerated entities.
152+
/// For large operations, BulkUpdate() is more efficient.
153+
/// </summary>
154+
/// <param name="entities"></param>
155+
/// <param name="updatedBy"></param>
156+
/// <param name="cancellationToken">a token allowing aborting of this request</param>
157+
/// <returns>True if entities updated without any exceptions. False if an exception was thrown.</returns>
158+
Task<IResult<bool>> UpdateAsync(IEnumerable<T> entities, long? updatedBy = default(long?), CancellationToken cancellationToken = default);
159+
160+
#endregion Update
161+
130162
}
131163
}

0 commit comments

Comments
 (0)