/// <summary> /// Creates auction, example URL call can be found in test folder. /// </summary> /// <param name="model">Created auction details.</param> /// <returns>Message describing the action result.</returns> public async Task <string> Post([FromBody] AuctionCreateModel model) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var auctionId = await AuctionFacade.CreateAuctionWithCategoryNameAsync(model.Auction, model.CategoryName); if (auctionId.Equals(Guid.Empty)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } return($"Created auction with id: {auctionId}, within {model.CategoryName} category."); }
public async Task <string> Post([FromBody] AuctionCreateModel model) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var auctionId = await AuctionProcessFacade.CreateAuctionWithCategoryNameForUserAsync(model.Auction, model.UserEmail, model.CategoryName); if (auctionId.Equals(Guid.Empty)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } return($"Auction was created with id: {auctionId}"); }
public ActionResult Create(AuctionCreateModel model) { string loggedUserId = User.Identity.GetUserId(); ApplicationUser currentUser = this.db.Users.GetById(loggedUserId); if (ModelState.IsValid) { Product currentProduct = this.db.Products.All().FirstOrDefault(product => product.Id == model.ProductId); Auction newAuction = this.db.Auctions.All().FirstOrDefault(auction => auction.Product.Id == model.ProductId); if (newAuction != null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "There is already an auction for this product")); } newAuction = new Auction { Id = Guid.NewGuid(), DateStarted = DateTime.Now, Duration = model.Duration, Product = currentProduct, Type = model.Type, CurrentPrice = currentProduct.StartingPrice }; this.db.Auctions.Add(newAuction); this.db.SaveChanges(); return(RedirectToAction("Details", "Products", new { id = currentProduct.Id })); } var ownProducts = this.db.Products .All() .Where(product => product.Owner.Id == currentUser.Id) .ToList() .Select(productEntity => new SelectListItem() { Text = productEntity.Title, Value = productEntity.Id.ToString() }); ViewBag.OwnProducts = ownProducts; return(View()); }