public ActionResult Upload(ImageView image,
                                   HttpPostedFileBase ImageFile)
        {
            CheckAda();
            ApplicationUser user = GetLoggedInUser();

            ViewData["tags"] = new SelectList(db.Tags, "Id", "Name", 1);
            if (ModelState.IsValid)
            {
                /*
                 * Save image infomation in the database
                 */
                Image imageEntity = new Image();
                imageEntity.Caption     = image.Caption;
                imageEntity.Description = image.Description;
                imageEntity.DateTaken   = image.DateTaken;
                imageEntity.TagId       = image.TagId;
                imageEntity.UserId      = user.Id;
                imageEntity.Validated   = false;
                imageEntity.Approved    = false;

                if (ImageFile != null && ImageFile.ContentLength > 0)
                {
                    if (!ImageFile.ContentType.Equals("image/jpeg"))
                    {
                        ViewBag.Message = "The file you uploaded is not a jpg file";
                        return(View());
                    }
                    else
                    {
                        db.Images.Add(imageEntity);
                        db.SaveChanges();
                        db.Images.Find(imageEntity.Id).Uri = ImageStorage.ImageURI(Url, imageEntity.Id);
                        db.SaveChanges();
                        ImageStorage.SaveFile(Server, ImageFile, imageEntity.Id);
                        // string imgFileName = Server.MapPath("~/Content/Images/img-" + imageEntity.Id + ".jpg");
                        // ImageFile.SaveAs(imgFileName);

                        ValidationRequest validationReq = new ValidationRequest();
                        validationReq.imageId = imageEntity.Id;
                        validationReq.UserId  = user.Id;

                        return(RedirectToAction("Details", new { Id = imageEntity.Id }));
                    }
                }
                else
                {
                    ViewBag.Message = "No image file specified!";
                    return(View());
                }
            }
            else
            {
                ViewBag.Message = "Please correct the errors in the form!";
                return(View());
            }
        }
        //[RequireHttps]
        public ActionResult Upload(ImageView image, HttpPostedFileBase ImageFile)
        {
            CheckAda();
            ApplicationUser user = GetLoggedInUser();

            if (user == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            String userid      = user.Id;
            Image  imageEntity = new Image();

            imageEntity.Caption     = image.Caption;
            imageEntity.Description = image.Description;
            imageEntity.DateTaken   = image.DateTaken;
            imageEntity.User        = user;
            imageEntity.UserId      = userid;
            imageEntity.TagId       = image.TagId;
            imageEntity.Approved    = false;
            imageEntity.Validated   = false;
            if (ImageFile != null && ImageFile.ContentLength > 0)
            {
                System.Drawing.Image img = System.Drawing.Image.FromStream(ImageFile.InputStream);
                //if (img.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Jpeg.Guid)
                //{
                ApplicationDBContext.Images.Add(imageEntity);
                ApplicationDBContext.SaveChanges();
                ImageStorage.SaveFile(Server, ImageFile, imageEntity.Id);
                ValidationRequest validationReq = new ValidationRequest();
                validationReq.imageId = imageEntity.Id;
                validationReq.UserId  = user.Id;
                validationQ.Initialize();
                validationQ.Send(validationReq);
                validationQ.Finalize();
                azureStorageQueue.addMessage(user.UserName.ToString() + " " + image.Caption + " ");
                return(RedirectToAction("Details", new { Id = imageEntity.Id }));

                //}
                //else
                //{
                //    ViewBag.Message = "Invalid JPEG image!";
                //    return RedirectToAction("Error", "Home", new { errid = "NoImageToUpload" });
                //}
            }
            else
            {
                ViewBag.Message = "Invalid JPEG image!";
                return(RedirectToAction("Error", "Home", new { errid = "NoImageToUpload" }));
            }
        }
示例#3
0
        public ActionResult Upload(ImageView image,
                                   HttpPostedFileBase ImageFile)
        {
            CheckAda();

            TryUpdateModel(image);


            if (ModelState.IsValid)
            {
                // HttpCookie cookie = Request.Cookies.Get("ImageSharing");
                ApplicationUser userid = GetLoggedInUser();

                if (userid != null)
                {
                    ApplicationUser user = db.Users.SingleOrDefault(u => u.Id.Equals(userid.Id));
                    if (user != null)
                    {
                        //save image information in the database.

                        Image imageEntity = new Image();
                        imageEntity.Caption     = image.Caption;
                        imageEntity.Description = image.Description;
                        imageEntity.DateTaken   = image.DateTaken;
                        imageEntity.UserId      = user.UserName;
                        imageEntity.Approved    = false;
                        imageEntity.Valid       = false;
                        imageEntity.TagId       = image.TagId;
                        if (ImageFile != null && ImageFile.ContentLength > 0 && ImageFile.ContentType.Equals("image/jpeg"))
                        {
                            db.Images.Add(imageEntity);
                            db.SaveChanges();

                            ImageStorage.SaveFile(Server, ImageFile, imageEntity.Id);
                            QueueConnector.SendToQueue(imageEntity);

                            // image.Id = imageEntity.Id;
                            //return View("Details", image);
                            return(RedirectToAction("Details", new { Id = imageEntity.Id }));
                        }
                        else
                        {
                            ViewBag.Message = "No image file specified!";
                            return(View());
                        }
                    }
                    else
                    {
                        ViewBag.Message = "No such userid registered!";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Message = "No such userid registered!";
                    return(View());
                }
            }
            else
            {
                ViewBag.Message = "Please correct the errors in the form!";
                return(View());
            }
        }
示例#4
0
        public ActionResult Upload(ImageView image, HttpPostedFileBase ImageFile)
        {
            // Checking ADA
            CheckAda();

            TryUpdateModel(image);
            ViewBag.Tags = new SelectList(ApplicationDbContext.Tags, "Id", "Name", image.TagId);
            if (ModelState.IsValid)
            {
                ApplicationUser AppUser = GetLoggedInUser();
                if (AppUser != null)
                {
                    if (!ImageFile.FileName.Split('.')[1].ToUpper().Equals("JPG"))
                    {
                        ViewBag.ImageValidation = "File type must be JPG";
                        return(View());
                    }

                    double fileSize = 4;
                    if (((double)ImageFile.ContentLength / (1024 * 1024)) > fileSize)
                    {
                        ViewBag.ImageValidation = "File size is greater";
                        return(View());
                    }
                    // Assigning Image Details
                    Image imageEntity = new Image();
                    imageEntity.Caption     = image.Caption;
                    imageEntity.User        = AppUser;
                    imageEntity.Description = image.Description;
                    imageEntity.Approved    = false;
                    imageEntity.TagId       = image.TagId;
                    imageEntity.Validated   = false;
                    imageEntity.DateTaken   = image.DateTaken;

                    ImageView imageView = new ImageView();
                    imageView.Uri         = ImageStorage.ImageURI(Url, imageEntity.Id);
                    imageView.Caption     = imageEntity.Caption;
                    imageView.Description = imageEntity.Description;
                    imageView.DateTaken   = imageEntity.DateTaken;
                    imageView.UserId      = imageEntity.User.UserName;

                    if (ImageFile != null && ImageFile.ContentLength > 0)
                    {
                        ApplicationDbContext.Images.Add(imageEntity);
                        ApplicationDbContext.SaveChanges();

                        ImageStorage.SaveFile(Server, ImageFile, imageEntity.Id);
                        imageView.Id = imageEntity.Id;
                        LogContext.addLogEntry(User.Identity.Name, imageView);

                        // Logic for Validation Request.
                        ValidationRequest ValidationRequest = new ValidationRequest();
                        ValidationRequest.ImageId = imageEntity.Id;
                        ValidationRequest.UserId  = imageView.UserId;

                        //Send message in the queue
                        ValidationQueue.Send(ValidationRequest);

                        TempData["UploadSuccessMessage"] = "Image uploaded successfully.";
                        return(RedirectToAction("Upload"));
                    }
                    else
                    {
                        ViewBag.Message = "No image file specified";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Message = "No such user registered";
                    return(View());
                }
            }
            else
            {
                ViewBag.Message = "Please reenter the details!";
                return(View());
            }
        }
        //  [RequireHttps]
        public ActionResult Upload(ImageView image, HttpPostedFileBase ImageFile)
        {
            CheckAda();
            TryUpdateModel(image);

            if (ModelState.IsValid)
            {
                ApplicationUser user = GetLoggedInUser();

                if (user != null)
                {
                    /*
                     * Save image information in the database.
                     */

                    Image imageEntity = new Image();
                    imageEntity.Caption     = image.Caption;
                    imageEntity.Description = image.Description;
                    imageEntity.DateTaken   = image.DateTaken;
                    imageEntity.User        = user;
                    imageEntity.TagId       = image.TagId;
                    imageEntity.Validated   = false;
                    imageEntity.Approved    = false;

                    // currentuser = imageEntity.User.Email.Split('@')[0];

                    if (ImageFile != null && ImageFile.ContentLength > 0)
                    {
                        //if (ImageFile.ContentLength < 3000000)
                        //{
                        String imgPath = ImageFile.ContentType.ToString();

                        //if (imgPath == "image/JPEG" || imgPath == "image/JPG" || imgPath == "image/jpeg" || imgPath == "image/jpg")
                        //{

                        this.ApplicationDbContext.Images.Add(imageEntity);
                        this.ApplicationDbContext.SaveChanges();


                        ImageStorage.SaveFile(Server, ImageFile, imageEntity.Id);
                        QueueConnector.SendToQueue(imageEntity.UserId, imageEntity.Id);


                        return(RedirectToAction("Details", new { Id = imageEntity.Id }));
                        //  }
                        //else
                        //{
                        //    ViewBag.Message = "Please enter only JPEG image file !";
                        //    SelectList tags = new SelectList(db.Tags, "Id", "Name", 1);
                        //    return View(tags);
                        //}
                        //}


                        //else
                        //{
                        //    ViewBag.Message = "Please enter the image with the content size less than 3 MB !";
                        //    SelectList tags = new SelectList(db.Tags, "Id", "Name", 1);
                        //    return View(tags);

                        //}
                    }

                    else
                    {
                        ViewBag.Message = "No image file specified ! ";
                        SelectList tags = new SelectList(db.Tags, "Id", "Name", 1);
                        return(View(tags));
                    }
                }

                else
                {
                    ViewBag.Message = "No such uerid registered !";
                    SelectList tags = new SelectList(db.Tags, "Id", "Name", 1);
                    return(View(tags));
                }
            }
            else
            {
                ViewBag.Message = "Please correct the errors in the form ! ";
                SelectList tags = new SelectList(db.Tags, "Id", "Name", 1);
                return(View(tags));
            }
        }
示例#6
0
        public ActionResult Upload(ImagesView image,
                                   HttpPostedFileBase ImageFile)
        {
            CheckAda();

            String  message = "";
            Boolean flag    = false;

            //System.Drawing.Image img;

            TryUpdateModel(image);

            if (ModelState.IsValid)
            {
                //HttpCookie cookie = Request.Cookies.Get("ImageSharing");
                ApplicationUser userid = GetLoggedInUser();
                ApplicationUser user   = db.Users.SingleOrDefault(u => u.Id.Equals(userid.Id));

                //if (cookie != null)
                //{
                //    image.Userid = cookie["Userid"];
                //    User user = db.Users.SingleOrDefault(u => u.Userid.Equals(image.Userid));

                if (user != null)
                {
                    /*
                     * Save image information in the database
                     */

                    //JavaScriptSerializer serializer = new JavaScriptSerializer();
                    //String jsonData = serializer.Serialize(image);

                    Image imageEntity = new Image();
                    imageEntity.Caption     = image.Caption;
                    imageEntity.Description = image.Description;
                    imageEntity.DateTaken   = image.DateTaken;
                    imageEntity.Userid      = user.Id;     //navigation property
                    imageEntity.TagId       = image.TagId; //navigation property
                    imageEntity.Approved    = false;
                    imageEntity.Validated   = false;

                    if (ImageFile != null && ImageFile.ContentLength > 0)
                    {
                        if (ImageFile.ContentLength > Limit)
                        {
                            flag    = true;
                            message = "Image size exceed permissible values";
                        }
                        //else if (ImageFile.ContentType != "image/jpeg")
                        //{
                        //    flag = true;
                        //    message = "File type " + ImageFile.ContentType +
                        //        " is not valid.  Only supports 'jpeg'.";
                        //}
                        else
                        {
                            //try
                            //{
                            //    img = System.Drawing.Image.FromStream(ImageFile.InputStream);

                            //}
                            //catch (SystemException ex)
                            //{
                            //    return View("Error");
                            //}

                            //if (img.RawFormat.Guid != System.Drawing.Imaging.ImageFormat.Jpeg.Guid)
                            //{
                            //    flag = true;
                            //    message = "File is invalid!";
                            //}
                            //else
                            //{
                            db.Images.Add(imageEntity);
                            db.SaveChanges();  //Save the changes to db so we get ID chosen by db
                            //Save the image
                            //String imgFileName = Server.MapPath("~/Content/Images/img-" + imageEntity.Id + ".jpg");
                            //ImageFile.SaveAs(imgFileName);
                            //ImageFile.SaveAs(getFilePath(imageEntity.Id));
                            ImageStorage.SaveFile(Server, ImageFile, imageEntity.Id);
                            //Push the image to the service bus queue for validation
                            QueueManager qm = new QueueManager(imageEntity.User.Id);
                            qm.addMessage(imageEntity, "Uploaded but it requires admin approvals.");
                            ValidationQueue.Send(new ValidationRequest(imageEntity.Id, imageEntity.User.Id));
                            //}
                        }
                    }
                    else
                    {
                        flag    = true;
                        message = "No file given or 0 sized file.";
                    }

                    if (flag)
                    {
                        ViewBag.Message = message;
                        ViewBag.Tags    = new SelectList(db.Tags, "Id", "Name", 1);
                        return(View());
                    }
                    else
                    {
                        ViewBag.Title = "Image uploaded.";
                        return(RedirectToAction("Details", new { Id = imageEntity.Id }));
                    }
                }
                else
                {
                    ViewBag.Message = "No such user found.";
                    return(View());
                }
                //}
                //else
                //{
                //    ViewBag.Message = "You need to register first before uploading.";
                //    return View();
                //}
            }
            else
            {
                ViewBag.Message = "Errors in the form fields";
                return(View());
            }
        }