public IActionResult ConditionFilter(bool isNew, bool myAucts = false) { var vm = new AuctionIndexViewModel { Categories = context.Categories.ToList() }; IQueryable <Auction> auctions; if (isNew) { auctions = context.Auctions.Include(a => a.Article).Include(a => a.User).Where(a => a.Article.IsNew); } else { auctions = context.Auctions.Include(a => a.Article).Include(a => a.User).Where(a => !a.Article.IsNew); } if (myAucts) { var userName = User.Identity.Name; if (userName != null) { var userId = context.Users.Single(u => u.UserName == userName).Id; vm.Auctions = auctions.Where(a => a.UserId == userId).ToList(); return(View("MyAuctions", vm)); }//else mandar error aqui y en todos los filtros } vm.Auctions = auctions.ToList(); return(View("Index", vm)); }
public IActionResult Index() { var date = DateTime.Now; var vm = new AuctionIndexViewModel { Auctions = context.Auctions.Include(a => a.Article).ToList().Where(a => a.Start <= date && a.Start + a.Duration > date || a.Start > date), Categories = context.Categories.ToList(), UserIsAdmin = User.IsInRole("Admin") }; return(View(vm)); }
public IActionResult MyAuctions() { var currentUserName = User.Identity.Name; var userId = context.Users.Single(u => u.UserName == currentUserName).Id; var date = DateTime.Now; var vm = new AuctionIndexViewModel { Auctions = context.Auctions.Include(a => a.Article).Where(a => a.UserId == userId).ToList(), Categories = context.Categories.ToList() }; return(View(vm)); }
public IActionResult AllFilter(bool myAucts = false) { var vm = new AuctionIndexViewModel { Categories = context.Categories.ToList() }; if (myAucts) { var userName = User.Identity.Name; var userId = context.Users.Single(u => u.UserName == userName).Id; vm.Auctions = context.Auctions.Include(a => a.Article).Where(a => a.UserId == userId).ToList(); return(View("MyAuctions", vm)); } vm.Auctions = context.Auctions.Include(a => a.Article).ToList(); return(View("Index", vm)); }
public async Task <IActionResult> Index() { IQueryable <Bet> bets = db.Bets; if (db.Lots.Count() != 0 && db.Lots.FirstOrDefault().Status == true && db.Lots.FirstOrDefault().endDate < DateTimeOffset.UtcNow) { return(RedirectToAction("EndAuction")); } AuctionIndexViewModel viewModel = new AuctionIndexViewModel { Bets = await bets.AsNoTracking().ToListAsync(), ActualLot = db.Lots.FirstOrDefault() }; //if (viewModel.ActualLot != null) viewModel.ActualLot.endDate = viewModel.ActualLot.endDate.ToLocalTime(); return(View(viewModel)); }
public IActionResult StateFilter(int state, bool myAucts = false) { var vm = new AuctionIndexViewModel { Categories = context.Categories.ToList() }; var date = DateTime.Now; if (state == 1)//pasadas { vm.Auctions = context.Auctions.Include(a => a.Article).Include(a => a.User).ToList().Where(a => a.Duration < date - a.Start); } else if (state == 2)//en curso { vm.Auctions = context.Auctions.Include(a => a.Article).Include(a => a.User).ToList().Where(a => a.Start <= date && a.Start + a.Duration > date); //auctions = context.Auctions.Include(a => a.Article).Include(a => a.User).Where(a => a.Start <= date && a.Start + a.Duration > date); } else//pendientes { vm.Auctions = context.Auctions.Include(a => a.Article).Include(a => a.User).Where(a => a.Start > date).ToList(); } if (myAucts) { var userName = User.Identity.Name; if (userName != null) { var userId = context.Users.Single(u => u.UserName == userName).Id; vm.Auctions = vm.Auctions.Where(a => a.UserId == userId); return(View("MyAuctions", vm)); }//else mandar error aqui y en todos los filtros } return(View("Index", vm)); }