public async Task <IActionResult> Create(AuctionFormModel auctionToCreate) { if (!ModelState.IsValid) { return(View(auctionToCreate)); } //Create(string description, decimal price, DateTime startDate, DateTime endDate, int categoryId, int productId) User loggedUser = await this.userManager.FindByNameAsync(this.User.Identity.Name); if (!this.categoryService.IsCategoryExist(auctionToCreate.CategoryId)) { return(this.BadRequest()); } var categoryForAuction = this.categoryService.GetCategoryById(auctionToCreate.CategoryId); if (!this.productService.IsProductExist(auctionToCreate.ProductId)) { RedirectToAction(nameof(ProductController.List), "Product"); } var productForAuction = await this.productService.GetProductByIdAsync(auctionToCreate.ProductId); if (productForAuction.OwnerId != loggedUser.Id) { return(Forbid()); } if (!IsValid(auctionToCreate)) { return(this.BadRequest()); } await this.auctionService.Create( auctionToCreate.Description, auctionToCreate.Price, auctionToCreate.StartDate, auctionToCreate.EndDate, auctionToCreate.CategoryId, auctionToCreate.ProductId); return(RedirectToAction(nameof(AuctionController.Index), "Auction")); }
public IActionResult Create(int id) { var loggedUserId = this.userManager.GetUserId(User); if (auctionService.IsAuctionExist(id)) { return(this.BadRequest("The selected product is already in active/inactive auction!")); } var newAuction = new AuctionFormModel() { ProductId = id, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(30), IsActive = true }; return(View(newAuction)); }