Exemplo n.º 1
0
        public async Task LoadConditions()
        {
            try
            {
                ConditionsLoading = true;
                var results = await seasonIndexAPI.Condition((int)Parameter.type).Request();

                if (results.status)
                {
                    var data = results.GetJObject();
                    if (data["code"].ToInt32() == 0)
                    {
                        var items = JsonConvert.DeserializeObject <ObservableCollection <SeasonIndexConditionFilterModel> >(data["result"]["filter"].ToString());
                        foreach (var item in items)
                        {
                            if (item.id == "style_id")
                            {
                                item.current = item.value.FirstOrDefault(x => x.id == Parameter.style);
                            }
                            else if (item.id == "area")
                            {
                                item.current = item.value.FirstOrDefault(x => x.id == Parameter.area);
                            }
                            else if (item.id == "pub_date")
                            {
                                item.current = item.value.FirstOrDefault(x => x.id == Parameter.year);
                            }
                            else if (item.id == "season_month")
                            {
                                item.current = item.value.FirstOrDefault(x => x.id == Parameter.month);
                            }
                            else
                            {
                                item.current = item.value.FirstOrDefault();
                            }
                        }
                        var orders = new List <SeasonIndexConditionFilterItemModel>()
                        {
                            new SeasonIndexConditionFilterItemModel()
                            {
                                id   = "3",
                                name = "最多追" + ((Parameter.type == IndexSeasonType.Anime)?"番":"剧")
                            },
                            new SeasonIndexConditionFilterItemModel()
                            {
                                id   = "0",
                                name = "最近更新"
                            },
                            new SeasonIndexConditionFilterItemModel()
                            {
                                id   = "4",
                                name = "最高评分"
                            }
                        };
                        items.Insert(0, new SeasonIndexConditionFilterModel()
                        {
                            name    = "排序",
                            value   = orders,
                            id      = "order",
                            current = orders.FirstOrDefault(x => x.id == Parameter.order),
                        });
                        Conditions = items;
                    }
                    else
                    {
                        Utils.ShowMessageToast(data["message"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                var handel = HandelError <SeasonIndexConditionFilterModel>(ex);
                Utils.ShowMessageToast(handel.message);
            }
            finally
            {
                ConditionsLoading = false;
            }
        }
Exemplo n.º 2
0
        public async Task LoadConditions()
        {
            try
            {
                ConditionsLoading = true;
                var results = await seasonIndexAPI.Condition((int)Parameter.type).Request();

                if (results.status)
                {
                    var data = results.GetJObject();
                    if (data["code"].ToInt32() == 0)
                    {
                        var items = JsonConvert.DeserializeObject <ObservableCollection <SeasonIndexConditionFilterModel> >(data["data"]["filter"].ToString());
                        foreach (var item in items)
                        {
                            if (item.field == "style_id")
                            {
                                item.current = item.values.FirstOrDefault(x => x.keyword == Parameter.style);
                            }
                            else if (item.field == "area")
                            {
                                item.current = item.values.FirstOrDefault(x => x.keyword == Parameter.area);
                            }
                            else if (item.field == "pub_date")
                            {
                                item.current = item.values.FirstOrDefault(x => x.keyword == Parameter.year);
                            }
                            else if (item.field == "season_month")
                            {
                                item.current = item.values.FirstOrDefault(x => x.keyword == Parameter.month);
                            }
                            else
                            {
                                item.current = item.values.FirstOrDefault();
                            }
                        }
                        var orders = new List <SeasonIndexConditionFilterItemModel>();

                        foreach (var item in data["data"]["order"])
                        {
                            orders.Add(new SeasonIndexConditionFilterItemModel()
                            {
                                keyword = item["field"].ToString(),
                                name    = item["name"].ToString()
                            });
                        }

                        items.Insert(0, new SeasonIndexConditionFilterModel()
                        {
                            name    = "排序",
                            values  = orders,
                            field   = "order",
                            current = orders.FirstOrDefault(x => x.name == Parameter.order) ?? orders[0],
                        });
                        Conditions = items;
                    }
                    else
                    {
                        Utils.ShowMessageToast(data["message"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                var handel = HandelError <SeasonIndexConditionFilterModel>(ex);
                Utils.ShowMessageToast(handel.message);
            }
            finally
            {
                ConditionsLoading = false;
            }
        }