예제 #1
0
        public async Task <bool> MakeNewCart()
        {
            Cart new_cart = new Cart()
            {
                cart_id      = Guid.NewGuid().ToString(),
                session_id   = _session.CurrentSession(),
                created_date = DateTime.Now,
            };
            var _query  = $@"INSERT INTO cart VALUES (@cart, @session, @date)";
            var _params = new
            {
                cart    = new_cart.cart_id,
                session = new_cart.session_id,
                date    = new_cart.created_date
            };

            using (var conn = new NpgsqlConnection(_conn))
            {
                var cart = await conn.ExecuteAsync(_query, _params);

                if (cart == 1)
                {
                    _session.SetSession("cart", new_cart.cart_id);
                    return(true);
                }
            }
            // TODO should add some feedback,
            // but basically unless everything works we fails yo
            return(false);
        }
예제 #2
0
        public string InitializeCart()
        {
            // TODO
            // check session expiration
            // currently this just returns true
            // needs time check in session utility
            if (_session.IsValid())
            {
                if (!_cart.NeedACart()) // kind of a double negative but checks session for cart-id
                {
                    return(_session.GetSession("cart"));
                }

                if (_cart.MakeNewCart().Result == true) // hit when starting new session
                {
                    IPAddress ip      = Request.HttpContext.Connection.LocalIpAddress;
                    var       details = new SessionLog() // log the session information
                    {
                        cart_id    = _session.GetSession("cart"),
                        session_id = _session.CurrentSession(),
                        client_ip  = ip.ToString()
                    };
                    _log.Session(details);
                    return(details.cart_id); // return with the cart id
                }
                // TODO error creating the new cart
            }
            var error = "you messed up"; // error in session. figure out how to reset

            return(error);
        }