Example #1
0
        public ActionResult ByUser()
        {
            string userId = User.Identity.GetUserId();

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

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

            IEnumerable <AuctionDetailedViewModel> auctions =
                from auctionEntity in currentUser.CurrentAuctions
                select new AuctionDetailedViewModel
            {
                Id           = auctionEntity.Id,
                ProductName  = auctionEntity.Product.Title,
                DateStarted  = auctionEntity.DateStarted,
                Product      = ProductViewModel.CreateFromProduct(auctionEntity.Product),
                CurrentBuyer = auctionEntity.CurrentBuyer,
                Duration     = auctionEntity.Duration
            };


            return(View(auctions));
        }
Example #2
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));
        }
Example #3
0
        public static AuctionDetailedViewModel CreateFromAuction(Auction auction)
        {
            if (auction == null)
            {
                return(null);
            }

            AuctionDetailedViewModel result = new AuctionDetailedViewModel
            {
                CurrentPrice = auction.CurrentPrice,
                DateStarted  = auction.DateStarted,
                Id           = auction.Id,
                Product      = ProductViewModel.CreateFromProduct(auction.Product),
                Type         = auction.Type,
                Duration     = auction.Duration,
                CurrentBuyer = auction.CurrentBuyer
            };

            return(result);
        }
Example #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));
            }
        }