//public async Task LoadInitializeMetaData()
        //{
        //    await LoadBatchAsync();
        //    await LoadPartnersAsync();
        //    await LoadOperators();
        //    await LoadMaintainTypeAsync();
        //    await LoadAssetSizeAsync();
        //    await LoadAssetTypeAsync();
        //    await LoadAssetVolumeAsync();
        //    await LoadOwnerAsync();
        //    await LoadDashboardPartnersAsync();
        //    await LoadBrandAsync();
        //    await LoadPartnerTypeAsync();
        //    await LoadGetSkuListAsync();
        //}

        public async Task LoadGetSkuListAsync()
        {
            var RealmDb  = Realm.GetInstance(RealmDbManager.GetRealmDbConfig());
            var response = await ApiManager.GetSkuList(Settings.SessionId);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var data = await Task.Run(() => JsonConvert.DeserializeObject <IList <Sku> >(json, GetJsonSetting()));

                await RealmDb.WriteAsync((realmDb) =>
                {
                    foreach (var item in data)
                    {
                        realmDb.Add(item);
                    }
                });
            }
        }
        public async Task LoadDashboardPartnersAsync()
        {
            var RealmDb = Realm.GetInstance(RealmDbManager.GetRealmDbConfig());

            var result = await ApiManager.GetDashboardPartnersList(Settings.CompanyId, Settings.SessionId);

            if (result.IsSuccessStatusCode)
            {
                var response = await result.Content.ReadAsStringAsync();

                var model = await Task.Run(() => JsonConvert.DeserializeObject <IList <PossessorResponseModel> >(response, GetJsonSetting()));

                var partners = model.Where(x => !string.IsNullOrEmpty(x.Location.FullName)).ToList();
                await RealmDb.WriteAsync((realmDb) =>
                {
                    foreach (var item in partners)
                    {
                        realmDb.Add(item);
                    }
                });
            }
        }
        public async Task LoadBatchAsync()
        {
            var RealmDb = Realm.GetInstance(RealmDbManager.GetRealmDbConfig());

            var response = await ApiManager.GetBatchList(Settings.SessionId);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var data = await Task.Run(() => JsonConvert.DeserializeObject <IList <NewBatch> >(json, GetJsonSetting()));

                var batches = data.Where(p => !string.IsNullOrEmpty(p.BrandName)).OrderBy(x => x.BrandName).ToList();
                await RealmDb.WriteAsync((realmDb) =>
                {
                    foreach (var item in batches)
                    {
                        realmDb.Add(item);
                    }
                });
            }
        }
        public async Task LoadPartnersAsync()
        {
            var RealmDb  = Realm.GetInstance(RealmDbManager.GetRealmDbConfig());
            var response = await ApiManager.GetPartnersList(Settings.SessionId);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var data = await Task.Run(() => JsonConvert.DeserializeObject <IList <PartnerModel> >(json, GetJsonSetting()));

                var Partners = data.Where(x => !string.IsNullOrEmpty(x.FullName)).ToList();

                await RealmDb.WriteAsync((realmDb) =>
                {
                    foreach (var item in Partners)
                    {
                        realmDb.Add(item);
                    }
                });
            }
        }
Exemplo n.º 5
0
        private async void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
        {
            var access   = e.NetworkAccess;
            var profiles = e.ConnectionProfiles;
            var current  = Connectivity.NetworkAccess;

            if (current == NetworkAccess.Internet)
            {
                var RealmDb = Realm.GetInstance(RealmDbManager.GetRealmDbConfig());
                var value   = RealmDb.All <ManifestModel>().Where(x => x.IsQueue).ToList();

                if (value.Count > 0)
                {
                    foreach (var item in value)
                    {
                        switch ((EventTypeEnum)item.EventTypeId)
                        {
                        case EventTypeEnum.MOVE_MANIFEST:
                            var response = await ApiManager.PostManifest(item, Settings.SessionId);

                            if (response.IsSuccessStatusCode)
                            {
                                AddorUpdateManifestOffline(item, false);
                            }
                            break;

                        case EventTypeEnum.SHIP_MANIFEST:
                            break;

                        case EventTypeEnum.RECEIVE_MANIFEST:
                            break;

                        case EventTypeEnum.FILL_MANIFEST:
                            response = await ApiManager.PostManifest(item, Settings.SessionId);

                            if (response.IsSuccessStatusCode)
                            {
                                AddorUpdateManifestOffline(item, false);
                            }
                            break;

                        case EventTypeEnum.PALLETIZE_MANIFEST:

                            break;

                        case EventTypeEnum.RETURN_MANIFEST:
                            break;

                        case EventTypeEnum.REPAIR_MANIFEST:
                            response = await ApiManager.PostMaintenanceDone(item.MaintenanceModels.MaintenanceDoneRequestModel, Settings.SessionId);

                            if (response.IsSuccessStatusCode)
                            {
                                AddorUpdateManifestOffline(item, false);
                            }
                            break;

                        case EventTypeEnum.COLLECT_MANIFEST:
                            break;

                        case EventTypeEnum.ARCHIVE_MANIFEST:
                            break;
                        }
                    }

                    CheckDraftmaniFests checkDraftmaniFests = new CheckDraftmaniFests
                    {
                        IsCheckDraft = true
                    };
                    MessagingCenter.Send(checkDraftmaniFests, "CheckDraftmaniFests");
                }

                var pallets = RealmDb.All <PalletRequestModel>().Where(x => x.IsQueue).ToList();

                if (pallets.Count > 0)
                {
                    foreach (var pallet in pallets)
                    {
                        var response = await ApiManager.PostPallet(pallet, Settings.SessionId);

                        AddorUpdatePalletsOffline(pallet);
                    }

                    CheckDraftmaniFests checkDraftmaniFests = new CheckDraftmaniFests
                    {
                        IsCheckDraft = true
                    };
                    MessagingCenter.Send(checkDraftmaniFests, "CheckDraftmaniFests");
                }
            }
        }