public IHttpActionResult Post([FromBody] AddToCartModel data) { try { var identity = (ClaimsIdentity)User.Identity; var name = identity.Claims.Where(x => x.Type == ClaimTypes.Name).Single().Value; if (data.cartId == 0) { var cart = _business.CreateOrder(name, data.productId); if (cart != null) { return(Ok(cart)); } } else { bool result = false; if (_business.IsExisted(data.productId, data.cartId)) { result = _business.AddMoreItem(data.cartId, data.productId); if (result) { return(Ok(result)); } } else { result = _business.AddToCart(data.productId, data.cartId); return(Ok(result)); } } return(BadRequest()); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(BadRequest()); } }