//renvoie le nombre de favoris de l'utilsateur
        public async Task <int> GetFavoritesCount()
        {
            int count      = 0;
            var client_fav = new ImgurClient(client_id, imgur_token);
            var endpoint   = new AccountEndpoint(client_fav);
            var favourites = await endpoint.GetAccountFavoritesAsync();

            for (int i = 0; i < favourites.Count(); i++)
            {
                if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryImage")
                {
                    count++;
                }
                else if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryAlbum")
                {
                    GalleryAlbum galleryAlbum = (GalleryAlbum)(favourites.ElementAt(i));
                    foreach (var image in galleryAlbum.Images)
                    {
                        count++;
                    }
                }
            }

            return(count);
        }
Ejemplo n.º 2
0
 public static Album ToAlbum(this GalleryAlbum galleryAlbum)
 {
     return(new Album()
     {
         Id = galleryAlbum.Id,
         Title = galleryAlbum.Title,
         Description = galleryAlbum.Description,
         DateTime = galleryAlbum.DateTime,
         Cover = galleryAlbum.Cover,
         CoverWidth = galleryAlbum.CoverWidth,
         CoverHeight = galleryAlbum.CoverHeight,
         AccountUrl = galleryAlbum.AccountUrl,
         AccountId = galleryAlbum.AccountId,
         Privacy = galleryAlbum.Privacy,
         Layout = galleryAlbum.Layout,
         Views = galleryAlbum.Views,
         Link = galleryAlbum.Link,
         Favorite = galleryAlbum.Favorite == true,
         Nsfw = galleryAlbum.Nsfw,
         ImageCount = galleryAlbum.ImageCount,
         Images = galleryAlbum.Images,
         InGallery = galleryAlbum.InGallery,
         IsAlbum = galleryAlbum.IsAlbum,
         Points = galleryAlbum.Points
     });
 }
