예제 #1
0
        public ActionResult AddItemToCart(int?item, float?itemQuantity)
        {
            var msgType = false;
            var msg     = Requestor.Req_Cart_ErrorNoItem;

            try
            {
                if (Application.LoggedRequestorId != null)
                {
                    var userId = (int)Application.LoggedRequestorId;

                    if (item != null && itemQuantity != null)
                    {
                        var itemId   = (int)item;
                        var itemQuan = (float)itemQuantity;

                        CartRepository.AddItemToCart(userId, itemId, itemQuan);

                        msgType = true;
                        msg     = Requestor.Req_Cart_ItemAdded;
                    }
                }
                else
                {
                    msg = Common.ErrorMsgForSession;
                }
            }
            catch (Exception exc)
            {
                msg = exc.Message;
                Logger.LogError(exc, "Error while adding item to cart from Requestor zone");
            }

            return(Json(new
            {
                success = msgType,
                message = msg
            }));
        }
        public IActionResult PostItem(string userName, [FromBody] ItemDTO item)
        {
            var cart = _cartRepository.AddItemToCart(userName, item);

            return(Created("", cart));
        }