public async Task <T> GetItemAsync(T item, string pkPrefix, List <string> CallTrace) { try { string id = GetProperty(item, "ID", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).ToString(); try { Guid g = Guid.Parse(id); if (g.Equals(Guid.Empty)) { throw new ArgumentException("ID is empty!"); } } catch (Exception) { throw; } string pkValue = PartitionKeyGenerator.Create(pkPrefix, id.ToString()); return(await cosmosDBRepo.GetItemAsync(id, pkValue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))); } catch (CosmosException ex) { await CosmosAPI.cosmosDBClientError.AddErrorLog(GetProperty(item, "UserID", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())), ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())); return(null); } }
public async Task <bool> DeleteItemAsync(T item, string pkPrefix, List <string> CallTrace) { try { string id = GetProperty(item, "ID", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).ToString(); string pkValue = PartitionKeyGenerator.Create(pkPrefix, id.ToString()); T deleteItem = await cosmosDBRepo.GetItemAsync(id, pkValue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())); if (deleteItem == null) { return(false); } else { await cosmosDBRepo.DeleteItemAsync(id, pkValue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())); return(true); } } catch (CosmosException ex) { await CosmosAPI.cosmosDBClientError.AddErrorLog(GetProperty(item, "UserID", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())), ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())); return(false); } }
public async Task <CosmosDocUser> FindUserByID(Guid id, List <string> CallTrace) { string pkvalue = PartitionKeyGenerator.Create(pkPrefix, id.ToString()); return(await cosmosDBRepo.FindFirstItemsAsync(x => x.DocType == (int)DocTypeEnum.User && x.ID == id && x.PK == pkvalue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))); }
public async Task <T> GetItemAsync(Guid id, Guid UserID, string pkPrefix, List <string> CallTrace) { try { string pkValue = PartitionKeyGenerator.Create(pkPrefix, id.ToString()); return(await cosmosDBRepo.GetItemAsync(id.ToString(), pkValue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))); } catch (CosmosException ex) { await CosmosAPI.cosmosDBClientError.AddErrorLog(UserID, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())); return(null); } }