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 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 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 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 DeleteImage(Image img) { if (img != null) { using (ImageHolderContext ihc = new ImageHolderContext()) { var toDelete = ihc.Images.Where(x => x.ImageID == img.ImageID).FirstOrDefault(); if (toDelete != null) { ihc.Images.Remove(toDelete); ViewBag.message = "Image successfully deleted"; } ihc.SaveChanges(); } } return RedirectToAction("Index", "Home"); }
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"); }
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 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); }