Exemple #1
0
        public static async Task <bool> IsEmployeeExists(string empNum, CosmosDBRepository <User> client)
        {
            var results = await client.GetItemsAsync((u) => u.AccountId == empNum && u.AccountType == "Employee" && u.IsActive);

            if (results.Count() > 0)
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public static async Task <User> GetEmployeeById(string empId, CosmosDBRepository <User> client)
        {
            var results = await client.GetItemsAsync((u) => u.Id == empId && u.AccountType == "Employee" && u.IsActive);

            if (results.Count() > 0)
            {
                return(results.ElementAt(0));
            }
            return(null);
        }
        private async Task <ODMWorkspace> GetOrCreateWorkspaceAsync(string ownerId)
        {
            List <ODMWorkspace> workspaceLockup = await workspaceRepo.GetItemsAsync(x => x.OwnerId == ownerId) as List <ODMWorkspace>;

            //No workspace found for OwnerId
            if (workspaceLockup.Count == 0)
            {
                activeWorkspace = await CreateWorkspaceAsync(ownerId, new ModelPolicy());
            }
            else
            {
                //TODO: Add logic to handle multiple workspaces for same owner. for now only a single workspace for owner is supported.
                activeWorkspace = workspaceLockup[0];
            }

            filesBlobContainer  = new AzureBlobStorageRepository(blobStorageName, blobStorageKey, activeWorkspace.FilesCotainerUri);
            modelsBlobContainer = new AzureBlobStorageRepository(blobStorageName, blobStorageKey, activeWorkspace.ModelCotainerUri);

            return(activeWorkspace);
        }
Exemple #4
0
        public async Task <IActionResult> Search([FromQuery] string q)
        {
            if (string.IsNullOrEmpty(q))
            {
                return(BadRequest());
            }

            var querySql = this.context.GenerateQuery(q).Trim();
            var result   = await repository.GetItemsAsync(querySql);

            return(Ok(result));
        }
Exemple #5
0
        public static async Task <string> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            // Get CosmosDB Connection
            var Repository = new CosmosDBRepository("VMManagement", "VM_Power_State", log);

            log.LogInformation("RUN-MESSAGE 1 (GW 1103): Got CosmosDB Connection");

            // Get CosmosDB Data
            var CosmosItems = await Repository.GetItemsAsync();

            log.LogInformation("RUN-MESSAGE 2: Got CosmosDB Items", CosmosItems);

            var jsonCosmosItems = JsonConvert.SerializeObject(CosmosItems, Formatting.Indented);

            return(jsonCosmosItems);
        }
Exemple #6
0
        public static async void Run([TimerTrigger("0/20 * * * * *")] TimerInfo myTimer, ILogger log)
        {
            try
            {
                // Get Connections
                var Repository = new CosmosDBRepository("VMManagement", "VM_Power_State", log);
                var Connection = new AzureConnection("11c4bafa-00bb-43f4-a42d-ed6f2663fbaf",
                                                     "92c95553-455f-4b53-8bcf-e2dfe4dbcb0b",
                                                     "A4LbQRKmqT:2x4Iu/h=yM=pDBuu9VVA1",
                                                     log);


                log.LogInformation("RUN-MESSAGE 1 (AW 0903): Got Connections");

                // Get Data
                var CosmosItems = await Repository.GetItemsAsync();


                log.LogInformation($"RUN-MESSAGE 2: Got {CosmosItems.Count} items from CosmosDB.");

                var AzureMachines = Connection.VirtualMachines;

                log.LogInformation($"RUN-MESSAGE 3: Got {AzureMachines.Count} items from Azure VMs.");

                // Check if any data needs updating
                var toBeUpdated = CompareItems(CosmosItems, AzureMachines, log);

                if (toBeUpdated.Any())
                {
                    log.LogInformation($"RUN-MESSAGE 5: Got {toBeUpdated.Count} items to be updated.");

                    foreach (var cosmosItem in toBeUpdated)
                    {
                        // Update any data requiring updates
                        await Repository.UpdateItemAsync(cosmosItem);
                    }
                }
            }
            catch (Exception ex)
            {
                log.LogError(ex, $"ERROR-RUN in Function. Message: {ex.Message}; InnerException: {ex.InnerException}");
            }
        }
Exemple #7
0
        private void FillInitialData()
        {
            DoctorManager  doctorManager;
            PatientManager patientManager;
            var            list = _doctorContext.GetItemsAsync(y => y.Name != "").Result.ToList();

            if (list.Count < 3)
            {
                doctorManager = new DoctorManager(_doctorContext);
                var x = doctorManager.CreateAsync(new Doctor()
                {
                    Name       = "Mikael Seström",
                    Email      = "*****@*****.**",
                    ItemId     = "201012-1425",
                    Speciality = new Speciality()
                    {
                        Id   = "3",
                        Name = "Clinical radiology"
                    },
                    Description = ""
                });

                x = doctorManager.CreateAsync(new Doctor()
                {
                    Name       = "Carina Axel",
                    Email      = "*****@*****.**",
                    ItemId     = "200911-1758",
                    Speciality = new Speciality()
                    {
                        Id   = "2",
                        Name = "Anaesthesia"
                    },
                    Description = ""
                });

                x = doctorManager.CreateAsync(new Doctor()
                {
                    Name       = "Martin Eriksson",
                    Email      = "*****@*****.**",
                    ItemId     = "199005-1875",
                    Speciality = new Speciality()
                    {
                        Id   = "1",
                        Name = "Clinical oncology"
                    },
                    Description = ""
                });
            }

            var list2 = _patientContext.GetItemsAsync(y => y.Name != "").Result.ToList();

            if (list2.Count < 3)
            {
                patientManager = new PatientManager(_patientContext);
                var x = patientManager.CreateAsync(new Patient()
                {
                    Name    = "Henrik Karlsson",
                    Email   = "*****@*****.**",
                    ItemId  = "19860813-1111",
                    Address = new Address()
                    {
                        ItemId  = "111",
                        ZipCode = "121211"
                    },
                    Description = ""
                });

                x = patientManager.CreateAsync(new Patient()
                {
                    Name    = "Erik Henriksson",
                    Email   = "*****@*****.**",
                    ItemId  = "19750612-2222",
                    Address = new Address()
                    {
                        ItemId  = "112",
                        ZipCode = "121211"
                    },
                    Description = ""
                });

                x = patientManager.CreateAsync(new Patient()
                {
                    Name    = "Cecilia Eliasson",
                    Email   = "*****@*****.**",
                    ItemId  = "19600519-3333",
                    Address = new Address()
                    {
                        ItemId  = "113",
                        ZipCode = "122122"
                    },
                    Description = ""
                });
            }
        }
        public async Task <IEnumerable <Book> > Get()
        {
            var result = await CosmosDBRepository <Book> .GetItemsAsync(CollectionId);

            return(result);
        }