public async Task <IActionResult> ReOrder([FromBody] ReorderRequest reorderRequest) { try { var Cart = await _cartService.GetCartByUserIdAsync(reorderRequest.UserId); var orderItems = await _orderItemService.GetOrderItems(reorderRequest.OrderId); var ListUnActive = new List <Product>(); if (orderItems != null) { for (int i = 0; i < orderItems.Count; i++) { var CheckProductActive = await _productService.CheckProductsIfActive(orderItems[i].ProductId); if (!CheckProductActive) { var product = _productService.GetProductById(orderItems[i].ProductId); ListUnActive.Add(product); } } if (ListUnActive.Count == 0) { await _cartItemService.DeleteCartItemByUserAsync(reorderRequest.UserId); for (int i = 0; i < orderItems.Count; i++) { var CartItem = new CartItem { CartId = Cart.Id, ProductId = orderItems[i].ProductId, Quantity = orderItems[i].Quantity, CreatedAt = DateTime.Now }; var createItem = await _cartItemService.CreateCartItemAsync(CartItem); } return(Ok(await _cartItemService.GetCartItemByUserIdAsync(reorderRequest.UserId))); } else { return(NotFound(new { status = NotFound().StatusCode, message = "There are inactive products", Inactive_Products = ListUnActive })); } } return(NotFound(new { status = NotFound().StatusCode, message = "Not Found" })); } catch (Exception ex) { return(BadRequest(new { status = BadRequest().StatusCode, message = ex.Message })); } }