public async Task <OdooResult <T> > SingleAsync() { Take(2); var result = await ToListAsync(); return(result.Succeed ? result.ToResult(result.Value.Single()) : OdooResult <T> .FailedResult(result)); }
public async Task <OdooResult <bool> > AnyAsync() { Take(1); var result = await ToListAsync(); return(result.Succeed ? result.ToResult(result.Value.Any()) : OdooResult <bool> .FailedResult(result)); }
public async Task <OdooResult <T> > FirstOrDefaultAsync() { Take(1); var result = await ToListAsync(); return(result.Succeed ? result.ToResult(result.Value.FirstOrDefault()) : OdooResult <T> .FailedResult(result)); }
public static async Task <OdooResult <long> > CreateAsync(OdooConfig odooConfig, int userUid, OdooDictionaryModel model) { var request = OdooRequestModel.Create(odooConfig, userUid, GetTableName(model), model); var result = await CallAndDeserializeAsync <long[]>(request); return(result.Succeed ? result.ToResult(result.Value.FirstOrDefault()) : OdooResult <long> .FailedResult(result)); }
private async Task <OdooResult <TResult> > ExecuteWitrAccesDenideRetryAsync <TResult>(Func <int, Task <OdooResult <TResult> > > func) { var userUid = await GetCurrentUserUidOrLoginAsync(); if (userUid.Failed) { return(OdooResult <TResult> .FailedResult(userUid)); } var result = await func.Invoke(userUid.Value); if (!result.Failed || !string.Equals(result.Error?.Data?.Name, OdooExceptionName.AccessDenied)) { return(result); } var loginUid = await LoginAsync(); if (loginUid.Failed) { return(OdooResult <TResult> .FailedResult(loginUid)); } return(await func.Invoke(loginUid.Value)); }
public static async Task<OdooResult<T>> CallAndDeserializeAsync<T>(OdooRequestModel request) { try { var response = await CallAsync(request); var responseString = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject<OdooResult<T>>(responseString); return result; } catch (Exception e) { return OdooResult<T>.FailedResult(e.ToString()); } }
public static async Task<OdooResult<long>> CreateAsync(OdooConfig odooConfig, int userUid, IOdooCreateModel model, OdooContext context = null) { var request = OdooRequestModel.Create(odooConfig, userUid, model.OdooTableName(), model, context); var result = await CallAndDeserializeAsync<long>(request); return result.Succeed ? result.ToResult(result.Value) : OdooResult<long>.FailedResult(result); }