-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionService.cs
124 lines (108 loc) · 4.95 KB
/
CollectionService.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
using System.Collections.Generic;
using System.Threading.Tasks;
using Collections.API.Repositories.Interfaces;
using Collections.API.Services.Interfaces;
namespace Collections.API.Services
{
/// <summary>
/// The collections service
/// </summary>
/// <seealso cref="Collections.API.Services.Interfaces.ICollectionService" />
public class CollectionService : ICollectionService
{
/// <summary>
/// The collections repository
/// </summary>
private readonly ICollectionRepository collectionRepository;
/// <summary>
/// Initializes a new instance TModelf the <see cref="CollectionService"/> class.
/// </summary>
/// <param name="collectionRepository">The data repository.</param>
public CollectionService(ICollectionRepository collectionRepository)
{
this.collectionRepository = collectionRepository;
}
/// <summary>
/// Gets the records asynchronously.
/// </summary>
/// <typeparam name="TInterface">The collection type</typeparam>
/// <typeparam name="TModel">The model type</typeparam>
/// <returns><see cref="IEnumerable{T}"/>collection TModelf records</returns>
public async Task<IEnumerable<TInterface>> GetAsync<TInterface, TModel>() where TModel : class, TInterface, new()
{
var results = await this.collectionRepository.GetAsync<TInterface, TModel>();
return results;
}
/// <summary>
/// Gets the requested record asynchronously.
/// </summary>
/// <typeparam name="TInterface">The collection type</typeparam>
/// <returns>The requested record</returns>
public async Task<TInterface> GetByIdAsync<TInterface>(string id)
{
var result = await this.collectionRepository.GetByIdAsync<TInterface>(id);
return result;
}
/// <summary>
/// Searches for the specified model with the advanced search model.
/// </summary>
/// <typeparam name="TInterface">The collection type</typeparam>
/// <typeparam name="TModel">The model type</typeparam>
/// <param name="model">The advanced search model.</param>
/// <returns>The results TModelf the search</returns>
public async Task<IEnumerable<TInterface>> PostSearchAsync<TInterface, TModel>(TModel model) where TModel : class, TInterface, new()
{
var results = await this.collectionRepository.PostSearchAsync<TInterface, TModel>(model);
return results;
}
/// <summary>
/// Posts the record asynchronously
/// </summary>
/// <param name="model">The model to be posted</param>
/// <typeparam name="TInterface">The collection type</typeparam>
/// <typeparam name="TModel">The model type</typeparam>
/// <returns>True if successful</returns>
public async Task<bool> PostAsync<TInterface, TModel>(IEnumerable<TModel> model) where TModel : class, TInterface, new()
{
var result = await this.collectionRepository.PostMultipleAsync<TInterface, TModel>(model);
return result;
}
/// <summary>
/// Patches specified the record asynchronously.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="model">The model.</param>
/// <typeparam name="TInterface">The collection type</typeparam>
/// <typeparam name="TModel">The model type</typeparam>
/// <returns>True if successful</returns>
public async Task<bool> PatchAsync<TInterface, TModel>(string id, TModel model) where TModel : class, TInterface, new()
{
var result = await this.collectionRepository.PatchAsync<TInterface, TModel>(id, model);
return result;
}
/// <summary>
/// Puts specified the record asynchronously.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="model">The model.</param>
/// <typeparam name="TInterface">The collection type</typeparam>
/// <typeparam name="TModel">The model type</typeparam>
/// <returns>True if successful</returns>
public async Task<bool> PutAsync<TInterface, TModel>(string id, TModel model) where TModel : class, TInterface, new()
{
var result = await this.collectionRepository.PutAsync<TInterface, TModel>(id, model);
return result;
}
/// <summary>
/// Deletes specified the record asynchronously.
/// </summary>
/// <param name="ids">The identifier.</param>
/// <typeparam name="TInterface">The collection type</typeparam>
/// <returns>True if successful</returns>
public async Task<bool> DeleteAsync<TInterface>(string id)
{
var result = await this.collectionRepository.DeleteAsync<TInterface>(id);
return result;
}
}
}