public async Task <IActionResult> GetAll([FromQuery] string UserId) { var advertize = await _AdvertisingService.GetAdvertisingAsync(1); var CatgTop = await _CategoryService.GetCategoriesTopAsync(); var ProdMostRecent = await _ProductService.GetProductsMostRecentAsync(UserId, 8); var MostWanted = await _ProductService.GetProductsMostWantedAsync(UserId, 8); var TopRated = await _ProductService.GetProductsTopRatedAsync(UserId, 8); var Offers = await _OffersService.GetOffersTopAsync(UserId, 8); var CartItem = await _cartItemService.GetCartItemByUserIdAsync(UserId); var OrderStatus = await _orderService.GetLastOrderStatusNo(UserId); var userNotifCount = _userNotificationCountService.getCountByUser(UserId); int ItemCount = 0; for (int i = 0; i < CartItem.Count; i++) { ItemCount += CartItem[i].Quantity; } var obj = new { Advertize = advertize, Category_Tob = CatgTop, Product_Most_Recent = ProdMostRecent, Product_Most_Wanted = MostWanted, Product_TopRated = TopRated, Offers = Offers, Cart_Items_Count = ItemCount, Order_Status = OrderStatus, notification_count = userNotifCount }; return(Ok(obj)); }
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 })); } }
public async Task <IActionResult> GetCartItemByUser([FromRoute] string userId) { return(Ok(await _cartItemService.GetCartItemByUserIdAsync(userId))); }