Esempio n. 1
0
        public async Task AddMap(string imageUrl, string mapName = "", string description = "")
        {
            IPictureGallery gallery = await GetMapGalleryAsync();

            // Remove any pictures with the same name.

            foreach (IPicture pictureWithSameName in gallery.Where(picture => picture.Name?.Equals(mapName, StringComparison.OrdinalIgnoreCase) ?? false).ToArray())
            {
                gallery.Pictures.Remove(pictureWithSameName);
            }

            // Add the new picture to the gallery.

            IPicture newPicture = new Picture(imageUrl)
            {
                Name        = mapName,
                Description = description
            };

            gallery.Pictures.Add(newPicture);

            await Db.UpdateGalleryAsync(gallery);

            if (string.IsNullOrEmpty(mapName))
            {
                await ReplySuccessAsync($"Successfully added new {"map".FromLink(imageUrl)}.");
            }
            else
            {
                await ReplySuccessAsync($"Successfully added new {"map".FromLink(imageUrl)}, {mapName.ToTitle().ToBold()}.");
            }
        }
        public static async Task UpdateGalleryAsync(this SQLiteDatabase database, IPictureGallery gallery)
        {
            if (!gallery.Id.HasValue)
            {
                // If the gallery doesn't have an ID, assume that it's new, and attempt to add it.

                await database.AddGalleryAsync(gallery);
            }
            else
            {
                // Update the gallery in the database.

                IPictureGallery oldGallery = await database.GetGalleryAsync(gallery.Id);

                IEnumerable <IPicture> deletedPictures = oldGallery.Where(oldPicture => !gallery.Any(picture => oldPicture.Id == picture.Id));
                IEnumerable <IPicture> newPictures     = gallery.Where(picture => !oldGallery.Any(oldPicture => picture.Id == oldPicture.Id));

                foreach (IPicture picture in deletedPictures)
                {
                    await database.RemovePictureAsync(gallery, picture);
                }

                foreach (IPicture picture in newPictures)
                {
                    await database.AddPictureAsync(gallery, picture);
                }
            }
        }
Esempio n. 3
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()}.");
                }
            }
        }
 public static IPicture GetPicture(this IPictureGallery gallery, string name)
 {
     return(gallery
            .Where(p => p.GetName().Equals(name, StringComparison.OrdinalIgnoreCase))
            .FirstOrDefault());
 }