public ActionResult UpdateOrderDetail(UpdateOrderDertail req)
 {
     if (ModelState.IsValid)
     {
         if (_orderRepository.CheckStatusOrder(req.OrderId) == 0)
         {
             if (_orderDetailRepository.CheckOrderDetailBelongToOrder(req.OrderDetailId, req.OrderId) == 1)
             {
                 Order order = _orderRepository.Get(req.OrderId);
                 if (order.UserId.Equals(req.UserId))
                 {
                     OrderDetail orderDetail = _orderDetailRepository.Get(req.OrderDetailId);
                     if (orderDetail != null)
                     {
                         int price = req.UnitPrice;
                         if (req.Mode == 1)
                         {
                             orderDetail.Quantity += 1; // nếu user giảm quantity thì quantity âm
                         }
                         else if (req.Mode == 0)
                         {
                             orderDetail.Quantity -= 1;
                             price = -price;
                         }
                         else
                         {
                             return(BadRequest(JsonConvert.SerializeObject(new { message = "Mode must between 1 or 0" })));
                         }
                         if (_orderDetailRepository.SaveChanges() == 1)
                         {
                             int result = UpdateOrderAfterBuy(req.OrderId, price);
                             if (result != -1)
                             {
                                 return(Ok(JsonConvert.SerializeObject(new { totalPrice = result })));
                             }
                         }
                         return(BadRequest(JsonConvert.SerializeObject(new { message = "Server Error." })));
                     }
                 }
                 return(BadRequest(JsonConvert.SerializeObject(new { message = "The order is not macth to user." })));
             }
             return(BadRequest(JsonConvert.SerializeObject(new { message = "Order detail is not match to order." })));
         }
         return(BadRequest(JsonConvert.SerializeObject(new { message = "The cart is done." })));
     }
     return(BadRequest(ModelState));
 }