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)); }
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))); }
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))); }