Example #1
0
        public async Task TestDelete()
        {
            Models.ImageFile imageFile = await imageService.UploadImage(upload.Object, "test", 1600, CancellationToken.None);

            await imageService.DeleteImage(imageFile, CancellationToken.None);

            Assert.Equal(HttpStatusCode.Forbidden, await CheckUrl(imageService.GetUrl(imageFile)));
        }
Example #2
0
        public async Task TestUpload()
        {
            Models.ImageFile imageFile = await imageService.UploadImage(upload.Object, "test", 1600, CancellationToken.None);

            Assert.NotNull(imageFile);
            Assert.NotNull(imageFile.Filepath);
            Assert.Equal("test", imageFile.Description);
            Assert.Equal(HttpStatusCode.OK, await CheckUrl(imageService.GetUrl(imageFile)));

            await imageService.DeleteImage(imageFile, CancellationToken.None);
        }
Example #3
0
        public ActionResult Index(string addlocation = "", int photoLocationNumber = 0)
        {
            Models.PhotoViewModel pvm = new Models.PhotoViewModel();

            if (!addlocation.Equals(""))
            {
                pvm.CurrentLocation = addlocation;
            }

            if (pvm.CurrentLocation.Length < pvm.TopRoot.Length)
            {
                pvm.CurrentLocation = pvm.TopRoot;
            }


            pvm.Folders = System.IO.Directory.GetDirectories(pvm.CurrentLocation).ToList <string>();

            pvm.ImageLocations = Directory.GetFiles(pvm.CurrentLocation).Where(m =>
                                                                               m.ToLower().EndsWith("jpg") || m.ToLower().EndsWith("png")).ToList();

            pvm.PhotoLocationNumber += photoLocationNumber;
            pvm.TotalPages           = pvm.ImageLocations.Count / 6;

            pvm.Images.Clear();



            for (int i = photoLocationNumber; i <= pvm.PhotoLocationNumber + 5 && pvm.ImageLocations.Count - 1 >= i; i++)
            {
                string image = pvm.ImageLocations[i];

                Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                Bitmap myBitmap    = new Bitmap(image);
                Image  myThumbnail = myBitmap.GetThumbnailImage(75, 75, myCallback, IntPtr.Zero);
                //pvm.RealImages.Add(myThumbnail);

                ImageConverter _imageConverter = new ImageConverter();
                byte[]         xByte           = (byte[])_imageConverter.ConvertTo(myThumbnail, typeof(byte[]));

                Models.ImageFile ifModel = new Models.ImageFile();


                FileInfo currentFile = new FileInfo(image);

                ifModel.Name = currentFile.FullName;
                ifModel.Data = xByte;

                pvm.Images.Add(ifModel);
            }

            return(View(pvm));
        }
        public ActionResult Index(string fileId, bool download = false)
        {
            var defaultImageNotFound     = "pixel.gif";
            var defaultImageNotFoundPath = $"~/content/img/{defaultImageNotFound}";
            var defaultImageContentType  = "image/gif";

            var cacheKey = string.Format("imagebankfile_{0}", fileId);

            Models.ImageFile model = null;

            if (Cache.NotExists(cacheKey))
            {
                model = Repository.GetFile(fileId);

                if (model == null)
                {
                    if (download)
                    {
                        return(File(Server.MapPath(defaultImageNotFoundPath), defaultImageContentType, defaultImageNotFound));
                    }

                    return(File(Server.MapPath(defaultImageNotFoundPath), defaultImageContentType));
                }

                Cache.Insert(cacheKey, "Default", model);
            }
            else
            {
                model = Cache.Get(cacheKey) as Models.ImageFile;
            }

            if (download)
            {
                return(File(model.Body, model.ContentType, string.Concat(fileId, model.Extension)));
            }

            return(File(model.Body, model.ContentType));
        }