Ejemplo n.º 1
0
        /// <summary>
        /// Get a user's orders from the database.
        /// </summary>
        /// <param name="id">
        /// string: the userId
        /// </param>
        /// <returns>
        /// List<OrderCart>: a List of OrderCart entity objects
        /// </returns>
        public async Task <List <OrderCart> > GetUserOrders(string userId)
        {
            var orders = await _context.OrderCart
                         .Where(x => x.UserId == userId)
                         .OrderByDescending(x => x.CartId)
                         .ToListAsync();

            if (orders == null)
            {
                return(orders);
            }
            foreach (var order in orders)
            {
                if (order != null)
                {
                    order.CartItems = await _orderItem.GetUserOrderItems(order.Id);
                }
            }
            return(orders);
        }