Exemple #1
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"));
        }
Exemple #2
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"));
        }