Ejemplo n.º 1
0
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = db.Products.GetById(id);

            if (product == null)
            {
                return(HttpNotFound());
            }

            ProductViewModel currentProduct = ProductViewModel.CreateFromProduct(product);

            Auction currentAuctionEntity = this.db.Auctions.All().FirstOrDefault(auction => auction.Product.Id == currentProduct.Id);

            AuctionDetailedViewModel currentAuction = AuctionDetailedViewModel.CreateFromAuction(currentAuctionEntity);

            ProductDetailedViewModel model = new ProductDetailedViewModel(currentProduct, currentAuction);

            model.SimilarProducts =
                from productEntity in this.db.Products.All()
                .Where(p => p.CategoryId == product.CategoryId)
                .OrderBy(p => Guid.NewGuid())
                .Take(5)
                select new ProductFlatViewModel()
            {
                Id       = productEntity.Id,
                ImageUrl = productEntity.ImageUrl
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Bid(UserBetModel currentBet)
        {
            if (ModelState.IsValid == false)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            string userId = User.Identity.GetUserId();

            ApplicationUser currentUser = this.db.Users.All().FirstOrDefault(user => user.Id == userId);

            Auction currentAuction = this.db.Auctions.All().FirstOrDefault(auction => auction.Id == currentBet.AuctionId);

            if (currentAuction == null || currentUser == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "User or auction doesn't exist."));
            }

            if (currentAuction.Type != AuctionType.Auction)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "This isn't an auction"));
            }

            //if (currentAuction.CurrentBuyer == User.Identity.GetUserName())
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "You are already current buyer.");
            //}

            if (currentAuction.CurrentPrice >= currentBet.OfferedPrice)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest,
                                                string.Format("You have to offer more than {0}.",
                                                              currentAuction.CurrentPrice.ToString("f2", CultureInfo.InvariantCulture))));
            }

            if (DateTime.Compare(DateTime.Now, currentAuction.DateStarted.AddMinutes(currentAuction.Duration)) > 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Auction already expired."));
            }

            Product currentProduct = db.Products.All().FirstOrDefault(product => product.Id == currentAuction.Product.Id);

            currentAuction.Product      = currentProduct;
            currentAuction.CurrentBuyer = currentUser.UserName;
            currentAuction.CurrentPrice = currentBet.OfferedPrice;
            currentAuction.ParticipatingUsers.Add(currentUser);
            currentUser.CurrentAuctions.Add(currentAuction);

            this.db.Auctions.Update(currentAuction);
            this.db.Users.Update(currentUser);
            this.db.SaveChanges();


            return(PartialView("_Auction", AuctionDetailedViewModel.CreateFromAuction(currentAuction)));
        }
Ejemplo n.º 3
0
        public ActionResult GetCurrentBid(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Auction currentAuction = this.db.Auctions.All().FirstOrDefault(auction => auction.Id == id);

            if (currentAuction == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "User or auction doesn't exist."));
            }


            return(PartialView("_BaseAuction", AuctionDetailedViewModel.CreateFromAuction(currentAuction)));
        }
Ejemplo n.º 4
0
        public ActionResult Current(Guid?productId)
        {
            if (productId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Auction currentAuction = this.db.Auctions.All().Include("Product").FirstOrDefault(auction => auction.Product.Id == productId);

            if (currentAuction == null)
            {
                return(Content("There isn't auction for this product any more. Please stay tuned up, for new auctions :)"));
            }

            if (DateTime.Compare(currentAuction.DateStarted.AddMinutes(currentAuction.Duration), DateTime.Now) < 0)
            {
                this.db.Auctions.Delete(currentAuction);
                this.db.SaveChanges();

                return(Content("There isn't auction for this product any more. Please stay tuned up, for new auctions :)"));
            }
            else
            {
                AuctionDetailedViewModel model = new AuctionDetailedViewModel
                {
                    Id           = currentAuction.Id,
                    CurrentPrice = currentAuction.CurrentPrice,
                    DateStarted  = currentAuction.DateStarted,
                    Product      = ProductViewModel.CreateFromProduct(currentAuction.Product),
                    Type         = currentAuction.Type,
                    Duration     = currentAuction.Duration,
                    CurrentBuyer = currentAuction.CurrentBuyer
                };

                return(View(model));
            }
        }
Ejemplo n.º 5
0
 public ProductDetailedViewModel(ProductViewModel product, AuctionDetailedViewModel auction)
     : this(product)
 {
     this.Auction = auction;
 }