public IActionResult AddImage(Image image)
        {
            var repo = new ImageRepository(_connectionString);

            repo.AddImage(image);
            return(Redirect("/"));
        }
Beispiel #2
0
        public IActionResult AddImage(Image i)
        {
            ImageRepository repository = new ImageRepository(_connection);

            repository.AddImage(i);
            return(Redirect("/"));
        }
Beispiel #3
0
        public void AddImage(Image i)
        {
            var db = new ImageRepository(_conn);

            i.UploadDate = DateTime.Now;
            db.AddImage(i);
        }
Beispiel #4
0
        private void ProcessImages(int resizeImageWidth, int resizeImageHeight, int thumbWidth, int thumbHeight, int hashThumbWidth, int hashThumbHeight, List <SKBitmap> skImages, ref List <Image> images)
        {
            for (int i = 0; i < skImages.Count; i++)
            {
                SKBitmap img;
                if (skImages[i].Width > resizeImageWidth || skImages[i].Height > resizeImageHeight)
                {
                    img = _imageService.ResizeImage(skImages[i], resizeImageWidth, resizeImageHeight);
                }
                else
                {
                    img = _imageService.ResizeImage(skImages[i], skImages[i].Width, skImages[i].Height); // To prevent GDI+ Exception
                }

                using (var image = img)
                {
                    // to prevent hash colisions
                    string hashThumbnail = _imageService.GetThumbnail(image, hashThumbWidth, hashThumbHeight);

                    // Check for duplicate
                    Image original = repository.GetImageByThumb(hashThumbnail);

                    // Return original, dont save duplicate
                    if (original != null)
                    {
                        images.Add(original);
                    }
                    else
                    {
                        var   newId    = Guid.NewGuid();
                        Image newImage = new Image
                        {
                            Id    = newId,
                            Thumb = hashThumbnail,
                            Path  = newId.ToString() + ".jpg",
                        };

                        // Saving FULL to storage
                        using (MemoryStream fullMs = _imageService.ConvertToStream(image))
                        {
                            _storageService.SaveToStorage(newImage.Path, fullMs);
                        }

                        images.Add(newImage);
                        repository.AddImage(newImage);

                        // Converting thumb
                        var thumbImage = _imageService.ResizeImage(image, thumbWidth, thumbHeight);
                        using (MemoryStream thumbMs = _imageService.ConvertToStream(thumbImage))
                        {
                            _storageService.SaveToStorage(newImage.Id.ToString() + "s.jpg", thumbMs);
                        }
                    }
                }

                img.Dispose();
                skImages[i].Dispose();
            }
        }
Beispiel #5
0
        public IActionResult AddImage(Image image)
        {
            var repo = new ImageRepository(_conStr);

            image.DatePosted = DateTime.Now;
            repo.AddImage(image);
            return(Redirect("/"));
        }
Beispiel #6
0
        public IActionResult Add(Image image)
        {
            var repos  = new ImageRepository(_connenctionString);
            var result = new Image
            {
                Title      = image.Title,
                URL        = image.URL,
                DatePosted = DateTime.Now
            };

            repos.AddImage(result);
            return(Redirect("/"));
        }
        public IActionResult Upload(Image image, IFormFile file)
        {
            var    fileName = $"{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
            string fullPath = Path.Combine(_environment.WebRootPath, "uploads", fileName);

            using (FileStream stream = new FileStream(fullPath, FileMode.CreateNew))
            {
                file.CopyTo(stream);
            }
            image.FileName = fileName;
            image.Date     = DateTime.Now;
            var connectionString = _configuration.GetConnectionString("connectionString");
            var repo             = new ImageRepository(connectionString);

            repo.AddImage(image);
            return(Redirect("/"));
        }
Beispiel #8
0
        public IActionResult Upload(IFormFile image, string description)
        {
            string fileName = $"{Guid.NewGuid()}{Path.GetExtension(image.FileName)}";
            string fullPath = Path.Combine(_environment.WebRootPath, "UploadedImages", fileName);

            using (var stream = new FileStream(fullPath, FileMode.CreateNew))
            {
                image.CopyTo(stream);
            }

            var img = new Image
            {
                FileName    = fileName,
                Description = description
            };

            var repo = new ImageRepository(_connectionString);

            repo.AddImage(img);

            return(Redirect("/"));
        }
        public ImageLabel UploadImage(Topic topic, string imageName, Stream imageStream)
        {
            #region validation

            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            if (string.IsNullOrEmpty(imageName))
            {
                throw new ArgumentNullException(nameof(imageName));
            }

            if (imageStream == null)
            {
                throw new ArgumentNullException(nameof(imageStream));
            }

            #endregion

            // check if image isn't corrupted
            // try to open image
            ImageUtil.TryOpenImage(imageStream);

            string[] topicImageFileName = ImageFileRepository.AddImageFile(topic, imageName, imageStream);

            Rect imageDimension = ImageUtil.GetDimensionFromImage(imageStream);

            ImageLabel imageLabel = new ImageLabel()
            {
                Id     = topicImageFileName.Last(),
                Height = imageDimension.Height,
                Width  = imageDimension.Width,
            };

            return(ImageRepository.AddImage(topic, imageLabel));
        }
Beispiel #10
0
 public Image AddImage(Image image)
 {
     return(repo.AddImage(image));
 }