Beispiel #1
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
                    });
                });
            }
        }
Beispiel #2
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()
                });
            });
        }