public void End() { shoppingcartfaridehEntities db = new shoppingcartfaridehEntities(); var maxDateTimeThreshhold = DateTime.Now.AddMinutes(-1 * 2); var expiredProductVisits = from ProductVisit in db.ProductVisits where ProductVisit.updated <= maxDateTimeThreshhold select ProductVisit; if (expiredProductVisits != null) { foreach (ProductVisit productVisit in expiredProductVisits) { db.ProductVisits.Remove(productVisit); } db.SaveChanges(); } var abandoneVisits = from v in db.Visits where !db.ProductVisits.Any(pv => pv.sessionID == v.sessionID) select v; if (abandoneVisits != null) { foreach (Visit visit in abandoneVisits) { db.Visits.Remove(visit); } db.SaveChanges(); } }
public void Delete(string id) { shoppingcartfaridehEntities db = new shoppingcartfaridehEntities(); Visit visit = db.Visits.Where(v => v.sessionID == id).FirstOrDefault(); db.Visits.Remove(visit); db.SaveChanges(); }
public void Add() { shoppingcartfaridehEntities db = new shoppingcartfaridehEntities(); SessionHelper sessionHelper = new SessionHelper(); Visit visit = new Visit(); visit.sessionID = sessionHelper.SessionID; Delete(visit.sessionID); visit.started = DateTime.Now; db.Visits.Add(visit); db.SaveChanges(); }
public ActionResult Cancel() { ProductVisitRepository productVisitRepository = new ProductVisitRepository(); shoppingcartfaridehEntities db = new shoppingcartfaridehEntities(); SessionHelper sessionHelper = new SessionHelper(); string sessionid = sessionHelper.SessionID; TempData["msg"] = "<script>alert('Are you sure that you want to remove all items from shopping cart?');</script>"; if (sessionid != null) { db.ProductVisits.Where(p => p.sessionID == sessionid).ToList().ForEach(p => db.ProductVisits.Remove(p)); } db.SaveChanges(); return(View()); }
public bool Delete(int id, string sessionid) { shoppingcartfaridehEntities db = new shoppingcartfaridehEntities(); ProductVisit productVisit = db.ProductVisits.Where(pv => pv.productID == id && pv.sessionID == sessionid).FirstOrDefault(); try { db.ProductVisits.Remove(productVisit); db.SaveChanges(); return(true); } catch { return(false); } }
public void Initialize() { shoppingcartfaridehEntities db = new shoppingcartfaridehEntities(); // HttpContext.Current.Session[SESSION_START] = DateTime.Now; try { Visit newVisit = new Visit(); newVisit.sessionID = SessionID; newVisit.started = DateTime.Now; db.Visits.Add(newVisit); db.SaveChanges(); } catch (Exception e) { } }
public void Add(int id, int Quantity, string sessionid) { shoppingcartfaridehEntities db = new shoppingcartfaridehEntities(); try { ProductVisit productVisit = new ProductVisit(); SessionHelper sessionHelper = new SessionHelper(); sessionid = sessionHelper.SessionID; // Delete(id, sessionid); productVisit.productID = id; productVisit.sessionID = sessionHelper.SessionID; productVisit.updated = DateTime.Now; productVisit.qtyOrdered = Quantity; db.ProductVisits.Add(productVisit); db.SaveChanges(); } catch { } }