public async System.Threading.Tasks.Task <IActionResult> AddAsync( [FromServices] IProductModel productModel, [FromServices] IPaymentService payment, [FromServices] UserManager <AppUser> userManager, [FromServices] ICacheHelper cache, OrderDTO orderDTO, int payId) { if (orderDTO.OrderItems == null || orderDTO.OrderItems == "" || payId <= 0) { return(BadRequest()); } //Parse list order Item List <OrderDetailDTO> orderDetailDTOs = DataHelper.ParserJsonTo <List <OrderDetailDTO> >(orderDTO.OrderItems); if (orderDetailDTOs.Count < 0) { return(Problem(statusCode: 500, detail: "Data invalid")); } orderDTO.MethodPayId = payId; //Payment if (payId == 2) { var re = await payment.OnPayment((int)orderDTO.MethodPayId, orderDTO); if (re == false) { return(Problem()); } } if (User != null) { var email = User.FindFirst(ClaimTypes.NameIdentifier); orderDTO.UserId = email.Value; } var od = _orderModel.AddDTO(orderDTO, orderDetailDTOs); if (od == null) { Problem(statusCode: 500, detail: "Can't add data"); } // productModel.UpdateForOrder(orderDetailDTOs); cache.DataUpdated(CacheKey.PRODUCT); return(Ok()); }