コード例 #1
0
        public async Task <IEnumerable <OrderReturnDto> > GetUserOrder(int userId, int currentMonth, int currentYear)
        {
            var orderItems = await _orderItemRepository.CustomFind(x => x.Order.User.Id == userId &&
                                                                   x.CreatedAt.Month == currentMonth &&
                                                                   x.CreatedAt.Year == currentYear,
                                                                   x => x.Order,
                                                                   x => x.Order.OrderStatus);

            var orders = new List <OrderReturnDto>();

            orders = _mapper.Map(orderItems.GroupBy(x => x.Order).Select(x => x.Key).ToList(), orders);

            foreach (var item in orders)
            {
                item.Description = string.Join(",", orderItems.Where(x => x.Order.Id == item.Id).Select(x => x.ProductName).ToList());
            }

            return(orders);
        }