Пример #1
0
        public HistoriqueViewModel()
        {
            SelectedStatut   = new StatutModel();
            LoadMoreCommande = new Command(
                execute: async() =>
            {
                _isLoadinMore = true;

                #region Get data from API

                /*if (FilterStationDemandes.StartDate != null || FilterStationDemandes.EndDate != null || !string.IsNullOrEmpty(FilterStationDemandes.StatutId))
                 * {
                 *  await GetFilteredDemandes(FilterStationDemandes, _filterCurentPage);
                 * }
                 * else
                 * {
                 *  await GetDemandes(_curentPage + 1);
                 * }*/
                #endregion

                #region Get data from Local JSON
                await GetDemandesJsonData();
                #endregion
            },
                canExecute: () =>
            {
                return(!_isLoadinMore);
            }
                );
            RefreshCommand = new Command(
                execute: async() =>
            {
                _isRefreshing = true;

                // Get data from API
                //await GetDemandes(_curentPage);

                // Get data from Local JSON
                await GetDemandesJsonData();
            },
                canExecute: () =>
            {
                return(!_isRefreshing);
            }
                );
            FilterCommande = new Command(
                execute: async() =>
            {
                return;

                if (
                    FilterStationDemandes.StartDate == DateTime.Now.Date &&
                    FilterStationDemandes.EndDate == DateTime.Now.Date &&
                    string.IsNullOrEmpty(SelectedStatut?.id))
                {
                    return;
                }

                //if (IsInitValue) return;


                _isFilterinMore = true;

                _filterCurentPage = 1;
                _filterLastPage   = 0;

                if (!string.IsNullOrEmpty(SelectedStatut?.id))
                {
                    FilterStationDemandes.StatutId = SelectedStatut.id;
                }

                await GetFilteredDemandes(FilterStationDemandes, _filterCurentPage);
            },
                canExecute: () =>
            {
                return(!_isFilterinMore);
            }
                );
            CancelFilterCommande = new Command(
                execute: () =>
            {
                //IsInitValue = true;

                SelectedStatut        = new StatutModel();
                FilterStationDemandes = new FilterStationDemandesModel();
            }
                );
        }
Пример #2
0
        public static async Task <RESTServiceResponse <PaginateDemandeModel> > FilterStationDemandes(int page, FilterStationDemandesModel filterStationDemandes, int offset = 0)
        {
            try
            {
                string url = string.Concat(AppUrls.FilterStationDemandes, 1 /*, AppSettings.UserId*/, "?page=" + page, (offset != 0) ? "&offset=" + offset : "");

                return(await RESTHelper.GetRequest <PaginateDemandeModel>(url : url, token : AppSettings.AccessToken, method : HttpVerbs.POST, postObject : filterStationDemandes));
            }
            catch (Exception ex)
            {
                return(new RESTServiceResponse <PaginateDemandeModel>()
                {
                    success = false, message = $"Erreur: {ex.Message}"
                });
            }
        }
Пример #3
0
        private async Task GetFilteredDemandes(FilterStationDemandesModel FilterStationDemandes, int page)
        {
            try
            {
                //if (
                //    FilterStationDemandes.StartDate == default &&
                //    FilterStationDemandes.EndDate == default &&
                //    string.IsNullOrEmpty(FilterStationDemandes?.StatutId))
                //{
                //    return;
                //}

                //if (FilterStationDemandes?.StartDate == null && FilterStationDemandes?.EndDate == null && string.IsNullOrEmpty(FilterStationDemandes?.StatutId))


                if (page < _filterLastPage || _filterLastPage == 0)
                {
                    AppHelper.ALoadingShow("Chargement...");

                    var RequestResult = new RESTServiceResponse <PaginateDemandeModel>();
                    if (Offset != 0)
                    {
                        RequestResult = await ApiCalls.FilterStationDemandes(page, FilterStationDemandes, Offset);
                    }
                    else
                    {
                        RequestResult = await ApiCalls.FilterStationDemandes(page, filterStationDemandes : FilterStationDemandes);
                    }

                    if (RequestResult.success)
                    {
                        _filterCurentPage = RequestResult.data.current_page;
                        _filterLastPage   = RequestResult.data.last_page;

                        if (_filterCurentPage == 1)
                        {
                            StationDemandes.Clear();
                        }

                        if (RequestResult.data.data.Count == 0)
                        {
                            RefreshBtnVisible = true;
                            ContentVisible    = false;
                        }
                        else
                        {
                            foreach (var item in RequestResult.data.data)
                            {
                                StationDemandes.Add(item);
                            }
                            ContentVisible    = true;
                            RefreshBtnVisible = false;
                        }

                        _filterCurentPage++;
                    }
                    else
                    {
                        if (StationDemandes.Count <= 0)
                        {
                            ContentVisible    = false;
                            RefreshBtnVisible = true;
                        }
                        AppHelper.ASnack(message: RequestResult.message, type: SnackType.Error);
                    }
                }
                else
                {
                    AppHelper.ASnack(message: Assets.Strings.NoMoreResultMessage, type: SnackType.Info);
                }
            }
            catch (Exception ex)
            {
                AppHelper.ASnack(message: Assets.Strings.ErreurMessage, type: SnackType.Error);
            }
            finally
            {
                AppHelper.ALoadingHide();
            }
        }