Ejemplo n.º 1
0
        public async Task <List <SiteWorkerDto> > SiteWorkerLoadAllFromRemote()
        {
            log.LogEverything("Communicator.SiteWorkerLoadAllFromRemote", "called");

            var parsedData           = JRaw.Parse(await http.SiteWorkerLoadAllFromRemote());
            List <SiteWorkerDto> lst = new List <SiteWorkerDto>();

            foreach (JToken item in parsedData)
            {
                int           microtingUid = int.Parse(item["id"].ToString());
                int           siteUId      = int.Parse(item["site_id"].ToString());
                int           workerUId    = int.Parse(item["user_id"].ToString());
                SiteWorkerDto temp         = new SiteWorkerDto(microtingUid, siteUId, workerUId);
                lst.Add(temp);
            }
            return(lst);
        }
        public async Task SQL_SiteWorker_SiteWorkerRead_ReadsSiteWorker()
        {
            // Arrance

            #region Arrance

            #region Checklist
            DateTime    cl1_Ca = DateTime.Now;
            DateTime    cl1_Ua = DateTime.Now;
            check_lists Cl1    = await testHelpers.CreateTemplate(cl1_Ca, cl1_Ua, "A1", "D1", "caseType1", "WhereItIs", 1, 0);

            #endregion

            #region SubCheckList

            check_lists Cl2 = await testHelpers.CreateSubTemplate("A2", "D2", "caseType2", 2, 0, Cl1);

            #endregion

            #region Fields

            #region field1


            fields f1 = await testHelpers.CreateField(1, "barcode", Cl2, "e2f4fb", "custom", null, "", "Comment field description",
                                                      5, 1, dbContext.field_types.Where(x => x.FieldType == "picture").First(), 0, 0, 1, 0, "Comment field", 1, 55, "55", "0", 0, 0, null, 1, 0,
                                                      0, 0, "", 49);

            #endregion

            #region field2


            fields f2 = await testHelpers.CreateField(1, "barcode", Cl2, "f5eafa", "custom", null, "", "showPDf Description",
                                                      45, 1, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 0, 1, 0, 0,
                                                      "ShowPdf", 0, 5, "5", "0", 0, 0, null, 0, 0, 0, 0, "", 9);


            #endregion

            #region field3

            fields f3 = await testHelpers.CreateField(0, "barcode", Cl2, "f0f8db", "custom", 3, "", "Number Field Description",
                                                      83, 0, dbContext.field_types.Where(x => x.FieldType == "picture").First(), 0, 0, 1, 0,
                                                      "Numberfield", 1, 8, "4865", "0", 0, 1, null, 1, 0, 0, 0, "", 1);


            #endregion

            #region field4


            fields f4 = await testHelpers.CreateField(1, "barcode", Cl2, "fff6df", "custom", null, "", "date Description",
                                                      84, 0, dbContext.field_types.Where(x => x.FieldType == "picture").First(), 0, 0, 1, 0,
                                                      "Date", 1, 666, "41153", "0", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field5

            fields f5 = await testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                      85, 0, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 1, 0, 1, 0,
                                                      "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field6

            fields f6 = await testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                      86, 0, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 1, 0, 1, 0,
                                                      "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field7

            fields f7 = await testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                      87, 0, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 1, 0, 1, 0,
                                                      "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field8

            fields f8 = await testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                      88, 0, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 1, 0, 1, 0,
                                                      "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field9

            fields f9 = await testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                      89, 0, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 1, 0, 1, 0,
                                                      "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field10

            fields f10 = await testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                       90, 0, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 1, 0, 1, 0,
                                                       "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #endregion

            #region Workers

            #region worker1
            workers worker1 = await testHelpers.CreateWorker("*****@*****.**", "Arne", "Jensen", 21);

            #endregion

            #region worker2
            workers worker2 = await testHelpers.CreateWorker("*****@*****.**", "Lasse", "Johansen", 44);

            #endregion

            #region worker3
            workers worker3 = await testHelpers.CreateWorker("*****@*****.**", "Svend", "Jensen", 22);

            #endregion

            #region worker4
            workers worker4 = await testHelpers.CreateWorker("*****@*****.**", "Bjarne", "Nielsen", 23);

            #endregion

            #region worker5
            workers worker5 = await testHelpers.CreateWorker("*****@*****.**", "Ib", "Hansen", 24);

            #endregion

            #region worker6
            workers worker6 = await testHelpers.CreateWorker("*****@*****.**", "Hozan", "Aziz", 25);

            #endregion

            #region worker7
            workers worker7 = await testHelpers.CreateWorker("*****@*****.**", "Nicolai", "Peders", 26);

            #endregion

            #region worker8
            workers worker8 = await testHelpers.CreateWorker("*****@*****.**", "Amin", "Safari", 27);

            #endregion

            #region worker9
            workers worker9 = await testHelpers.CreateWorker("*****@*****.**", "Leo", "Rebaz", 28);

            #endregion

            #region worker10
            workers worker10 = await testHelpers.CreateWorker("*****@*****.**", "Stig", "Berthelsen", 29);

            #endregion

            #endregion

            #region sites

            #region Site1
            sites site1 = await testHelpers.CreateSite("SiteName1", 88);

            #endregion

            #region Site2
            sites site2 = await testHelpers.CreateSite("SiteName2", 89);

            #endregion

            #region Site3
            sites site3 = await testHelpers.CreateSite("SiteName3", 90);

            #endregion

            #region Site4
            sites site4 = await testHelpers.CreateSite("SiteName4", 91);

            #endregion

            #region Site5
            sites site5 = await testHelpers.CreateSite("SiteName5", 92);

            #endregion

            #region Site6
            sites site6 = await testHelpers.CreateSite("SiteName6", 93);

            #endregion

            #region Site7
            sites site7 = await testHelpers.CreateSite("SiteName7", 94);

            #endregion

            #region Site8
            sites site8 = await testHelpers.CreateSite("SiteName8", 95);

            #endregion

            #region Site9
            sites site9 = await testHelpers.CreateSite("SiteName9", 96);

            #endregion

            #region Site10
            sites site10 = await testHelpers.CreateSite("SiteName10", 97);

            #endregion

            #endregion

            #region units
            units unit = await testHelpers.CreateUnit(48, 49, site1, 348);

            #endregion

            #region site_workers
            site_workers site_workers = await testHelpers.CreateSiteWorker(55, site1, worker1);

            #endregion

            #endregion

            // Act

            SiteWorkerDto match = await sut.SiteWorkerRead(site_workers.MicrotingUid, site1.Id, worker1.Id);

            // Assert

            Assert.AreEqual(site_workers.MicrotingUid, match.MicrotingUId);
            Assert.AreEqual(site_workers.Worker.MicrotingUid, match.WorkerUId);
            Assert.AreEqual(site_workers.Site.MicrotingUid, match.SiteUId);
        }
Ejemplo n.º 3
0
        public async Task <string> DbSetup(string token)
        {
//            try
//            {
            DbContextHelper dbContextHelper = new DbContextHelper(connectionString);

            sqlController = new SqlController(dbContextHelper);

            if (token == null)
            {
                token = await sqlController.SettingRead(Settings.token);
            }

            await sqlController.SettingUpdate(Settings.token, token);

            // configure db
            await DbSettingsReloadRemote();


            string comAddressApi = await sqlController.SettingRead(Settings.comAddressApi);

            string comAddressBasic = await sqlController.SettingRead(Settings.comAddressBasic);

            string comOrganizationId = await sqlController.SettingRead(Settings.comOrganizationId);

            string ComAddressPdfUpload = await sqlController.SettingRead(Settings.comAddressPdfUpload);

            string ComSpeechToText = await sqlController.SettingRead(Settings.comSpeechToText);

            Communicator communicator = new Communicator(token, comAddressApi, comAddressBasic, comOrganizationId, ComAddressPdfUpload, log, ComSpeechToText);

            #region add site's data to db
            if (!bool.Parse(await sqlController.SettingRead(Settings.knownSitesDone)))
            {
                foreach (var item in await communicator.SiteLoadAllFromRemote())
                {
                    SiteNameDto siteDto = await sqlController.SiteRead(item.SiteUId);

                    if (siteDto == null)
                    {
                        await sqlController.SiteCreate(item.SiteUId, item.SiteName);
                    }
                }

                foreach (var item in await communicator.WorkerLoadAllFromRemote())
                {
                    WorkerDto workerDto = await sqlController.WorkerRead(item.WorkerUId);

                    if (workerDto == null)
                    {
                        await sqlController.WorkerCreate(item.WorkerUId, item.FirstName, item.LastName, item.Email);
                    }
                }

                foreach (var item in await communicator.SiteWorkerLoadAllFromRemote())
                {
                    SiteWorkerDto siteWorkerDto = await sqlController.SiteWorkerRead(item.MicrotingUId, null, null);

                    if (siteWorkerDto == null)
                    {
                        try
                        {
                            await sqlController.SiteWorkerCreate(item.MicrotingUId, item.SiteUId, item.WorkerUId);
                        }
                        catch
                        {
                            // We do catch this because right now we a descripency at the API side.
                        }
                    }
                }

                int customerNo = communicator.OrganizationLoadAllFromRemote(token).Result.CustomerNo;

                foreach (var item in await communicator.UnitLoadAllFromRemote(customerNo))
                {
                    UnitDto unitDto = await sqlController.UnitRead(item.UnitUId);

                    if (unitDto == null)
                    {
                        try
                        {
                            await sqlController.UnitCreate(item.UnitUId, item.CustomerNo, item.OtpCode, item.SiteUId);
                        }
                        catch
                        {
                            // We do catch this because right now we a descripency at the API side.
                        }
                    }
                }

                foreach (FolderDto folderDto in await communicator.FolderLoadAllFromRemote())
                {
                    if (folderDto.MicrotingUId != null)
                    {
                        FolderDto folder = await sqlController.FolderReadByMicrotingUUID((int)folderDto.MicrotingUId);

                        if (folder == null)
                        {
                            if (folderDto.ParentId == 0)
                            {
                                await sqlController.FolderCreate(folderDto.Name, folderDto.Description, null,
                                                                 (int)folderDto.MicrotingUId);
                            }
                            else
                            {
                                if (folderDto.ParentId != null)
                                {
                                    FolderDto parenFolder =
                                        await sqlController.FolderReadByMicrotingUUID((int)folderDto.ParentId);

                                    await sqlController.FolderCreate(folderDto.Name, folderDto.Description, parenFolder.Id,
                                                                     (int)folderDto.MicrotingUId);
                                }
                            }
                        }
                    }
                }

                await sqlController.SettingUpdate(Settings.knownSitesDone, "true");
            }
            #endregion

            await sqlController.SettingUpdate(Settings.firstRunDone, "true");

            return("");
//            }
//            catch (Exception ex)
//            {
//                return t.PrintException(t.GetMethodName("AdminTools") + " failed", ex);
//            }
        }