Beispiel #1
0
 public ActionResult AddAuction(long startingBid, int auctionDuration, ImageOwner poster)
 {
     DateTime todaysDate = DateTime.Now;
     using (ImageHolderContext ihc = new ImageHolderContext())
     {
         if (todaysDate < todaysDate.AddDays(auctionDuration))
         {
             Auction_ auctionToAdd = new Auction_ { CurrentBid = startingBid, ExpirationDate = DateTime.Now.AddDays(auctionDuration), PosterID = poster.OwnerID, ImageID = poster.ImageID };
             ihc.Auction_.Add(auctionToAdd);
         }
     }
     return View();
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
        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");
        }
Beispiel #4
0
        public ActionResult UpdateBid(ImageOwner image, long bid)
        {
            DateTime todaysDate = DateTime.Now;
            using (ImageHolderContext ihc = new ImageHolderContext())
            {
                Auction_ auction = ihc.Auction_.Where(x => x.ImageID == image.ImageID).FirstOrDefault();
                DateTime? expirationDate = auction.ExpirationDate;
                Models.AccountModels.User bidder = AccountController.GetUserFromID(WebSecurity.CurrentUserId);

                if (todaysDate < expirationDate)
                {
                    if (bidder.Points >= image.Price && bidder.Points >= bid)
                    {
                        auction.CurrentBid = bid;
                        bidder.Points -= (int)bid;
                    }
                }
            }
            return RedirectToAction("Index", "Home");
        }
Beispiel #5
0
        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");
        }
Beispiel #6
0
 public ActionResult SingleImage(ImageOwner imgOwn)
 {
     using (ImageHolderContext ihc = new ImageHolderContext())
     {
        // byte[] img = ihc.Images.Where(x => x.ImageID == imgOwn.ImageID).FirstOrDefault().Image1;
         var base64 = Convert.ToBase64String(ihc.Images.Where(x => x.ImageID == imgOwn.ImageID).FirstOrDefault().Image1);
         var img = String.Format("data:image/gif;base64,{0}", base64);
         ViewBag.Image = img;
         List<string> tagList = ihc.ImageTags.Where(x => x.ImageID == imgOwn.ImageID).Select(x => x.Tag).ToList();
         ViewBag.Tags = tagList;
         List<Comment> Comments = ihc.Comments.Where(x => x.ImageID == imgOwn.ImageID && x.OwnerID == imgOwn.OwnerID).Select(x => x).ToList();
         @ViewBag.LikeCount = ihc.Likes.Where(x => x.ImageID == imgOwn.ImageID && x.OwnerID == imgOwn.OwnerID).Select(x => x).Count();
         imgOwn.Comments = Comments;
         ViewBag.Comments = Comments;
     }
     return View(imgOwn);
 }
Beispiel #7
0
 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);
 }
Beispiel #8
0
 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);
 }