public ActionResult PlaceBid(AuctionListViewModel allAuctions) { var auctionWithBid = allAuctions.ViewModels.FirstOrDefault(a => a.BidAmount != null); if (auctionWithBid == null) { throw new Exception("PlaceBid was called an no bid was detected for any auction."); } float amount; if (!float.TryParse(auctionWithBid.BidAmount, out amount)) { ViewBag.ErrorMessage = "Wrong format for amount. Please input the correct number."; return(View("Index")); } try { _auctionService.PlaceBid(UserSession.CurrentUser.Username, auctionWithBid); } catch (Exception) { ViewBag.ErrorMessage = "Bit wasn't placed. Something went wrong."; } ClearAllBids(allAuctions); return(RedirectToAction("Index")); }
// M e t h o d s //public IActionResult Index() //{ // IQueryable<Auctions> allAuctions = // repository.GetAllAuctions(); // return View(allAuctions); //IQueryable<Employees> allEmployees = // repository.GetAllEmployees(); //return View(allEmployees); //IQueryable<Inventory> allInventory = // repository.GetAllInventory(); //return View(allInventory); //IQueryable<Sales> allSales = // repository.GetAllSales(); //return View(allSales); //IQueryable<Sellers> allSellers = // repository.GetAllSellers(); //return View(allSellers); //IQueryable<Users> allUsers = // repository.GetAllUsers(); //return View(allUsers); public IActionResult Index(string category) { AuctionListViewModel dto = new AuctionListViewModel(); if (category == null) { dto.Auctions = repository.GetAllAuctions() .OrderBy(a => a.AuctionId); //IQueryable<Auction> someAuctions = // repository.GetAllAuctions() // .OrderBy(a => a.AuctionId); //return View(someAuctions); } else { dto.Auctions = repository.GetAllAuctions() .Where(a => a.Category == category) .OrderBy(a => a.AuctionId); //IQueryable<Auction> someAuctions = // repository.GetAllAuctions() // .Where(a => a.Category == category) // .OrderBy(a => a.AuctionId); //return View(someAuctions); } dto.CurrentCategory = category; return(View(dto)); }
private static void ClearAllBids(AuctionListViewModel allAuctions) { foreach (var auction in allAuctions.ViewModels) { auction.BidAmount = null; } }
public ActionResult MyBids() { ViewBag.Title = "My bids"; var auctionList = new AuctionListViewModel(_auctionService.GetAuctionsWithUsersBid(UserSession.CurrentUser.Username).ToList()); return(View("Index", auctionList)); }
public ActionResult Index() { ViewBag.Title = "Auctions"; var auctionList = new AuctionListViewModel(_auctionService.GetOpenAuctions().ToList()); return(View(auctionList)); }
public async Task <ActionResult> Index(AuctionListViewModel model) { model.Filter.PageSize = PageSize; //model.Filter.CategoryIds = ProcessCategoryIds(model); Session[FilterSessionKey] = model.Filter; Session[CategoryTreesSessionKey] = model.Categories; var result = await AuctionProcessFacade.GetAuctionsAsync(model.Filter); var newModel = await InitializeProductListViewModel(result, model.Categories); return(View("AuctionListView", newModel)); }
public async Task <ActionResult> Index(AuctionListViewModel model) { model.Filter.PageSize = PageSize; Session[FilterSessionKey] = model.Filter; var allAuctions = await AuctionFacade.GetAllAuctionsAsync(new AuctionFilterDto()); var result = (await AuctionFacade.GetAllAuctionsAsync(model.Filter)); var filteredAuctions = model.CategoryId != null?result.Items.Where(x => x.CategoryId == new Guid(model.CategoryId)) : result.Items; var newModel = await InitializeAuctionListViewModel(result, filteredAuctions, (int)allAuctions.TotalItemsCount); return(View("AuctionListView", newModel)); }
/// <summary> /// Processes category IDs by filtering out unchecked categories /// </summary> /// <param name="model">model containing category trees</param> /// <returns>selected categories</returns> private static Guid[] ProcessCategoryIds(AuctionListViewModel model) { var selectedCategoryIds = new List <Guid>(); foreach (var categoryTreeRoot in model.Categories) { if (categoryTreeRoot.IsActive) { selectedCategoryIds.Add(categoryTreeRoot.Id); selectedCategoryIds.AddRange(model.Categories .Where(node => node.ParentId == categoryTreeRoot.Id && node.IsActive) .Select(node => node.Id)); } } return(selectedCategoryIds.ToArray()); }