public ActionResult Delete(int Id) { CheckAda(); ApplicationUser user = GetLoggedInUser(); if (user == null) { return(RedirectToAction("Login", "Account")); } Image imageEntity = ApplicationDBContext.Images.Find(Id); if (imageEntity != null) { ImageView imageview = new ImageView(); imageview.Id = imageEntity.Id; imageview.Caption = imageEntity.Caption; imageview.Description = imageEntity.Description; imageview.DateTaken = imageEntity.DateTaken; imageview.TagName = imageEntity.Tag.Name; imageview.UserId = imageEntity.User.UserName; imageview.Uri = ImageStorage.ImageURI(Url, imageEntity.Id); return(View(imageview)); } else { return(RedirectToAction("Error", "Home", new { errid = "ImageNotFound" })); } }
public ActionResult Edit(int Id) { CheckAda(); Image imageEntity = db.Images.Find(Id); if (imageEntity != null) { ApplicationUser userid = GetLoggedInUser(); if (imageEntity.UserId.Equals(userid.Id)) { ViewBag.Message = ""; ViewBag.Tags = new SelectList(db.Tags, "Id", "Name", imageEntity.TagId); ImageView image = new ImageView(); image.Id = imageEntity.Id; image.Uri = ImageStorage.ImageURI(Url, imageEntity.Id); image.TagId = imageEntity.Id; image.Caption = imageEntity.Caption; image.Description = imageEntity.Description; image.DateTaken = imageEntity.DateTaken; return(View("Edit", image)); } else { return(RedirectToAction("Error", "Home", new { errid = "EditNotAuth" })); } } else { return(RedirectToAction("Error", "Home", new { errid = "EditNotFound" })); } }
public ActionResult Details(int Id) { CheckAda(); Image imageEntity = ApplicationDbContext.Images.Find(Id); bool isPreview = false; if (TempData["Preview"] != null) { isPreview = Convert.ToBoolean(TempData["Preview"]); } if (imageEntity != null) { ImageView imageView = new ImageView(); imageView.Id = imageEntity.Id; imageView.Uri = ImageStorage.ImageURI(Url, imageEntity.Id); imageView.Caption = imageEntity.Caption; imageView.Description = imageEntity.Description; imageView.DateTaken = imageEntity.DateTaken; imageView.TagName = imageEntity.Tag.name; imageView.UserId = imageEntity.User.UserName; LogContext.addLogEntry(User.Identity.Name, imageView); return(View(imageView)); } else { return(View((ImageView)null)); } }
public ActionResult Details(int Id) { CheckAda(); { Image imageEntity = db.Images.Find(Id); if (imageEntity != null) { ImageView imageView = new ImageView(); imageView.Id = imageEntity.Id; imageView.Uri = ImageStorage.ImageURI(Url, imageEntity.Id); imageView.Caption = imageEntity.Caption; imageView.Description = imageEntity.Description; imageView.DateTaken = imageEntity.DateTaken; imageView.TagName = imageEntity.Tag.Name; imageView.Userid = imageEntity.UserId; LogContext.AddLogEntry(GetLoggedInUser(), imageView); return(View(imageView)); } else { return(RedirectToAction("Error", "Home", new { errid = "Details" })); } } }
public ActionResult Delete(int Id) { CheckAda(); try { Image imageEntity = ApplicationDbContext.Images.Find(Id); if (imageEntity != null) { ImageView imageView = new ImageView(); imageView.Id = imageEntity.Id; imageView.Caption = imageEntity.Caption; imageView.Description = imageEntity.Description; imageView.DateTaken = imageEntity.DateTaken; imageView.TagName = imageEntity.Tag.name; imageView.UserId = imageEntity.User.UserName; imageView.Uri = ImageStorage.ImageURI(Url, imageEntity.Id); return(View(imageView)); } else { return(RedirectToAction("Error", "Home", new { errid = "Details" })); } } catch (Exception) { return(RedirectToAction("Error", "Home")); } }
public ActionResult Edit(int Id) { CheckAda(); Image imageEntity = ApplicationDbContext.Images.Find(Id); if (imageEntity != null) { ApplicationUser User = GetLoggedInUser(); if (imageEntity.User.UserName.Equals(User.Email)) { ViewBag.Message = ""; ViewBag.Tags = new SelectList(ApplicationDbContext.Tags, "Id", "name", imageEntity.TagId); ImageView image = new ImageView(); image.Id = imageEntity.Id; image.Uri = ImageStorage.ImageURI(Url, Id); image.TagId = imageEntity.TagId; image.Caption = imageEntity.Caption; image.Description = imageEntity.Description; image.DateTaken = imageEntity.DateTaken; return(View("Edit", image)); } else { return(RedirectToAction("Error", "Home", new { errid = "EditNotAuth" })); } } else { ViewBag.Message = "Image with identifier" + Id + " not found"; ViewBag.Id = Id; return(RedirectToAction("Error", "Home", new { errid = "EditNotFound" })); } }
public ActionResult Delete(int Id) { CheckAda(); String userid = GetLoggedInUser().Id; Image imageEntity = db.Images.Find(Id); if (imageEntity != null) { if (imageEntity.User.Id.Equals(userid)) { ImageView imageView = new ImageView(); imageView.Id = imageEntity.Id; imageView.Uri = ImageStorage.ImageURI(Url, Id); imageView.Caption = imageEntity.Caption; imageView.Description = imageEntity.Description; imageView.DateTaken = imageEntity.DateTaken; imageView.TagName = imageEntity.Tag.Name; imageView.Userid = imageEntity.User.Id; return(View("Delete", imageView)); } else { return(RedirectToAction("Error", "Home", new { errid = "Delete" })); } } else { return(RedirectToAction("Error", "Home", new { errid = "Delete" })); } }
public ActionResult Details(int Id) { CheckAda(); Image imageEntity = db.Images.Find(Id); if (imageEntity != null) { ImageView imageView = new ImageView(); imageView.Id = imageEntity.Id; imageView.Uri = ImageStorage.ImageURI(Url, imageEntity.Id); imageView.Caption = imageEntity.Caption; imageView.Description = imageEntity.Description; imageView.DateTaken = imageEntity.DateTaken; imageView.TagName = imageEntity.Tag.Name; imageView.Userid = imageEntity.User.UserName; LogContext.AddLogEntry(System.Web.HttpContext.Current.User.Identity.Name.Substring(0, System.Web.HttpContext.Current.User.Identity.Name.IndexOf('@')), imageView); return(View(imageView)); } else { // return RedirectToAction("Error", "Home", new { errid = "Details" }); ViewBag.Message = "There is no such image available now !"; IEnumerable <Image> images = ApprovedImages().ToList(); ViewBag.Userid = GetLoggedInUser().Id; return(View("ListAll", images)); } }
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()); } }
public ActionResult Edit(int Id) { CheckAda(); ApplicationUser user = GetLoggedInUser(); if (user == null) { return(RedirectToAction("Login", "Account")); } Image imageEntity = ApplicationDBContext.Images.Find(Id); if (imageEntity != null) { HttpCookie cookie = Request.Cookies.Get("ImageSharing"); if (imageEntity.User.UserName == user.Id) { ViewBag.Message = ""; ViewBag.Tags = new SelectList(ApplicationDBContext.Tags, "Id", "Name", imageEntity.TagId); ImageView image = new ImageView(); image.Id = imageEntity.Id; image.TagId = imageEntity.TagId; image.Caption = imageEntity.Caption; image.Description = imageEntity.Description; image.DateTaken = imageEntity.DateTaken; image.Uri = ImageStorage.ImageURI(Url, imageEntity.Id); return(View("Edit", image)); } else { return(RedirectToAction("Login", "Account")); } } else { return(RedirectToAction("Error", "Home", new { errid = "ImageNotFound" })); } }
public ActionResult Edit(int Id) { CheckAda(); Image imageEntity = db.Images.Find(Id); if (imageEntity != null) { //Validate the person is the owner of the image ApplicationUser userid = GetLoggedInUser(); if (imageEntity.Userid.Equals(userid.Id)) { //HttpCookie cookie = Request.Cookies.Get("ImageSharing"); //if ((cookie != null) && cookie["Userid"] != null && imageEntity.User.Userid.Equals(cookie["Userid"])) //{ ViewBag.Message = ""; ViewBag.Tags = new SelectList(db.Tags, "Id", "Name", imageEntity.TagId); ImagesView image = new ImagesView(); image.Id = imageEntity.Id; image.Uri = ImageStorage.ImageURI(Url, Id); image.TagId = imageEntity.TagId; image.Caption = imageEntity.Caption; image.Description = imageEntity.Description; image.DateTaken = imageEntity.DateTaken; return(View("Edit", image)); } else { return(RedirectToAction("Error", "Home", new { errid = "EditNotAuth" })); } } else { ViewBag.Message = "Image with identifier " + Id + " not found"; ViewBag.Id = Id; return(RedirectToAction("Error", "Home", new { errid = "EditNotFound" })); } }
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()); } }