示例#1
0
        public Task <StandardResponse> AddToCart([FromBody] CartItemRequest req)
        {
            // irrelevant currently
            // verify the session we want to access
            var from = Request.HttpContext.Session.Id;

            // seems to be the place to make sure the item isn't already in the cart
            //make sure the request is for the correct cart
            if (req.cart_id == _cart.GetCart())
            {
                var item   = int.Parse(req.hsmv);
                var canAdd = _cart.AddToCart(item);
                if (canAdd)
                {
                    // record the addition to the cart
                    var details = new ActionLog()
                    {
                        action  = Log.Action.Add,
                        target  = item,
                        cart_id = req.cart_id
                    };
                    _log.Action(details);

                    var result = new StandardResponse()
                    {
                        code    = StatusCode(200),
                        message = "success"
                    };
                    return(Task.FromResult(result));
                }
            }

            var error = new StandardResponse()
            {
                message = @"Your trying to access a cart that 
                isn't yours or the session isn't active bruh. 
                Or maybe the cart didn't add the item correctly."
            };

            return(Task.FromResult(error));
        }