Exemplo n.º 1
0
 public ActionResult GetOrderId(string id)
 {
     if (ModelState.IsValid)
     {
         try
         {
             int orderId = _orderRepository.GetOrderIdByUserId(id);
             if (orderId != -1)
             {
                 int    amountOrderDetail = _orderDetailRepository.GetAmountByOrderId(orderId);
                 string json = JsonConvert.SerializeObject(new { OrderId = orderId, AmountDetail = amountOrderDetail, Message = "Your cart is ready." });
                 return(Ok(json));
             }
             else
             {
                 string json = JsonConvert.SerializeObject(new { OrderId = -1, AmountDetail = -1, Message = "No cart right now." });
                 return(BadRequest(json));
             }
         }
         catch (Exception e)
         {
             return(BadRequest(JsonConvert.SerializeObject(new { OrderId = -1, AmountDetail = -1, Message = e.InnerException.Message })));
         }
     }
     return(BadRequest(ModelState));
 }