Ejemplo n.º 3
0
        public IActionResult EditAlbum(GalleryAlbum model, List <IFormFile> photos)
        {
            if (ModelState.IsValid)
            {
                string albumFolderPath = hostingEnvironment.WebRootPath + "/images/gallery/album from " + model.EventDate.ToShortDateString();

                //Действие для записи нового альбома
                if (photos != null & model.AlbumPhotos == null)
                {
                    Directory.CreateDirectory(albumFolderPath);
                    model.AlbumPhotos = new List <AlbumPhoto>();
                    SavePhotos(model, photos, albumFolderPath);
                }

                //Действие для дополнения альбома
                else if (photos != null & model.AlbumPhotos.Count > 0)
                {
                    SavePhotos(model, photos, albumFolderPath);
                }

                else//Действие для изменения свойств модели без добавления фото
                {
                    dataManager.GalleryAlbums.SaveGalleryAlbum(model);
                }


                ViewBag.DataManager = dataManager;
                return(View("Index", ViewBag.DataManager));
            }

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult EditAlbum(int id, string Opisanie, HttpPostedFileBase[] file)
        {
            using (mozartdv_34Entities de = new mozartdv_34Entities())
            {
                GalleryAlbum ga = de.GalleryAlbum.Where(x => x.Id == id).First();
                ga.Text = Opisanie;
                de.SaveChanges();

                foreach (var item in file)
                {
                    if (item != null && item.ContentLength > 0)
                    {
                        string path = System.IO.Path.Combine(Server.MapPath("~/Content/UploadImage"), System.IO.Path.GetFileName(item.FileName));
                        item.SaveAs(path);
                        GalleryFoto gf = new GalleryFoto();
                        gf.Id_Album  = id;
                        gf.PathImage = item.FileName;
                        de.GalleryFoto.Add(gf);
                        de.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("EditAlbum/" + id, "AdminFoto"));
        }
        //renvoie les images associées au tag envoyé

        /**
         * This method extract images with a certain tag
         * @param tag the tag's name
         * @param nb_photos the number of pictures.
         */
        public async Task <ImageContainer> createImageContainerFromTag(string tag, int nb_photos)
        {
            ImageContainer  imageContainer  = new ImageContainer();
            GalleryEndpoint galleryEndpoint = new GalleryEndpoint(client);
            var             galleries       = await galleryEndpoint.SearchGalleryAsync(tag);

            for (int i = 0; i < nb_photos && i < galleries.Count(); i++)
            {
                if (galleries.ElementAt(i).GetType().ToString() != "Imgur.API.Models.Impl.GalleryImage")
                {
                    GalleryAlbum galleryAlbum = (GalleryAlbum)(galleries.ElementAt(i));

                    Windows.UI.Xaml.Controls.Image imgImgur = new Windows.UI.Xaml.Controls.Image();
                    if (galleryAlbum.Images.Count() > 0)
                    {
                        imgImgur.Source = new BitmapImage(new Uri(galleryAlbum.Images.ElementAt(0).Link, UriKind.Absolute));
                        imgImgur.Name   = galleryAlbum.Images.ElementAt(0).Id;
                        imageContainer.AddImageSource(imgImgur);
                    }
                }
                else
                {
                    nb_photos++;
                }
            }
            return(imageContainer);
        }
        //renvoie les images des favoris de l'utilsateur

        /**
         * Return favorite pictures of the user
         */
        public async Task <ImageContainer> createImageContainerFromFavorites()
        {
            ImageContainer imageContainer = new ImageContainer();
            var            client_fav     = new ImgurClient(client_id, imgur_token);
            var            endpoint       = new AccountEndpoint(client_fav);
            var            favourites     = await endpoint.GetAccountFavoritesAsync();

            for (int i = 0; i < favourites.Count(); i++)
            {
                if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryImage")
                {
                    GalleryImage galleryImage = (GalleryImage)(favourites.ElementAt(i));
                    Windows.UI.Xaml.Controls.Image imgImgur = new Windows.UI.Xaml.Controls.Image();
                    imgImgur.Source = new BitmapImage(new Uri(galleryImage.Link, UriKind.Absolute));
                    imgImgur.Name   = galleryImage.Id;
                    imageContainer.AddImageSource(imgImgur);
                }
                else if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryAlbum")
                {
                    GalleryAlbum galleryAlbum = (GalleryAlbum)(favourites.ElementAt(i));
                    Windows.UI.Xaml.Controls.Image imgImgur = new Windows.UI.Xaml.Controls.Image();
                    foreach (var image in galleryAlbum.Images)
                    {
                        imgImgur.Source = new BitmapImage(new Uri(image.Link, UriKind.Absolute));
                        imgImgur.Name   = image.Id;
                        imageContainer.AddImageSource(imgImgur);
                    }
                }
            }

            return(imageContainer);
        }
Ejemplo n.º 7
0
        public AlbumPhoto GetRandomPhoto(Guid id)
        {
            GalleryAlbum album       = GetGalleryAlbumById(id);
            var          albumPhotos = album.AlbumPhotos;
            var          random      = new Random();
            int          index       = random.Next(albumPhotos.Count());
            AlbumPhoto   albumPhoto  = albumPhotos.ElementAt(index);

            return(albumPhoto);
        }
Ejemplo n.º 8
0
        public ActionResult Main(int id)
        {
            using (mozartdv_34Entities de = new mozartdv_34Entities())
            {
                ViewBag.Image = "/GetAlbum/Preview/" + id;
                GalleryAlbum ga = de.GalleryAlbum.Where(x => x.Id == id).First();
                ViewBag.Opisanie = ga.Text;
                ViewBag.Id       = ga.Id;
            }

            return(PartialView());
        }
Ejemplo n.º 9
0
 public ActionResult AddAlbum(string opisanie)
 {
     using (mozartdv_34Entities de = new mozartdv_34Entities())
     {
         GalleryAlbum ga = new GalleryAlbum();
         ga.Text = opisanie;
         de.GalleryAlbum.Add(ga);
         de.SaveChanges();
         return(RedirectToAction("EditAlbum/" + ga.Id, "AdminFoto"));
     }
     return(View());
 }
Ejemplo n.º 10
0
 public void SaveGalleryAlbum(GalleryAlbum entity)
 {
     if (entity.Id == default)
     {
         context.Entry(entity).State = EntityState.Added;
     }
     else
     {
         context.Entry(entity).State = EntityState.Modified;
     }
     context.SaveChanges();
 }
Ejemplo n.º 11
0
        public static IEnumerable <Comment> GetComments(string clientId, GalleryAlbum album)
        {
            var client = new ImgurClient(clientId);

            var endpoint = new GalleryEndpoint(client);

            //TODO catch errors
            var albumsTask = endpoint.GetGalleryItemCommentsAsync(album.Id, CommentSortOrder.Best);

            albumsTask.Wait();

            return(albumsTask.Result.OfType <Comment>());
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Get additional information about an album in the gallery.
        /// </summary>
        /// <param name="albumId">The album id.</param>
        /// <exception cref="T:System.ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="T:Imgur.API.ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="T:Imgur.API.MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <IGalleryAlbum> GetGalleryAlbumAsync(string albumId)
        {
            if (string.IsNullOrWhiteSpace(albumId))
            {
                throw new ArgumentNullException(nameof(albumId));
            }
            string        url = string.Format("gallery/album/{0}", (object)albumId);
            IGalleryAlbum galleryAlbum;

            using (HttpRequestMessage request = this.RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                GalleryAlbum album = await this.SendRequestAsync <GalleryAlbum>(request).ConfigureAwait(false);

                galleryAlbum = (IGalleryAlbum)album;
            }
            return(galleryAlbum);
        }
Ejemplo n.º 13
0
        public ActionResult EditAlbum(int id)
        {
            List <GalleryFoto> lgf = new List <GalleryFoto>();

            using (mozartdv_34Entities de = new mozartdv_34Entities())
            {
                var data = de.GalleryFoto.Where(x => x.Id_Album == id).ToList();
                foreach (var item in data)
                {
                    lgf.Add(item);
                }

                GalleryAlbum opisanie = de.GalleryAlbum.Where(x => x.Id == id).FirstOrDefault();
                ViewBag.Opisanie = opisanie.Text;
            }
            ViewBag.FotoList = lgf;
            ViewBag.IdAlbum  = id;
            return(View());
        }
Ejemplo n.º 14
0
    public override object ReadJson(JsonReader reader,
                                    Type objectType, object existingValue, JsonSerializer serializer)
    {
        JObject jo = JObject.Load(reader);
        // Using a nullable bool here in case "is_album" is not present on an item
        bool?       isAlbum = (bool?)jo["is_album"];
        GalleryItem item;

        if (isAlbum.GetValueOrDefault())
        {
            item = new GalleryAlbum();
        }
        else
        {
            item = new GalleryImage();
        }
        serializer.Populate(jo.CreateReader(), item);
        return(item);
    }
Ejemplo n.º 15
0
        private void SavePhotos(GalleryAlbum model, List <IFormFile> photos, string albumFolderPath)
        {
            foreach (IFormFile photo in photos)
            {
                AlbumPhoto albumPhoto = new AlbumPhoto {
                    AlbumPhotoPath = photo.FileName
                };
                model.AlbumPhotos.Add(albumPhoto);

                using (var stream = new FileStream(Path.Combine(albumFolderPath, photo.FileName), FileMode.Create))
                    photo.CopyTo(stream);
            }

            dataManager.GalleryAlbums.SaveGalleryAlbum(model);

            foreach (AlbumPhoto photo in model.AlbumPhotos)
            {
                dataManager.AlbumPhotos.SaveAlbumPhoto(photo);
            }
        }
Ejemplo n.º 16
0
 public ActionResult DeleteAlbum(int id)
 {
     using (mozartdv_34Entities de = new mozartdv_34Entities())
     {
         List <GalleryFoto> lgf = de.GalleryFoto.Where(x => x.Id_Album == id).ToList();
         foreach (var item in lgf)
         {
             string fullPath = Request.MapPath("~/Content/UploadImage/" + item.PathImage);
             if (System.IO.File.Exists(fullPath))
             {
                 System.IO.File.Delete(fullPath);
                 de.GalleryFoto.Remove(item);
                 de.SaveChanges();
             }
         }
         GalleryAlbum ga = de.GalleryAlbum.Where(x => x.Id == id).First();
         de.GalleryAlbum.Remove(ga);
         de.SaveChanges();
     }
     return(RedirectToAction("Index", "AdminFoto"));
 }
        //renvoie le nombre d'image associées au tag envoyé
        public async Task <int> GetImageCount(string tag, int nb_photos)
        {
            int             count           = 0;
            GalleryEndpoint galleryEndpoint = new GalleryEndpoint(client);
            var             galleries       = await galleryEndpoint.SearchGalleryAsync(tag);

            for (int i = 0; i < nb_photos && i < galleries.Count(); i++)
            {
                if (galleries.ElementAt(i).GetType().ToString() != "Imgur.API.Models.Impl.GalleryImage")
                {
                    GalleryAlbum galleryAlbum = (GalleryAlbum)(galleries.ElementAt(i));
                    if (galleryAlbum.Images.Count() > 0)
                    {
                        count++;
                    }
                }
                else
                {
                    nb_photos++;
                }
            }
            return(count);
        }
Ejemplo n.º 18
0
 public GalleryAlbumWrapper(GalleryAlbum album)
 {
     this.Album = album;
 }