public bool SaveOrder() { using (var db = new RepositoryNS.Repository()) { using (var dbContextTransaction = db.Context.Database.BeginTransaction()) { try { List<Order> orders = new List<Order>(); if (Session["Cart"] != null) { orders = (List<Order>)Session["Cart"]; foreach (var or in orders) db.Add(or); } db.Save(); dbContextTransaction.Commit(); return true; } catch (Exception ex) { dbContextTransaction.Rollback(); return false; } } } }
public ActionResult Delete(int Id) { using (var db = new RepositoryNS.Repository()) { db.Delete<Order>(Id); db.Save(); } List<Order> orders = (List<Order>)Session["Cart"]; if (orders.Count == 0) return Redirect("/"); var ord = orders.Where(x => x.Id != Id); Session["Cart"] = ord; return RedirectToAction("Index"); }
// GET: Cart public ActionResult Index() { List<Order> orders = (List<Order>)Session["Cart"]; List<int> strOrd = new List<int>(); if (orders!=null && orders.Count != 0) { foreach (var or in orders) { strOrd.Add(or.Id); } var db = new RepositoryNS.Repository(); return View(db.Context.Order.Where(x => strOrd.Contains(x.Id)).ToList()); } else{ return Redirect("/"); } }
public ActionResult AddToCard(string DateStart, string DateEnd) { try { List<Order> orders = new List<Order>(); var carAmount = 0; var carName = ""; using (var db = new RepositoryNS.Repository()) { var carID = ((Order)Session["tempOrder"]).CarId; carAmount = db.Context.Car.Where(x => x.Id == carID).Select(x => x.BaseAmount).FirstOrDefault(); carName = db.Context.Car.Where(x => x.Id == carID).Select(x => x.Model ).FirstOrDefault(); } var order = new Order(); order.UserId = ((User)Session["user"]).Id; order.CarId = ((Order)Session["tempOrder"]).CarId; order.DateStart = DateTime.Parse(DateStart); order.DateEnd = DateTime.Parse(DateEnd); TimeSpan ts = (DateTime)order.DateEnd - (DateTime)order.DateStart; order.CassierId = 1; order.Amount = GetAmount(carAmount, false, ts.TotalHours); using (var db = new RepositoryNS.Repository()) { db.Add(order); db.Save(); } if (Session["Cart"] != null) { orders = (List<Order>)Session["Cart"]; orders.Add(order); } else { orders.Add(order); } Session["Cart"] = orders; return Redirect("/CarsCatalog"); } catch (Exception ex) { return RedirectToAction("/CarsCatalog"); } }
public ActionResult AddIdToCart(int Id) { using (var db = new RepositoryNS.Repository()) { var order = new Order(); order.CarId = Id; var car = db.Context.Car.Where(x => x.Id == Id).FirstOrDefault(); Session["tempOrder"] = order; ViewData["CarName"] = car.Mark+" "+car.Model; ViewData["userName"] = ((User)Session["user"]).FirstName + " " + ((User)Session["user"]).LastName; return View(order); } }
public ActionResult Index() { var b = new RepositoryNS.Repository(); var c = b.Context.User.ToList(); return View(); }