コード例 #1
0
        public void SaveCart(Cart cart)
        {
            var existingCart = _reservationsModel.Carts.FirstOrDefault(c => c.SessionId == cart.SessionId);

            if (existingCart != null)
            {
                existingCart._Products = cart._Products;
            }
            else
            {
                _reservationsModel.Carts.Add(cart);
            }
            _reservationsModel.SaveChanges();
        }
コード例 #2
0
        public void UpdateOrAddSession(string sessionId, bool isLoggedInUser)
        {
            Session session = _sessionsModel.Sessions.FirstOrDefault(id => id.SessionId == sessionId);

            if (session == null)
            {
                session = new Session(sessionId, isLoggedInUser);
                _sessionsModel.Sessions.Add(session);
            }
            else
            {
                session.LastTimeActive = DateTime.Now;
            }

            _sessionsModel.SaveChanges();
        }