private void SetupAuctionStatus() { statusVM = new AuctionStatusViewModel(); StatusView v = new StatusView() { DataContext = statusVM }; ChangeGridControl(v); }
private Auction CreateAuction(auction a) { using (kffg_simulations2Context db = new kffg_simulations2Context()) { simulation simModel = db.simulations.First(s => s.id == a.simulation_id); parameter parameters = db.parameters.First(p => p.id == simModel.parameters_id); Dictionary <string, clock_item> keyToPEA = db.clock_item.Where(ci => ci.pea_group_id == parameters.pea_group_id && ci.item_set_id == parameters.item_set_id) .ToList() .ToDictionary(ci => ForwardAuction.ProductKey(ci), ci => ci); List <bidder> bidders = db.bidders.Where(b => b.simulation_id == a.simulation_id).ToList(); IEnumerable <bidder_assigned_strategy> strats = db.bidder_assigned_strategy.Where(s => s.auction_id == a.id); statusVM = new AuctionStatusViewModel(); return(new Auction(a, keyToPEA, bidders, strats, parameters, statusVM)); } }
public Auction( auction a, Dictionary <string, clock_item> keyToPEA, List <bidder> bidders, IEnumerable <bidder_assigned_strategy> strategies, parameter p, AuctionStatusViewModel auctionVM) { rand = new Random(a.seed); this.keyToPEA = keyToPEA; auctionModel = a; List <AuctionItem> items = CreateAuctionItems(keyToPEA.Values); this.bidders = CreateBidders(bidders, p.activity_requirement, strategies, items); forwardAuction = new SmrForwardAuction(this.bidders.ToArray(), items, p, rand); auctionStatus = new AuctionStatus(); auctionStatusVM = auctionVM; }
public async Task <IActionResult> Auctions(string id, string callBack, string status) { var user = await _db.User.Where(u => u.Id == id).FirstOrDefaultAsync(); if (user == null) { return(NotFound()); } var vm = new AuctionStatusViewModel(); vm.UserId = user.Id; vm.CallBack = callBack; vm.Status = status; var auctions = new List <AuctionHeader>(); if (callBack == SD.CreatedAuctions) { auctions = await _db.AuctionHeader.Include(a => a.User).Where(a => a.SellerId == user.Id).ToListAsync(); } else { var aUsers = await _db.AuctionUser.Where(u => u.UserId == user.Id).ToListAsync(); foreach (var a in aUsers) { var auction = await _db.AuctionHeader.Include(au => au.User).Where(au => au.Id == a.AuctionId).FirstOrDefaultAsync(); auctions.Add(auction); } } var currentDate = DateTime.Now; foreach (var item in auctions) { var products = await _db.AuctionProduct.Include(a => a.Product).Where(a => a.AuctionId == item.Id).ToListAsync(); var itemVM = new AuctionItemViewModel() { AuctionHeader = item, AuctionProduct = products, CallBack = callBack }; itemVM.AuctionUser = await _db.AuctionUser.Include(u => u.User).Where(u => u.AuctionId == item.Id && u.UserId == user.Id).FirstOrDefaultAsync(); if (currentDate < item.BeginDate && status == SD.UpcomingStatus) { vm.Auctions.Add(itemVM); } if (currentDate >= item.BeginDate && currentDate <= item.EndDate && status == SD.ActiveStatus) { vm.Auctions.Add(itemVM); } if (currentDate > item.EndDate && status == SD.PastStatus) { vm.Auctions.Add(itemVM); } } return(View(vm)); }
public async Task <IActionResult> Index(string callBack, string status) { if (!User.Identity.IsAuthenticated && callBack != SD.AllAuctions) { return(NotFound()); } if (User.IsInRole(SD.CustomerUser) && callBack == SD.CreatedAuctions) { return(NotFound()); } var currentDate = DateTime.Now; var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var auItems = new AuctionStatusViewModel(); auItems.CallBack = callBack; auItems.Status = status; var auctions = await _db.AuctionHeader.Include(a => a.User).ToListAsync(); if (callBack == SD.BidedAuctions) { var newAuctions = new List <AuctionHeader>(); var user_auctions = await _db.AuctionUser.Where(a => a.UserId == claim.Value).ToListAsync(); foreach (var a in auctions) { if (UserParticipate(a.Id, user_auctions)) { newAuctions.Add(a); } } auctions = newAuctions; } if (callBack == SD.CreatedAuctions) { auctions = await _db.AuctionHeader.Where(a => a.SellerId == claim.Value).Include(a => a.User).ToListAsync(); } var filterAuctions = new List <AuctionItemViewModel>(); foreach (var a in auctions) { var item = new AuctionItemViewModel(); item.AuctionHeader = a; item.AuctionProduct = await _db.AuctionProduct.Where(ap => ap.AuctionId == a.Id).Include(a => a.Product).ToListAsync(); if (a.BeginDate > currentDate && status == SD.UpcomingStatus) { filterAuctions.Add(item); } if (a.BeginDate <= currentDate && a.EndDate >= currentDate && status == SD.ActiveStatus) { filterAuctions.Add(item); } if (a.EndDate < currentDate && status == SD.PastStatus) { filterAuctions.Add(item); } } auItems.Auctions = filterAuctions; return(View(auItems)); }