示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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())));
        }
示例#4
0
        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);
            }
        }