Untitled

 avatar
unknown
plain_text
a year ago
1.2 kB
1
Indexable
        private async Task<int> CountCoursesAmount(string selectedDatabase, string selectedTableName, string idToChk)
        {
            int res = 0;
            Microsoft.Azure.Cosmos.Container table;
            try
            {
                table =
                    cosmosClient.GetContainer(selectedDatabase, selectedTableName);
            }
            catch
            {
                return 0;
            }
            try
            {
                Microsoft.Azure.Cosmos.ItemResponse<Student> requestedItem =
                await table.ReadItemAsync<Student>(idToChk,
                                            new Microsoft.Azure.Cosmos.PartitionKey(idToChk));
                //Count the addresses of the current id
                Student student = requestedItem.Resource;
                if (student != null)
                {
                    if (student.Courses != null)
                    {
                        res = student.Courses.Length;
                    }
                }

            }
            catch
            {
                res = 0;
            }

            return res;
        }
Leave a Comment