public ActionResult Create(AuctionFormViewModel viewModel) { // CHECK IF MODEL IS VALID if (!ModelState.IsValid) return RedirectToAction("Details", "influencer"); var userId = User.Identity.GetUserId(); var gig = unitOfWork.GigsRepository.GetGigForDetails(viewModel.GigID); if (gig == null) return HttpNotFound(); if (gig.UserID != userId) return new HttpUnauthorizedResult(); //IF THERE IS ALREADY AN AUCTION FOR THE GIG, REMOVE THE AUCTION AND POST A NEW ONE if (unitOfWork.AuctionRepository.GetAuctionForGig(viewModel.GigID) != null) unitOfWork.AuctionRepository.RemoveAuctionForGig(viewModel.GigID); //CREATE AUTION var auction = Auction.CreateAuction(viewModel, gig, unitOfWork.AuroraWalletRepository.GetAuroraWallet()); //ADD AUCTION TO DB unitOfWork.AuctionRepository.AddAuctionForGig(auction); unitOfWork.Complete(); // WHEN EVERYTHING IS DONE GO TO INDEX return RedirectToAction("Details", "influencer"); }
//GET AUCTION TO MY PROFILE public ActionResult Index() { var userId = User.Identity.GetUserId(); var gigs = unitOfWork.GigsRepository.GetGigsForAuction(userId).ToList(); var auctions = unitOfWork.AuctionRepository.GetAuctionsForAuction().ToList(); //THE VIEW THAT A USER GETS SHOULD BE ALWAYS UPDATED //WHEN SOMEONE UPDATES THE VIEW ALL AUCTIONS ARE SORTED AGAIN foreach (var auction in auctions) { int index = auctions.IndexOf(auction); auction.PositionOnMarket = index + 1; unitOfWork.Complete(); } // CREATE VIEW MODEL TO SEND IT TO THE VIEW var viewModel = new AuctionFormViewModel { Gigs = gigs, Auctions = auctions.Where(a => a.Gig.UserID == userId) }; return PartialView("_Auction", viewModel); }
private Auction(AuctionFormViewModel viewModel, int specificIndustryID) { Bet = viewModel.Bet; PositionOnMarket = viewModel.PositionOnMarket; GigID = viewModel.GigID; SpecificIndustryID = specificIndustryID; }
public static Auction CreateAuction(AuctionFormViewModel viewModel, Gig gig, AuroraWallet auroraWallet) { gig.User.TransferMoneyToAurora(gig.User.Wallet, auroraWallet, viewModel.Bet); var auction = new Auction(viewModel, gig.SpecificIndustryID); return(auction); }
//FORM FOR THE AUCTION AT MY PROFILE public ActionResult AuctionForm() { var userId = User.Identity.GetUserId(); var gigs = unitOfWork.GigsRepository.GetGigsForAuction(userId).ToList(); var auctions = unitOfWork.AuctionRepository.GetAuctionsForFormAuction(userId).ToList(); // CREATE VIEW MODEL TO SEND IT TO THE VIEW var viewModel = new AuctionFormViewModel { Gigs = gigs, Auctions = auctions }; return PartialView("_AuctionForm", viewModel); }
public ActionResult Create(AuctionFormViewModel viewModel) { if (!ModelState.IsValid) { return(View("Create", viewModel)); } var auction = new Auction() { UserId = User.Identity.GetUserId(), StartDate = DateTime.Now, StartingPrice = Convert.ToInt32(viewModel.StartingPrice), ItemName = viewModel.ItemName, Details = viewModel.Details, EndTime = DateTime.Now.AddDays(viewModel.Days), Image = ProcessImage(viewModel.Image) }; _context.Auctions.Add(auction); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }