public async Task SetArtist(string genusName, string speciesName, int pictureIndex, string artist) { // Decrease the picture index by 1 (since users are expected to use the indices as shown by the "gallery" command, which begin at 1). --pictureIndex; Species species = await BotUtils.ReplyFindSpeciesAsync(Context, genusName, speciesName); if (species is null) { return; } Picture[] pictures = await SpeciesUtils.GetPicturesAsync(species); if (pictureIndex >= 0 && pictureIndex < pictures.Count()) { Picture picture = pictures[pictureIndex]; picture.artist = artist; await SpeciesUtils.AddPictureAsync(species, picture); await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully updated artist for {0} [picture]({1}) to **{2}**.", StringUtils.ToPossessive(species.ShortName), picture.url, artist)); } else { await BotUtils.ReplyAsync_Error(Context, string.Format("**{0}** has no picture at this index.", species.ShortName)); } }
public async Task PlusPic(string genusName, string speciesName, string imageUrl, string description) { // Get the species. Species species = await BotUtils.ReplyFindSpeciesAsync(Context, genusName, speciesName); if (species is null) { return; } // Validate the image URL. if (!await BotUtils.ReplyIsImageUrlValidAsync(Context, imageUrl)) { return; } // 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. Picture[] pictures = await GalleryUtils.GetPicturesAsync(await GalleryUtils.GetGalleryAsync(species)); bool firstPicture = pictures.Count() <= 0; bool pictureAlreadyExists = pictures.Any(x => x.url == imageUrl); Picture picture = pictures.Where(x => x.url == imageUrl).FirstOrDefault() ?? new Picture(); picture.url = imageUrl; picture.description = description; if (string.IsNullOrEmpty(picture.artist)) { picture.artist = firstPicture ? species.OwnerName : Context.User.Username; } await SpeciesUtils.AddPictureAsync(species, picture); if (pictureAlreadyExists) { await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully updated [picture]({1}) for **{0}**.", species.ShortName, imageUrl)); } else { await BotUtils.ReplyAsync_Success(Context, string.Format("Successfully added new [picture]({1}) for **{0}**.", species.ShortName, imageUrl)); } }