public ActionResult remove(int?id) { List <Bookcar> li2 = TempData["Bookcar"] as List <Bookcar>; Bookcar b = li2.Where(x => x.carid == id).SingleOrDefault(); li2.Remove(b); float h = 0; foreach (var item in li2) { h += item.bill; } TempData["bill"] = h; return(RedirectToAction("checkout")); }
public ActionResult BookaCar(Car pi, int Id, string picuplocation, DateTime startdate, DateTime enddate, int Age) { if (Session["Customer_Id"] == null) { return(RedirectToAction("Login", "Home")); } else { Car b = db.Cars.Where(x => x.CarId == Id).SingleOrDefault(); Bookcar bk = new Bookcar(); bk.Prize = b.prize; bk.PickupLoc = picuplocation; bk.carid = b.CarId; bk.cartype = b.CarType; bk.custid = Convert.ToInt32(Session["Customer_Id"].ToString()); bk.custname = Convert.ToString(Session["FirstName"]); bk.age = Age; bk.StartDate = Convert.ToDateTime(startdate); bk.EndDate = Convert.ToDateTime(enddate); DateTime sdate = bk.StartDate; DateTime edate = bk.EndDate; double difference = (edate - sdate).TotalDays; bk.bill = (float)b.prize * (float)difference; ViewBag.msg = "data added..."; if (TempData.Peek("Bookcar") == null) { li.Add(bk); TempData["Bookcar"] = li; } else { List <Bookcar> li2 = TempData["Bookcar"] as List <Bookcar>; li2.Add(bk); TempData["Bookcar"] = li2; } TempData.Keep("Bookcar"); return(RedirectToAction("checkout")); } }