public ActionResult ListPurchased() { try { if (User == null || string.IsNullOrEmpty(User.Identity.Name)) { return(PartialView(new List <PurchaseView>())); } ManagerQuery manager = new ManagerQuery(); var UserID = manager.GetAllUsers().Where(p => p.UserName == User.Identity.Name).Select(p => p.ID).FirstOrDefault(); var model = new List <PurchaseView>(); var lstPurchased = manager.AllPurchases().Where(p => p.UserId.HasValue && p.UserId.Value == UserID && p.PurchasesStatus.HasValue && p.PurchasesStatus.Value == 1).ToList(); if (lstPurchased.Count > 0) { foreach (var pur in lstPurchased) { var purView = new PurchaseView(pur); purView.Availlability = (pur.CarID.HasValue && pur.PurchaseDate.HasValue && pur.ReturnDate.HasValue) ? CheckCarAvailability(pur.PurchaseDate.Value, pur.ReturnDate.Value, pur.CarID.Value) : false; model.Add(purView); } } return(PartialView(model)); } catch { return(PartialView(new List <PurchaseView>())); } }
public ActionResult _List(int?gear, int?model, string manufa, decimal?price, DateTime?purchaseDate, DateTime?returnDate) { var domaninCars = guest.ListCar(gear, model, manufa, price, purchaseDate, returnDate); int UserID = 0; if (User != null && !string.IsNullOrEmpty(User.Identity.Name)) { UserID = manager.GetAllUsers().Where(p => p.UserName == User.Identity.Name).Select(p => p.ID).FirstOrDefault(); } var listSelect = guest.ListCarSelect(UserID).Select(p => p.CarID).ToList(); var result = domaninCars.Where(p => !listSelect.Contains(p.CarID)).ToList(); return(PartialView(result)); }
public ActionResult MyBusket() { //var deals = Session[DEALS_IN_THE_BUSKET] as List<PurchaseView>; ManagerQuery manager = new ManagerQuery(); if (User == null || string.IsNullOrEmpty(User.Identity.Name)) { return(RedirectToAction("Login", "Home")); } var UserID = manager.GetAllUsers().Where(p => p.UserName == User.Identity.Name).Select(p => p.ID).FirstOrDefault(); var listPur = manager.AllPurchases().Where(p => p.UserId == UserID && (!p.PurchasesStatus.HasValue || p.PurchasesStatus.Value == 0)).ToList(); List <PurchaseView> deals = new List <PurchaseView>(); if (listPur.Count > 0) { foreach (var pur in listPur) { var purView = new PurchaseView(pur); purView.Availlability = (pur.CarID.HasValue && pur.PurchaseDate.HasValue && pur.ReturnDate.HasValue) ? CheckCarAvailability(pur.PurchaseDate.Value, pur.ReturnDate.Value, pur.CarID.Value) : false; deals.Add(purView); } } return(View(deals)); }