Ejemplo n.º 1
0
        public async void EditSource(WallpaperSource source)
        {
            if (source.Source == Source.Reddit || source.Source == Source.Local)
            {
                await _dialog.ShowMessageAsync("Error", "There are no options to edit on Reddit sources!");

                return;
            }
            source.WallhavenOptions = await _db.GetWallhavenOptions(source);

            var wallhavenDialog = new WallhavenDialog("Edit Wallhaven Source options")
            {
                Query   = source.Query,
                General = Convert.ToBoolean(source.WallhavenOptions.General),
                Anime   = Convert.ToBoolean(source.WallhavenOptions.Anime),
                People  = Convert.ToBoolean(source.WallhavenOptions.People),
                SFW     = Convert.ToBoolean(source.WallhavenOptions.SFW),
                Sketchy = Convert.ToBoolean(source.WallhavenOptions.Sketchy),
            };

            if (!string.IsNullOrEmpty(source.WallhavenOptions.Resolution))
            {
                source.WallhavenOptions.Resolution.Split(',').AsParallel().ForAll(x => wallhavenDialog.Resolutions.FirstOrDefault(y => y.ObjectData == x).IsSelected = true);
            }
            if (!string.IsNullOrEmpty(source.WallhavenOptions.Ratio))
            {
                source.WallhavenOptions.Ratio.Split(',').AsParallel().ForAll(x => wallhavenDialog.Ratios.FirstOrDefault(y => y.ObjectData == x).IsSelected = true);
            }
            var editedSource = (WallpaperSource)await _dialog.ShowCustomDialog(wallhavenDialog);

            if (editedSource == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(editedSource.Query))
            {
                await _dialog.ShowMessageAsync("Error", "The search query cannot be blank");

                return;
            }
            source = editedSource;
            await _db.EditSource(source);
        }