Skip to content

Commit ba85fcb

Browse files
author
patryk.bujalla
committed
update range odoo repository
1 parent f05a559 commit ba85fcb

3 files changed

Lines changed: 37 additions & 34 deletions

File tree

PortaCapena.OdooJsonRpcClient/IOdooRepository.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ namespace PortaCapena.OdooJsonRpcClient
88
public interface IOdooRepository<T> where T : IOdooModel, new()
99
{
1010
OdooQueryBuilder<T> Query();
11-
11+
1212
Task<OdooResult<long>> CreateAsync(IOdooCreateModel model);
1313
Task<OdooResult<long>> CreateAsync(OdooCreateDictionary model);
1414

1515
Task<OdooResult<bool>> UpdateAsync(IOdooCreateModel model, long id);
16-
Task<OdooResult<bool>> UpdateAsync(OdooCreateDictionary model, params long[] ids);
16+
Task<OdooResult<bool>> UpdateRangeAsync(IOdooCreateModel model, long[] ids);
17+
Task<OdooResult<bool>> UpdateAsync(OdooCreateDictionary model, long id);
18+
Task<OdooResult<bool>> UpdateRangeAsync(OdooCreateDictionary model, long[] ids);
1719

1820
Task<OdooResult<bool>> DeleteAsync(T model);
1921
Task<OdooResult<bool>> DeleteAsync(long id);

PortaCapena.OdooJsonRpcClient/OdooClient.cs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ public OdooClient(OdooConfig config)
3333
{
3434
return await ExecuteWitrAccesDenideRetryAsync(userUid => GetAsync<T>(userUid, query));
3535
}
36-
3736
public async Task<OdooResult<T[]>> GetAsync<T>(int userUid, OdooQuery query = null) where T : IOdooModel, new()
3837
{
3938
return await GetAsync<T>(_config, userUid, query);
4039
}
41-
4240
public static async Task<OdooResult<T[]>> GetAsync<T>(OdooConfig odooConfig, int userUid, OdooQuery query = null) where T : IOdooModel, new()
4341
{
4442
var tableName = OdooExtensions.GetOdooTableName<T>();
@@ -54,12 +52,10 @@ public OdooClient(OdooConfig config)
5452
{
5553
return await ExecuteWitrAccesDenideRetryAsync(userUid => GetCountAsync<T>(userUid, query));
5654
}
57-
5855
public async Task<OdooResult<long>> GetCountAsync<T>(int userUid, OdooQuery query = null) where T : IOdooModel, new()
5956
{
6057
return await GetCountAsync<T>(_config, userUid, query);
6158
}
62-
6359
public static async Task<OdooResult<long>> GetCountAsync<T>(OdooConfig odooConfig, int userUid, OdooQuery query = null) where T : IOdooModel, new()
6460
{
6561
var tableName = OdooExtensions.GetOdooTableName<T>();
@@ -75,19 +71,16 @@ public async Task<OdooResult<long>> CreateAsync(IOdooCreateModel model)
7571
{
7672
return await ExecuteWitrAccesDenideRetryAsync(userUid => CreateAsync(_config, userUid, model));
7773
}
78-
7974
public static async Task<OdooResult<long>> CreateAsync(OdooConfig odooConfig, int userUid, IOdooCreateModel model)
8075
{
8176
var request = OdooRequestModel.Create(odooConfig, userUid, model.OdooTableName(), model);
8277
var result = await CallAndDeserializeAsync<long[]>(request);
8378
return result.Succeed ? result.ToResult(result.Value.FirstOrDefault()) : OdooResult<long>.FailedResult(result);
8479
}
85-
8680
public async Task<OdooResult<long>> CreateAsync(OdooCreateDictionary model)
8781
{
8882
return await ExecuteWitrAccesDenideRetryAsync(userUid => CreateAsync(_config, userUid, model));
8983
}
90-
9184
public static async Task<OdooResult<long>> CreateAsync(OdooConfig odooConfig, int userUid, OdooCreateDictionary model)
9285
{
9386
var request = OdooRequestModel.Create(odooConfig, userUid, GetTableName(model), model);
@@ -99,24 +92,38 @@ public static async Task<OdooResult<long>> CreateAsync(OdooConfig odooConfig, in
9992

10093
#region Update
10194

102-
public async Task<OdooResult<bool>> UpdateAsync(IOdooCreateModel model, params long[] ids)
95+
public async Task<OdooResult<bool>> UpdateAsync(IOdooCreateModel model, long id)
10396
{
104-
return await ExecuteWitrAccesDenideRetryAsync(userUid => UpdateAsync(_config, userUid, model, ids));
97+
return await UpdateRangeAsync(model, new[] { id });
98+
}
99+
public static async Task<OdooResult<bool>> UpdateAsync(OdooConfig odooConfig, int userUid, IOdooCreateModel model, long id)
100+
{
101+
return await UpdateRangeAsync(odooConfig, userUid, model, new[] { id });
102+
}
103+
public async Task<OdooResult<bool>> UpdateAsync(OdooCreateDictionary model, long id)
104+
{
105+
return await UpdateRangeAsync(model, new[] { id });
106+
}
107+
public static async Task<OdooResult<bool>> UpdateAsync(OdooConfig odooConfig, int userUid, OdooCreateDictionary model, long id)
108+
{
109+
return await UpdateRangeAsync(odooConfig, userUid, model, new[] { id });
105110
}
106111

107-
public static async Task<OdooResult<bool>> UpdateAsync(OdooConfig odooConfig, int userUid, IOdooCreateModel model, params long[] ids)
112+
public async Task<OdooResult<bool>> UpdateRangeAsync(IOdooCreateModel model, long[] ids)
113+
{
114+
return await ExecuteWitrAccesDenideRetryAsync(userUid => UpdateRangeAsync(_config, userUid, model, ids));
115+
}
116+
public static async Task<OdooResult<bool>> UpdateRangeAsync(OdooConfig odooConfig, int userUid, IOdooCreateModel model, long[] ids)
108117
{
109118
var tableName = model.OdooTableName();
110119
var request = OdooRequestModel.Update(odooConfig, userUid, tableName, ids, model);
111120
return await CallAndDeserializeAsync<bool>(request);
112121
}
113-
114-
public async Task<OdooResult<bool>> UpdateAsync(OdooCreateDictionary model, long[] ids)
122+
public async Task<OdooResult<bool>> UpdateRangeAsync(OdooCreateDictionary model, long[] ids)
115123
{
116-
return await ExecuteWitrAccesDenideRetryAsync(userUid => UpdateAsync(_config, userUid, model, ids));
124+
return await ExecuteWitrAccesDenideRetryAsync(userUid => UpdateRangeAsync(_config, userUid, model, ids));
117125
}
118-
119-
public static async Task<OdooResult<bool>> UpdateAsync(OdooConfig odooConfig, int userUid, OdooCreateDictionary model, long[] ids)
126+
public static async Task<OdooResult<bool>> UpdateRangeAsync(OdooConfig odooConfig, int userUid, OdooCreateDictionary model, long[] ids)
120127
{
121128
var request = OdooRequestModel.Update(odooConfig, userUid, GetTableName(model), ids, model);
122129
return await CallAndDeserializeAsync<bool>(request);
@@ -130,12 +137,10 @@ public async Task<OdooResult<bool>> DeleteAsync(IOdooModel model)
130137
{
131138
return await DeleteAsync(model.OdooTableName(), model.Id);
132139
}
133-
134140
public async Task<OdooResult<bool>> DeleteAsync(string tableName, long id)
135141
{
136142
return await DeleteRangeAsync(tableName, new[] { id });
137143
}
138-
139144
public static async Task<OdooResult<bool>> DeleteAsync(OdooConfig odooConfig, int userUid, string tableName, long id)
140145
{
141146
return await DeleteRangeAsync(odooConfig, userUid, tableName, new[] { id });
@@ -149,12 +154,10 @@ public async Task<OdooResult<bool>> DeleteRangeAsync(IOdooModel[] models)
149154

150155
return await DeleteRangeAsync(tableName, models.Select(x => x.Id).ToArray());
151156
}
152-
153157
public async Task<OdooResult<bool>> DeleteRangeAsync(string tableName, long[] ids)
154158
{
155159
return await ExecuteWitrAccesDenideRetryAsync(userUid => DeleteRangeAsync(_config, userUid, tableName, ids));
156160
}
157-
158161
public static async Task<OdooResult<bool>> DeleteRangeAsync(OdooConfig odooConfig, int userUid, string tableName, long[] ids)
159162
{
160163
var request = OdooRequestModel.Delete(odooConfig, userUid, tableName, ids);
@@ -172,7 +175,6 @@ public async Task<OdooResult<int>> GetCurrentUserUidOrLoginAsync()
172175

173176
return await LoginAsync();
174177
}
175-
176178
public async Task<OdooResult<int>> LoginAsync()
177179
{
178180
var result = await LoginAsync(_config);
@@ -182,7 +184,6 @@ public async Task<OdooResult<int>> LoginAsync()
182184

183185
return result;
184186
}
185-
186187
public static async Task<OdooResult<int>> LoginAsync(OdooConfig odooConfig)
187188
{
188189
var request = OdooRequestModel.Login(odooConfig);
@@ -197,7 +198,6 @@ public async Task<OdooResult<Dictionary<string, OdooPropertyInfo>>> GetModelAsyn
197198
{
198199
return await ExecuteWitrAccesDenideRetryAsync(userUid => GetModelAsync(_config, userUid, tableName));
199200
}
200-
201201
public static async Task<OdooResult<Dictionary<string, OdooPropertyInfo>>> GetModelAsync(OdooConfig odooConfig, int userUid, string tableName)
202202
{
203203
var request = OdooRequestModel.ModelFields(odooConfig, userUid, tableName);
@@ -212,7 +212,6 @@ public async Task<OdooResult<OdooVersion>> GetVersionAsync()
212212
{
213213
return await GetVersionAsync(_config);
214214
}
215-
216215
public static async Task<OdooResult<OdooVersion>> GetVersionAsync(OdooConfig odooConfig)
217216
{
218217
var request = OdooRequestModel.Version(odooConfig);
@@ -238,7 +237,6 @@ private async Task<OdooResult<TResult>> ExecuteWitrAccesDenideRetryAsync<TResult
238237

239238
return await func.Invoke(loginUid.Value);
240239
}
241-
242240
public static async Task<OdooResult<T>> CallAndDeserializeAsync<T>(OdooRequestModel request)
243241
{
244242
try
@@ -253,7 +251,6 @@ public static async Task<OdooResult<T>> CallAndDeserializeAsync<T>(OdooRequestMo
253251
return OdooResult<T>.FailedResult(e.ToString());
254252
}
255253
}
256-
257254
public static async Task<HttpResponseMessage> CallAsync(OdooRequestModel requestModel)
258255
{
259256
string json = JsonConvert.SerializeObject(requestModel, new IsoDateTimeConverter { DateTimeFormat = OdooConsts.DateTimeFormat });
@@ -267,7 +264,6 @@ public static async Task<HttpResponseMessage> CallAsync(OdooRequestModel request
267264
return result;
268265
}
269266
}
270-
271267
private static string GetTableName(OdooCreateDictionary model, string tableName = null)
272268
{
273269
if (tableName != null)

PortaCapena.OdooJsonRpcClient/OdooRepository.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public async Task<OdooResult<long>> CreateAsync(IOdooCreateModel model)
2727
{
2828
return await OdooClient.CreateAsync(model);
2929
}
30-
3130
public async Task<OdooResult<long>> CreateAsync(OdooCreateDictionary model)
3231
{
3332
return await OdooClient.CreateAsync(model);
@@ -37,24 +36,30 @@ public async Task<OdooResult<bool>> UpdateAsync(IOdooCreateModel model, long id)
3736
{
3837
return await OdooClient.UpdateAsync(model, id);
3938
}
39+
public async Task<OdooResult<bool>> UpdateRangeAsync(IOdooCreateModel model, long[] ids)
40+
{
41+
return await OdooClient.UpdateRangeAsync(model, ids);
42+
}
4043

41-
public async Task<OdooResult<bool>> UpdateAsync(OdooCreateDictionary model, params long[] ids)
44+
public async Task<OdooResult<bool>> UpdateAsync(OdooCreateDictionary model, long id)
45+
{
46+
return await OdooClient.UpdateAsync(model, id);
47+
}
48+
public async Task<OdooResult<bool>> UpdateRangeAsync(OdooCreateDictionary model, long[] ids)
4249
{
4350
model.TableName = TableName;
44-
return await OdooClient.UpdateAsync(model, ids);
51+
return await OdooClient.UpdateRangeAsync(model, ids);
4552
}
4653

4754
public async Task<OdooResult<bool>> DeleteAsync(T model)
4855
{
4956
return await OdooClient.DeleteAsync(model);
5057
}
51-
5258
public async Task<OdooResult<bool>> DeleteAsync(long id)
5359
{
5460
return await OdooClient.DeleteAsync(TableName, id);
5561
}
56-
57-
public async Task<OdooResult<bool>> DeleteRangeAsync(params T[] models)
62+
public async Task<OdooResult<bool>> DeleteRangeAsync(T[] models)
5863
{
5964
return await OdooClient.DeleteRangeAsync(models as IOdooModel[]);
6065
}

0 commit comments

Comments
 (0)