public async Task <ApiResponse <List <T> > > FindNetmeraContents <T>(string table, string idField, List <string> idValues)
        {
            NetmeraService service = new NetmeraService(table);

            service.whereContainedIn(idField, idValues);

            var items = await SearchObjects <T>(service);

            return(items);
        }
Пример #2
0
        void ImportSurveyoyr(string surveyorId, SqlConnection connection)
        {
            var addressService = new NetmeraService("Address_List1");

            addressService.whereEqual("Surveyor", surveyorId);

            var surveyor = DbContext.Surveyors.First(x => x.NetmeraId == surveyorId);


            SearchObjectsWithPaging <Address, AddressOld>(addressService, (db, s) =>
            {
                db.NetmeraId   = s.AddressID;
                db.SurveyorId  = surveyor.Id;
                db.TypeUpdated = s.PTUpdated;
                db.IsCompleted = s.Complete;
                db.UpdateDate  = db.CreateDate;

                var status         = new AddressStatus();
                status.IsCompleted = s.Complete;
                status.AddressId   = db.Id;

                return(false);
            });


            var downloadedAddresses = DbContext.Addresses.Where(x => x.SurveyorId == surveyor.Id).ToList();
            var page = 100;

            for (int i = 0; i < downloadedAddresses.Count; i = i + page)
            {
                var addresses = downloadedAddresses.Skip(i).Take(page);

                var service = new NetmeraService("Survelem");

                service.whereContainedIn("UPRN", addresses.Select(x => x.UPRN).ToList());

                ProcessSurvelems(service, connection);
            }
        }
        async Task <ApiResponse <Address> > ExecuteSyncUserData(long userId)
        {
            var surveyTypes = await SearchObjects <SurveyTypes>(new NetmeraService("SurveyTypes"));

            if (surveyTypes.IsSuccess)
            {
                await new DbService().ClearTable <SurveyTypes>();

                foreach (var surveyTypese in surveyTypes.Data.Distinct())
                {
                    surveyTypese.Identity = surveyTypese.ID;
                    await new DbService().Save(surveyTypese);
                }
            }
            else
            {
                return(new ApiResponse <Address>()
                {
                    IsSuccess = false
                });
            }


            var foundCustomers = await GetCustomers(userId);

            foreach (var foundCustomer in foundCustomers)
            {
                foundCustomer.Identity = foundCustomer.CustomerID.ToString();
                await new DbService().Save(foundCustomer);
            }

            NetmeraService service2 = new NetmeraService("Address_List1");

            service2.whereEqual("Surveyor", userId.ToString());
            service2.whereEqual("Complete", false);


            //var addresses = await SearchObjects<Address>(service2);
            var addresses = await SearchObjectsWithPaging <Address>(service2);

            var downloadedAddresses = new List <Address>();

            if (addresses.IsSuccess)
            {
                var insert = new List <Address>();
                foreach (var address in addresses.Data)
                {
                    if (foundCustomers.Any(x => x.CustomerSurveyID.ToString() == address.CustomerSurveyID.ToString()))
                    {
                        address.Identity = address.AddressID;

                        if (string.IsNullOrEmpty(address.FullAddress))
                        {
                            address.FullAddress = "";
                        }

                        if (!insert.Any(x => x.Identity == address.Identity))
                        {
                            insert.Add(address);
                            downloadedAddresses.Add(address);
                        }
                    }
                }

                await new DbService().Insert(insert);
            }
            else
            {
                return(new ApiResponse <Address>()
                {
                    IsSuccess = false
                });
            }


            var r = await DownloadQuestionsAndOptions(foundCustomers);

            if (!r.IsSuccess)
            {
                return(r);
            }
            //var questions = await SearchObjects<Question>(new NetmeraService("Questions"));
            //var questions = await SearchObjectsWithPaging<Question>(new NetmeraService("Questions"));

            //if (questions.IsSuccess)
            //{
            //    var insert = new List<Question>();
            //    foreach (var question in questions.Data)
            //    {
            //        if (foundCustomers.Any(x => x.CustomerSurveyID == question.CustomerSurveyID))
            //        {
            //            question.Identity = question.Question_Ref;
            //            if (!insert.Any(x => x.Identity == question.Identity))
            //                insert.Add(question);

            //        }
            //    }

            //    await new DbService().Insert(insert);
            //}
            //else
            //{
            //    return new ApiResponse<Address>() { IsSuccess = false };
            //}

            //var options = await SearchObjectsWithPaging<Option>(new NetmeraService("Options"));
            ////var options = await SearchObjects<Option>(new NetmeraService("Options"));

            //if (options.IsSuccess)
            //{
            //    var insert = new List<Option>();
            //    foreach (var option in options.Data)
            //    {
            //        if (foundCustomers.Any(x => x.CustomerSurveyID == option.CustomerSurveyID))
            //        {
            //            option.Identity = option.OptionId;
            //            if (!insert.Any(x => x.Identity == option.Identity))
            //                insert.Add(option);


            //        }
            //    }
            //    await new DbService().Insert(insert);
            //}
            //else
            //{
            //    return new ApiResponse<Address>() { IsSuccess = false };
            //}



            var media = await SearchObjects <RichMedia>(new NetmeraService("RichMedia"));

            if (media.IsSuccess)
            {
                var insert = new List <RichMedia>();
                foreach (var option in media.Data)
                {
                    if (foundCustomers.Any(x => x.CustomerSurveyID == option.CustomerSurveyID))
                    {
                        option.Identity = option.ID;
                        if (!insert.Any(x => x.Identity == option.Identity))
                        {
                            insert.Add(option);
                        }
                    }
                }
                await new DbService().Insert(insert);
            }
            else
            {
                return(new ApiResponse <Address>()
                {
                    IsSuccess = false
                });
            }

            var page = 100;

            for (int i = 0; i < downloadedAddresses.Count; i = i + page)
            {
                var survelemSearch = new NetmeraService("Survelem");

                survelemSearch.whereContainedIn("UPRN", downloadedAddresses.Skip(i).Take(page).Select(x => x.UPRN).ToList());

                //var survelems = await SearchObjects<Survelem>(survelemSearch);
                var survelems = await SearchObjectsWithPaging <Survelem>(survelemSearch);

                if (survelems.IsSuccess)
                {
                    var insert = new List <Survelem>();
                    foreach (var option in survelems.Data)
                    {
                        if (foundCustomers.Any(x => x.CustomerSurveyID == option.CustomerSurveyID))
                        {
                            option.Identity = option.id;
                            if (!insert.Any(x => x.Identity == option.Identity))
                            {
                                insert.Add(option);
                            }
                        }
                    }
                    await new DbService().Insert(insert);
                }
                else
                {
                    return(new ApiResponse <Address>()
                    {
                        IsSuccess = false
                    });
                }
            }



            var survelemMaps = await SearchObjects <SurvelemMap>(new NetmeraService("TblSurvelemMap"));

            if (survelemMaps.IsSuccess)
            {
                var insert = new List <SurvelemMap>();
                foreach (var option in survelemMaps.Data)
                {
                    if (foundCustomers.Any(x => x.CustomerSurveyID == option.CustomerSurveyID))
                    {
                        option.Identity = option.SvmMapID;
                        if (!insert.Any(x => x.Identity == option.Identity))
                        {
                            insert.Add(option);
                        }
                    }
                }
                await new DbService().Insert(insert);
            }
            else
            {
                return(new ApiResponse <Address>()
                {
                    IsSuccess = false
                });
            }

            return(new ApiResponse <Address>()
            {
                IsSuccess = true
            });
        }