Ejemplo n.º 1
0
        private async void RemoveImage(object o)
        {
            var selectedItem = o as INavigatorListEntry;

            if (!selectedItem.DbId.HasValue)
            {
                return;
            }

            var mySettings = new MetroDialogSettings
            {
                AffirmativeButtonText = "Yes",
                NegativeButtonText    = "No",
                ColorScheme           = MetroDialogColorScheme.Accented
            };
            var result = await _view.ShowMessageDialog("Remove Element", $"Are you sure you want to remove this element from database?", MessageDialogStyle.AffirmativeAndNegative, mySettings);

            if (result == MessageDialogResult.Affirmative)
            {
                await Task.Run(() =>
                {
                    ImoutoService.Use(imoutoService =>
                    {
                        imoutoService.RemoveImage(selectedItem.DbId.Value);
                    });
                });

                // NavigatorList.Remove(selectedItem);

                await _view.ShowMessageDialog("Remove Element", "Element successfully removed.", MessageDialogStyle.Affirmative, new MetroDialogSettings
                {
                    ColorScheme = MetroDialogColorScheme.Accented
                });
            }
        }
Ejemplo n.º 2
0
        public async void UpdateCurrentTags(INavigatorListEntry listEntry)
        {
            if (listEntry?.DbId == null)
            {
                IsRateSetted = false;

                return;
            }

            var id = listEntry.DbId.Value;

            var tags = await Task.Run(() =>
            {
                return(ImoutoService.Use(imoutoService =>
                {
                    return imoutoService.GetImageTags(id);
                }));
            });

            _lastListEntryId = id;

            var tagVmsCollection = tags.Where(x => x.Tag.Type.Title != "LocalMeta")
                                   .Select(x => new BindedTagVM(x, listEntry.DbId))
                                   .ToList();

            CurrentTagsSources.Clear();

            var userTags = tagVmsCollection.Where(x => x.Model.Source == Source.User)
                           .ToList();

            if (userTags.Any())
            {
                CurrentTagsSources.Add(new TagSourceVM
                {
                    Title = "User",
                    Tags  = new ObservableCollection <BindedTagVM>(userTags)
                });
            }

            var parsedSources = tagVmsCollection.Select(x => x.Model.Source)
                                .Where(x => x != Source.User)
                                .Distinct();

            foreach (var parsedSource in parsedSources)
            {
                CurrentTagsSources.Add(new TagSourceVM
                {
                    Title = parsedSource.ToString(),
                    Tags  = new ObservableCollection <BindedTagVM>(tagVmsCollection.Where(x => x.Model.Source == parsedSource)
                                                                   .OrderBy(x => x.TypePriority)
                                                                   .ThenBy(x => x.Tag.Title))
                });
            }

            GetFavorite(tags);
            GetRate(tags);
            IsRateSetted = true;
        }
 private Task UnbindTagTask(int imageId, int tagId)
 {
     return Task.Run(() =>
     {
         ImoutoService.Use(imoutoService =>
         {
             imoutoService.UnbindTag(imageId, tagId);
         });
     });
 }
 private Task <List <TagType> > ReloadTagTypesTask()
 {
     return(Task.Run(() =>
     {
         return ImoutoService.Use(imoutoService =>
         {
             return imoutoService.GetTagTypes();
         });
     }));
 }
Ejemplo n.º 5
0
 private static Task <List <Tag> > SearchTagsAsyncTask(string searchString)
 {
     return(Task.Run(() =>
     {
         return ImoutoService.Use(imoutoService =>
         {
             return imoutoService.SearchTags(searchString);
         });
     }));
 }
Ejemplo n.º 6
0
 private Task <int> GetImagesCountFromCollectionAsyncTask()
 {
     return(Task.Run(() =>
     {
         return ImoutoService.Use(imoutoService =>
         {
             return imoutoService.CountSearchImage(TagSearchVM.SelectedColleciton.Value,
                                                   TagSearchVM.SelectedBindedTags.Select(x => x.Model).ToList());
         });
     }));
 }
Ejemplo n.º 7
0
        private Task <List <Tag> > LoadTagsTask(string searchPattern)
        {
            return(Task.Run(() =>
            {
                var tags = ImoutoService.Use(imoutoService =>
                {
                    return imoutoService.SearchTags(searchPattern);
                });

                return tags;
            }));
        }
 private Task CreateTagTask(CreateTagVM createTagVM)
 {
     return(Task.Run(() =>
     {
         ImoutoService.Use(imoutoService =>
         {
             imoutoService.CreateTag(new Tag
             {
                 HasValue = createTagVM.HasValue,
                 SynonymsCollection = createTagVM.SynonymsCollection,
                 Title = createTagVM.Title,
                 Type = createTagVM.SelectedType
             });
         });
     }));
 }
