Пример #1
0
        public async Task PlusPic(string genusName, string speciesName, string imageUrl, string description)
        {
            // Get the species.

            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid() && await ReplyValidateImageUrlAsync(imageUrl))
            {
                // Add the new picture to the gallery.

                // If this is the first picture we've added to the species, set the artist as the species' owner.
                // Otherwise, set the artist to the person submitting the image.

                IPictureGallery gallery = await Db.GetGalleryAsync(species) ?? new PictureGallery();

                bool isFirstPicture       = gallery.Count() <= 0;
                bool pictureAlreadyExists = gallery
                                            .Any(x => x.Url == imageUrl);

                IPicture picture = gallery
                                   .Where(p => p.Url == imageUrl)
                                   .FirstOrDefault() ?? new Picture();

                picture.Url         = imageUrl;
                picture.Description = description;

                if (string.IsNullOrEmpty(picture.Artist?.Name))
                {
                    picture.Artist = isFirstPicture ? species.Creator : Context.User.ToCreator();
                }

                await Db.AddPictureAsync(species, picture);

                if (pictureAlreadyExists)
                {
                    await ReplySuccessAsync($"Successfully updated {imageUrl.ToLink("picture")} for {species.GetShortName().ToBold()}.");
                }
                else
                {
                    await ReplySuccessAsync($"Successfully added new {imageUrl.ToLink("picture")} for {species.GetShortName().ToBold()}.");
                }
            }
        }
Пример #2
0
        public async Task SetPic(string genusName, string speciesName, string imageUrl)
        {
            // Updates the default picture for the given species.
            // While any users can add pictures for species, only moderators can update the default picture.

            ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName);

            if (species.IsValid())
            {
                if (await ReplyValidateImageUrlAsync(imageUrl))
                {
                    IPictureGallery gallery = await Db.GetGalleryAsync(species) ?? new PictureGallery();

                    bool isFirstPicture = gallery.Count() <= 0;

                    await Db.SetPictureAsync(species, new Picture {
                        Url    = imageUrl,
                        Artist = isFirstPicture ? species.Creator : Context.User.ToCreator()
                    });

                    await ReplySuccessAsync($"Successfully set the picture for {species.GetShortName().ToBold()}.");
                }
            }
        }