Ejemplo n.º 1
0
        public ActionResult Custom(string file, string name, string path, bool saved)
        {
            int currentuserID = (int)Membership.GetUser(User.Identity.Name).ProviderUserKey;

            UserProfile currentUser = _db.UserProfiles.Find(currentuserID);

            PhotoPack Ppack = new PhotoPack {
                newFileName = file, PhotoName = name, savedPath = userOrigPath, ShareThisPhoto = false, Original = true
            };

            if (saved == false)
            {
                WebImage photo = new WebImage(@"~\" + uploadedPath + Ppack.newFileName);
                photo.Save(@"~\" + userOrigPath + Ppack.newFileName);

                currentUser.MyPhotos.Add(Ppack);

                _db.Entry(currentUser).State = EntityState.Modified;
                _db.SaveChanges();

                Delete(@"~\" + uploadedPath, Ppack.newFileName);
            }


            ViewBag.file = Ppack.savedPath + Ppack.newFileName;
            return(View(Ppack));
        }
Ejemplo n.º 2
0
        public ActionResult ShowAll(string message)
        {
            int currentuserID = (int)Membership.GetUser(User.Identity.Name).ProviderUserKey;

            UserProfile             currentUser       = _db.UserProfiles.Find(currentuserID);
            ICollection <PhotoPack> currentuserPhotos = new List <PhotoPack>();
            PhotoPack Ppack = new PhotoPack();

            var model =
                _db.PhotoPacks
                .OrderBy(r => r.Id)
                .Where(r => r.UserID == currentuserID)
                //.Where(r => searchTerm == null || r.ModelNum.StartsWith(searchTerm))
                .Select(r => new SearchPhotoPack
            {
                Id             = r.Id,
                newFileName    = r.newFileName,
                Original       = r.Original,
                PhotoName      = r.PhotoName,
                savedPath      = r.savedPath,
                SelectedSize   = r.SelectedSize,
                ShareThisPhoto = r.ShareThisPhoto,
                fullPath       = @"..\" + r.savedPath + r.newFileName
            });

            ViewBag.delete = message;

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Index(string file = null, string name = null)
        {
            PhotoPack Ppack = new PhotoPack {
                newFileName = file, PhotoName = name, ShareThisPhoto = false
            };

            ViewBag.file = file;
            return(View(Ppack));
        }
Ejemplo n.º 4
0
        public ActionResult Display(string file, bool sized, string name, bool savedFile, int legoSize = 0, string savedFilePath = null, int w = 0, int h = 0)
        {
            PhotoPack Ppack = new PhotoPack {
                newFileName = Guid.NewGuid().ToString() + "_" + name + ".jpg", PhotoName = name, ShareThisPhoto = false
            };

            string filepath = HttpRuntime.AppDomainAppPath;
            Bitmap newImage;
            Bitmap bmpPostedImage;

            if (savedFilePath == null)
            {
                savedFilePath = uploadedPath;
            }

            WebImage photo = new WebImage(filepath + savedFilePath + file);

            int currentH = photo.Height;
            int currentW = photo.Width;

            if (sized == false)
            {
                FitLegoSize(photo, file, currentH, currentW, legoSize);
            }
            else
            {
                photo.Resize(width: w, height: h, preserveAspectRatio: true,
                             preventEnlarge: false);

                FitLegoSize(photo, file, h, w, legoSize);
            }


            bmpPostedImage = new Bitmap(filepath + displayPath + file);
            newImage       = Pixelate(bmpPostedImage, new Rectangle(0, 0, bmpPostedImage.Width, bmpPostedImage.Height), legoSize);
            bmpPostedImage.Dispose();
            newImage.Save(filepath + pixelPath + Ppack.newFileName, ImageFormat.Jpeg);

            newImage.Dispose();
            ViewBag.filepath = displayPath + Ppack.newFileName;
            LegoWaterMark(Ppack, legoSize);

            SearchPhotoPack Spack = new SearchPhotoPack
            {
                Id             = Ppack.Id,
                newFileName    = Ppack.newFileName,
                oldFileName    = file,
                Original       = Ppack.Original,
                PhotoName      = Ppack.PhotoName,
                savedPath      = Ppack.savedPath,
                savedFile      = savedFile,
                SelectedSize   = Ppack.SelectedSize,
                ShareThisPhoto = Ppack.ShareThisPhoto
            };

            return(View(Spack));
        }
Ejemplo n.º 5
0
        public ActionResult DeleteConfirmed(int deletedid)
        {
            PhotoPack Ppack = _db.PhotoPacks.Find(deletedid);

            _db.PhotoPacks.Remove(Ppack);
            _db.SaveChanges();

            string deleteMessage = DeleteMethod(@"~\" + Ppack.savedPath, Ppack.newFileName);

            return(RedirectToAction("Index", new { message = deleteMessage }));
        }
Ejemplo n.º 6
0
        public ActionResult Rename(SearchPhotoPack Spack, FormCollection collection)
        {
            PhotoPack Ppack = _db.PhotoPacks.Find(Spack.Id);

            Ppack.PhotoName = Spack.PhotoName;

            _db.Entry(Ppack).State = EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public ActionResult Index(PhotoPack Ppack, HttpPostedFileBase image)
        {
            string filepath = HttpRuntime.AppDomainAppPath;

            //@"C:\Users\Richard\Documents\Visual Studio 2013\Projects\LegoMyPhoto\LegoMyPhoto\UploadedImages\";


            if (image == null)
            {
                ViewBag.Error = "Please select a Photo";
                return(View(Ppack));
            }
            if (Request.ContentLength > 1900 * 1600 * 2)
            {
                ViewBag.Error = "Photo size too big. Maximum file size is 3MB.";
                return(View(Ppack));
            }

            if (Request.Files.Count == 0)
            {
                ViewBag.Error = "Failed uploading photo";
                return(View(Ppack));
            }
            if (!FileIsWebFriendlyImage(image.InputStream))
            {
                ViewBag.Error = "File is not an photo, Please only upload photo ( jpg, jpeg, gif, bmp, png, tif)";
                return(View(Ppack));
            }

            image = Request.Files[0];

            string imgfilename = Path.GetFileName(image.FileName);

            Ppack.PhotoName = Path.GetFileNameWithoutExtension(image.FileName);
            if (100 < imgfilename.Length)
            {
                imgfilename = "FileNameTooLong.jpg";
            }

            Bitmap bmpPostedImage = new Bitmap(image.InputStream);

            Ppack.newFileName = Guid.NewGuid().ToString() + "_" + imgfilename;
            bmpPostedImage.Save(filepath + uploadedPath + Ppack.newFileName, ImageFormat.Jpeg);
            Ppack.savedPath = uploadedPath;

            ViewBag.file = uploadedPath + Ppack.newFileName;

            return(View(Ppack));
        }
Ejemplo n.º 8
0
        public void LegoWaterMark(PhotoPack Ppack, int legoSize)
        {
            WebImage filePhoto = new WebImage(@"~\" + pixelPath + Ppack.newFileName);

            int      h = filePhoto.Height;
            int      w = filePhoto.Width;
            WebImage WatermarkPhoto = new WebImage(@"~\Images\" + "Lego" + legoSize + "_4096X4096.png");

            WatermarkPhoto.Crop(0, 0, WatermarkPhoto.Height - h, WatermarkPhoto.Width - w);

            filePhoto.AddImageWatermark(WatermarkPhoto, width: w - 1, height: h - 1,
                                        horizontalAlign: "Left", verticalAlign: "Top",
                                        opacity: 60, padding: 0);

            filePhoto.Save(@"~\" + displayPath + Ppack.newFileName);

            return;
        }
Ejemplo n.º 9
0
        public ActionResult Delete(int deletedid, string returnUrl)
        {
            PhotoPack Ppack = _db.PhotoPacks.Find(deletedid);

            SearchPhotoPack Spack = new SearchPhotoPack
            {
                Id             = Ppack.Id,
                newFileName    = Ppack.newFileName,
                Original       = Ppack.Original,
                PhotoName      = Ppack.PhotoName,
                savedPath      = Ppack.savedPath,
                SelectedSize   = Ppack.SelectedSize,
                ShareThisPhoto = Ppack.ShareThisPhoto
            };

            ViewBag.fileName  = Ppack.savedPath + Ppack.newFileName;
            ViewBag.returnUrl = returnUrl;
            return(View(Spack));
        }
Ejemplo n.º 10
0
        public ActionResult SaveMe(string file, string name)
        {
            int currentuserID = (int)Membership.GetUser(User.Identity.Name).ProviderUserKey;

            UserProfile currentUser = _db.UserProfiles.Find(currentuserID);

            PhotoPack Ppack = new PhotoPack {
                newFileName = file, savedPath = userLegoPath, PhotoName = name, ShareThisPhoto = false, Original = false
            };
            WebImage Fphoto = new WebImage(@"~\" + displayPath + Ppack.newFileName);

            Fphoto.Save(@"~\" + userLegoPath + Ppack.newFileName);

            currentUser.MyPhotos.Add(Ppack);

            _db.Entry(currentUser).State = EntityState.Modified;
            _db.SaveChanges();

            string message  = Delete(@"~\" + displayPath, Ppack.newFileName);
            string message1 = Delete(@"~\" + pixelPath, Ppack.newFileName);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 11
0
        public ActionResult Custom(PhotoPack Ppack, FormCollection form)
        {
            int    legoSize = Convert.ToInt32(Request.Form["legosize"].ToString());
            string file     = Request.Form["newFileName"].ToString();
            int    h        = 0;
            int    w        = 0;

            if (Request.Form["SelectedSize"] != "Keep")
            {
                h = Convert.ToInt32(Request.Form["SelectedSize"].ToString());

                if (h == 480)
                {
                    w = 640;
                }
                if (h == 600)
                {
                    w = 800;
                }
                if (h == 768)
                {
                    w = 1024;
                }
                if (h == 960 || h == 1024 || h == 720 || h == 800)
                {
                    w = 1280;
                }
                if (h == 1200)
                {
                    w = 1600;
                }
                if (h == 900)
                {
                    w = 1440;
                }
                if (h == 1050)
                {
                    w = 1680;
                }
                if (h == 1080 || h == 1201)
                {
                    w = 1920;
                    if (h == 1201)
                    {
                        h = 1200;
                    }
                }

                //Full Screen:        Widescreen:

                //800 x 600           1280 x 720
                //1024 x 768          1280 x 800
                //1280 x 960          1440 x 900
                //1280 x 1024         1680 x 1050
                //1600 x 1200         1920 x 1080
                //                    1920 x 1200


                return(RedirectToAction("Display", new { file = file, name = Ppack.PhotoName, sized = true, savedFile = true, legoSize, savedFilePath = userOrigPath, w, h }));
            }
            else
            {
                return(RedirectToAction("Display", new { file = file, name = Ppack.PhotoName, sized = false, savedFile = true, legoSize, savedFilePath = userOrigPath }));
            }
        }