public ActionResult deleteCompleteImage(bool sure, string IDNum, int IDOrig) { int imageID; int.TryParse(IDNum, out imageID); if (imageID == IDOrig && sure) { using (ImageHolderContext ihc = new ImageHolderContext()) { if (ihc.Flags.Where(x => x.ImageID == IDOrig).Count() >= 1) { try { List <Auction_> AToDelete = new List <Auction_>(); AToDelete = ihc.Auction_.Where(x => x.ImageID == IDOrig).ToList(); ihc.Auction_.RemoveRange(AToDelete); List <Comment> CToDelete = new List <Comment>(); CToDelete = ihc.Comments.Where(x => x.ImageID == IDOrig).ToList(); ihc.Comments.RemoveRange(CToDelete); List <Flag> FToDelete = new List <Flag>(); FToDelete = ihc.Flags.Where(x => x.ImageID == IDOrig).ToList(); ihc.Flags.RemoveRange(FToDelete); List <Purchase> PToDelete = new List <Purchase>(); PToDelete = ihc.Purchases.Where(x => x.ImageID == IDOrig).ToList(); ihc.Purchases.RemoveRange(PToDelete); List <Like> LToDelete = new List <Like>(); LToDelete = ihc.Likes.Where(x => x.ImageID == IDOrig).ToList(); ihc.Likes.RemoveRange(LToDelete); List <ImageTag> TToDelete = new List <ImageTag>(); TToDelete = ihc.ImageTags.Where(x => x.ImageID == IDOrig).ToList(); ihc.ImageTags.RemoveRange(TToDelete); ihc.SaveChanges(); List <ImageOwner> IOToDelete = new List <ImageOwner>(); IOToDelete = ihc.ImageOwners.Where(x => x.ImageID == IDOrig).ToList(); ihc.ImageOwners.RemoveRange(IOToDelete); ihc.SaveChanges(); List <Image> IToDelete = new List <Image>(); IToDelete = ihc.Images.Where(x => x.ImageID == IDOrig).ToList(); ihc.Images.RemoveRange(IToDelete); ihc.SaveChanges(); ViewBag.Message = "Success! Image " + IDOrig + " has been deleted!"; } catch (Exception e) { ViewBag.Message = "Something went wrong with the deletion: " + e.Message + "\n" + e.InnerException; } } else { ViewBag.Message = "This image isn't flagged, why are you purging it completely?"; } } } else { ViewBag.Message = "You missed the confirmation, such drastic action will not be acted upon without the proper convermation."; } ViewBag.submitted = true; return(View()); }
public ActionResult BuyImage(ImageOwner image) { using (ImageHolderContext ihc = new ImageHolderContext()) { Models.AccountModels.User oldOwner = AccountController.GetUserFromID(image.OwnerID); Models.AccountModels.User newOwner = AccountController.GetUserFromID(WebSecurity.CurrentUserId); if (image.Price > 0) { if (image.OwnerID != newOwner.Id && newOwner.Id >= image.Price) { oldOwner.Points += (int)image.Price; newOwner.Points -= (int)image.Price; //Purchase purchase = new Purchase { ImageID = image.ImageID, PurchasePrice = image.Price, PurchaserID = newOwner.MemberID, SellerID = oldOwner.MemberID, TimeOfPurchase = DateTime.Now }; //ihc.Purchases.Add(purchase); ImageOwner newImageOwner = new ImageOwner() { OwnerID = WebSecurity.CurrentUserId, ImageID = image.ImageID, Caption = image.Caption, Title = image.Title, TimeStamp = image.TimeStamp, isForSale = false, isAuction = false, Price = 0 }; ihc.ImageOwners.Add(newImageOwner); ihc.SaveChanges(); } } else { throw new Exception("Price is not greater than 0"); } ihc.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public ActionResult AddTag(ImageOwner imgOwn, string tag) { using (ImageHolderContext ihc = new ImageHolderContext()) { ImageTag newTag = new ImageTag(); newTag.ImageID = imgOwn.ImageID; newTag.Tag = tag; ihc.ImageTags.Add(newTag); ViewBag.message = "Tag successfully added"; ihc.SaveChanges(); } return(View("DisplayImagePage", imgOwn)); }
public ActionResult DeleteImageID(int imageID) { using (ImageHolderContext ihc = new ImageHolderContext()) { var toDelete = ihc.Images.Where(x => x.ImageID == imageID).FirstOrDefault(); if (toDelete != null) { ihc.Images.Remove(toDelete); ViewBag.message = "Image successfully deleted"; } ihc.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public ActionResult DeleteTag(ImageOwner imgOwn, string tag) { using (ImageHolderContext ihc = new ImageHolderContext()) { ImageTag foundTag = ihc.ImageTags.Where(x => x.ImageID == imgOwn.ImageID && x.Tag.Equals(tag)).FirstOrDefault(); if (foundTag != null) { ihc.ImageTags.Remove(foundTag); } ViewBag.message = "Tag successfully deleted"; ihc.SaveChanges(); } return(View("DisplayImagePage", imgOwn)); }
public ActionResult sendMessage(String username, string title, string messageText) { Message m = new Message(); m.ReceiverID = WebSecurity.GetUserId(username); m.Title = title; m.Content = messageText; m.SenderID = WebSecurity.CurrentUserId; m.TimeStamp = DateTime.Now; using (ImageHolderContext ihc = new ImageHolderContext()) { ihc.Messages.Add(m); ihc.SaveChanges(); } return Redirect("MessageCenter"); }
public ActionResult sendMessage(String username, string title, string messageText) { Message m = new Message(); m.ReceiverID = WebSecurity.GetUserId(username); m.Title = title; m.Content = messageText; m.SenderID = WebSecurity.CurrentUserId; m.TimeStamp = DateTime.Now; using (ImageHolderContext ihc = new ImageHolderContext()) { ihc.Messages.Add(m); ihc.SaveChanges(); } return(Redirect("MessageCenter")); }
public ActionResult removeFlagsOnImage() { //Should only be available for admin from the image page. When user pages and messages are up there will be a way to delete specific flags int ImageID; int.TryParse((String)Url.RequestContext.RouteData.Values["id"], out ImageID); using (ImageHolderContext con = new ImageHolderContext()) { var imageFlags = from F in con.Flags where F.ImageID == ImageID select F; foreach (Flag F in imageFlags) { con.Flags.Remove(F); } con.SaveChanges(); } return(RedirectToAction("Index", "Home"));//Right now this redirects to home, it will redirect back to the image page. }
public ActionResult AddComment(Comment com) { using (ImageHolderContext con = new ImageHolderContext()) { try { com.PosterID = WebSecurity.CurrentUserId; com.TimeStamp = DateTime.Now; com.ImageOwner = con.ImageOwners.Where(x => (x.ImageID == com.ImageID) && (x.OwnerID == com.OwnerID)).FirstOrDefault(); com.ImageOwner.Comments.Add(com); con.Comments.Add(com); con.SaveChanges(); } catch (Exception e) { var m = e.Message; } return(RedirectToAction("SingleImage", "Image", com.ImageOwner)); } }
public ActionResult AddComment(Comment com) { using (ImageHolderContext con = new ImageHolderContext()) { try { com.PosterID = WebSecurity.CurrentUserId; com.TimeStamp = DateTime.Now; com.ImageOwner = con.ImageOwners.Where(x=> (x.ImageID==com.ImageID) && (x.OwnerID==com.OwnerID)).FirstOrDefault(); com.ImageOwner.Comments.Add(com); con.Comments.Add(com); con.SaveChanges(); } catch (Exception e) { var m = e.Message; } return RedirectToAction("SingleImage", "Image", com.ImageOwner); } }
public ActionResult AddFlag(Flag f) { using (ImageHolderContext con = new ImageHolderContext()) { f.FlaggerID = WebSecurity.CurrentUserId; f.TimeOfFlag = DateTime.Now; int seekID = 0; int.TryParse((String)Url.RequestContext.RouteData.Values["id"], out seekID); f.ImageID = seekID; // f.Member = con.Members.Where(x => x.MemberID == WebSecurity.CurrentUserId).FirstOrDefault(); f.Image = con.Images.Where(x => x.ImageID == f.ImageID).FirstOrDefault(); con.Flags.Add(f); try { con.SaveChanges(); } catch (Exception e) { var m = e.Message; } } return(RedirectToAction("Index", "Home")); }
public ActionResult LikeImage(ImageOwner imgOwn) { using (ImageHolderContext ihc = new ImageHolderContext()) { if (ihc.Likes.Where(x => x.ImageID == imgOwn.ImageID && x.OwnerID == imgOwn.OwnerID && x.LikerID == WebSecurity.CurrentUserId).Select(x => x).Count() == 0) { Like neolike = new Like(); neolike.ImageID = imgOwn.ImageID; neolike.OwnerID = imgOwn.OwnerID; neolike.LikerID = WebSecurity.CurrentUserId; neolike.Timestamp = DateTime.Now; ihc.Likes.Add(neolike); ihc.SaveChanges(); } /* ImageOwner image = ihc.ImageOwners.Where(x => x.ImageID == imgOwn.ImageID && x.OwnerID == imgOwn.OwnerID).FirstOrDefault(); * if (image != null) * { * image.Likes = image.Likes + 1; * ihc.SaveChanges(); * }*/ } return(RedirectToAction("SingleImage", imgOwn)); }
public ActionResult StoreImage(HttpPostedFileBase file, long price, string title, string caption, long startingBid, int daysOfAuction, String listSelection) { if (file != null) { using (MemoryStream stream = new MemoryStream()) { file.InputStream.CopyTo(stream); byte[] imageArray = stream.GetBuffer(); if (ModelState.IsValid) { using (ImageHolderContext ihc = new ImageHolderContext()) { DateTime time = DateTime.Now; //this is using the test user created in the Index action in home //int ID = 11; int ID = WebSecurity.CurrentUserId; Image newImage = new Image(); newImage.Image1 = imageArray; newImage.DateOfUpload = time; newImage.OriginalPosterID = ID; ihc.Images.Add(newImage); ihc.SaveChanges(); ImageOwner imgOwn = new ImageOwner(); imgOwn.Price = price; if (title != null) { imgOwn.Title = title; } if (caption != null) { imgOwn.Caption = caption; } Image img = ihc.Images.Where(x => x.OriginalPosterID == ID && x.DateOfUpload == time).First(); imgOwn.Image = img; imgOwn.ImageID = img.ImageID; //imgOwn.Member = ihc.Members.Where(x => x.MemberID == ID).First(); imgOwn.OwnerID = ID; imgOwn.TimeStamp = time; if (price > 0) { imgOwn.isForSale = true; } else { imgOwn.isForSale = false; } if (startingBid > 0) { imgOwn.isAuction = true; AddAuction(startingBid, daysOfAuction, imgOwn); } else { imgOwn.isAuction = false; } ihc.ImageOwners.Add(imgOwn); ihc.SaveChanges(); } ViewBag.message = "Image successfully added"; } } } return(RedirectToAction("Profile/" + WebSecurity.CurrentUserId, "Account")); }