Ejemplo n.º 9
0
        private async Task SetFavorite(bool value, int target)
        {
            var favTag = await ImoutoService.UseAsync(imoutoService =>
            {
                return(imoutoService.SearchTags("favorite", 1)
                       .FirstOrDefault());
            });

            if (favTag == null)
            {
                await ImoutoService.UseAsync(imoutoService =>
                {
                    var types = imoutoService.GetTagTypes();
                    var type  = types.First(x => x.Title == "LocalMeta");

                    imoutoService.CreateTag(new Tag {
                        Title = "favorite", HasValue = false, Type = type
                    });
                });

                favTag = await ImoutoService.UseAsync(imoutoService =>
                {
                    return(imoutoService.SearchTags("favorite", 1).FirstOrDefault());
                });
            }

            var tags = await ImoutoService.UseAsync(imoutoService => imoutoService.GetImageTags(target));

            var favBindedTag = tags.FirstOrDefault(x => x.Tag.Id == favTag.Id);

            if (favBindedTag != null && !value)
            {
                await ImoutoService.UseAsync(imoutoService =>
                {
                    imoutoService.UnbindTag(target, favTag.Id.Value);
                });
            }
            else if (favBindedTag == null && value)
            {
                await ImoutoService.UseAsync(imoutoService =>
                {
                    imoutoService.BindTag(target, new BindedTag {
                        Source = Source.User, Tag = favTag, DateAdded = DateTime.Now
                    });
                });
            }
        }
Ejemplo n.º 10
0
 private Task <ObservableCollection <INavigatorListEntry> > GetImagesFromCollectionAsyncTask(int count, int skip)
 {
     return(Task.Run(() =>
     {
         return new ObservableCollection <INavigatorListEntry>(ImoutoService.Use(imoutoService =>
         {
             return imoutoService.SearchImage(TagSearchVM.SelectedColleciton.Value,
                                              TagSearchVM
                                              .SelectedBindedTags
                                              .Select(x => x.Model)
                                              .ToList(),
                                              count,
                                              skip,
                                              App.AppGuid);
         }).Select(x => EntryVM.GetListEntry(x.Item1, PreviewSize, x.Item2))
                                                               .SkipExceptions()
                                                               );
     }));
 }
Ejemplo n.º 11
0
        private async Task SetRate(int value, int target)
        {
            var rateTag = await ImoutoService.UseAsync(imoutoService =>
            {
                return(imoutoService.SearchTags("Rate", 1)
                       .FirstOrDefault());
            });

            if (rateTag.Title != "Rate")
            {
                rateTag = null;
            }

            if (rateTag == null)
            {
                await ImoutoService.UseAsync(imoutoService =>
                {
                    var types = imoutoService.GetTagTypes();
                    var type  = types.First(x => x.Title == "LocalMeta");

                    imoutoService.CreateTag(new Tag
                    {
                        Title    = "Rate",
                        HasValue = true,
                        Type     = type
                    });
                });

                rateTag = await ImoutoService.UseAsync(imoutoService =>
                {
                    return(imoutoService.SearchTags("Rate", 1)
                           .FirstOrDefault());
                });
            }

            await ImoutoService.UseAsync(imoutoService =>
            {
                imoutoService.BindTag(target, new BindedTag()
                {
                    Source = Source.User, Tag = rateTag, DateAdded = DateTime.Now, Value = value.ToString()
                });
            });
        }
Ejemplo n.º 12
0
        private async void Save(object obj)
        {
            var images = SelectedItems;
            var tags   = SelectedTags;

            try
            {
                IsSavind  = true;
                IsSuccess = false;
                await Task.Run(() =>
                {
                    ImoutoService.Use(imoutoService =>
                    {
                        imoutoService.BatchBindTag(images.Where(x => x.DbId.HasValue)
                                                   .Select(x => x.DbId.Value)
                                                   .ToList(), tags.Select(x => new BindedTag
                        {
                            Tag       = x.Tag,
                            DateAdded = DateTime.Now,
                            Source    = Source.User,
                            Value     = (x.Tag.HasValue)
                                                                     ? x.Value
                                                                     : null
                        })
                                                   .ToList());
                    });
                });

                IsSavind = false;

                UpdateRecentlyTags(SelectedTags);

                IsSuccess = true;
                await Task.Delay(500);

                IsSuccess = false;
            }
            catch
            {
                IsSavind = false;
            }
        }