public ActionResult Add(OrderDetailRequest req) // ok { if (ModelState.IsValid) { if (_orderRepository.CheckStatusOrder(req.OrderId) == 0) { OrderDetail o = _orderDetailRepository.GetOrderDetailFollowOption(req.OrderId, req.ProductId, req.Size); if (o != null) { o.Quantity += req.Quantity; } else { OrderDetail orderDetail = new OrderDetail() { OrderId = req.OrderId, ProductId = req.ProductId, ProductName = req.ProductName, Quantity = req.Quantity, UnitPrice = req.UnitPrice, Size = req.Size }; _orderDetailRepository.Add(orderDetail); } if (_orderDetailRepository.SaveChanges() > 0) { int totalPrice = req.Quantity * req.UnitPrice; int result = UpdateOrderAfterBuy(req.OrderId, totalPrice); if (result != -1) { return(Ok(JsonConvert.SerializeObject(new { totalPrice }))); } return(BadRequest(JsonConvert.SerializeObject(new { Error = "Update total price in order fail." }))); } } return(BadRequest(JsonConvert.SerializeObject(new { Error = "Add fail." }))); } return(BadRequest(ModelState)); }