示例#1
0
        public List <StatisticsDto> GetStatistics(QueryDto filter)
        {
            var query = from a in _dataContext.Orders
                        join b in _dataContext.Order_Foods
                        on a.Id equals b.OrderId
                        join c in _dataContext.FoodMenus
                        on b.FoodId equals c.Id
                        select new
            {
                a.CreateTime,
                c.Name,
                b.Count,
                c.Price
            };

            if (filter.Start != null)
            {
                query = query.Where(x => x.CreateTime >= filter.Start);
            }
            if (filter.End != null)
            {
                query = query.Where(x => x.CreateTime <= filter.End);
            }

            var data = query.ToList();

            var list = data.GroupBy(x => x.Name).Select(x => new StatisticsDto
            {
                FoodName = x.Key,
                Count    = x.Sum(y => y.Count),
                Price    = x.Sum(y => y.Price)
            });

            return(list.ToList());
        }
示例#2
0
        public List <FoodMenu> GetFoodMenus(QueryDto filter, out int total)
        {
            var query = _dataContext.FoodMenus.AsQueryable();

            if (!string.IsNullOrEmpty(filter.Type))
            {
                query = query.Where(x => x.Type == filter.Type);
            }

            var foods = query.Skip((filter.PageNo - 1) * filter.PageSize).Take(filter.PageSize).ToList();

            total = query.Count();
            return(foods);
        }