示例#1
0
        public IEnumerable <DishModelShortInfo> FilterDishes(int page, int pageSize, string filter = null)
        {
            IQueryable <Dish> dishesFromDb;

            if (!string.IsNullOrEmpty(filter))
            {
                if (filter == "-random")
                {
                    var randNum = new Random();
                    var skip    = randNum.Next(1, TotalFilteredDish("") - pageSize);
                    dishesFromDb = Database.Dish.QueryToTable
                                   .OrderBy(m => m.id)
                                   .Skip(skip)
                                   .Take(pageSize);
                }
                else
                {
                    dishesFromDb = Database.Dish.QueryToTable.Where(
                        m => m.Name.ToLower().Contains(filter.ToLower().Trim()))
                                   .OrderBy(m => m.id)
                                   .Skip(page * pageSize)
                                   .Take(pageSize);
                }
            }
            else
            {
                dishesFromDb = Database.Dish.QueryToTable
                               .OrderBy(m => m.id)
                               .Skip(page * pageSize)
                               .Take(pageSize);
            }
            return(UniteDishAndImage.GetDishImagesFromDbAndUnite(Database, dishesFromDb));
        }
示例#2
0
        public IEnumerable <DishModelShortInfo> GetPlatesByDate(DateTime date, User user)
        {
            var fromDb =
                Database.OrderDishes.QueryToTable.Where(x => x.Order.Date == date.Date && x.Order.User.id == user.id);
            var dishesInfo =
                UniteDishAndImage.GetDishImagesFromDbAndUnite(Database, fromDb.Select(x => x.Dish)).ToList();
            var dishCount = fromDb.Select(x => x.Count).ToList();

            for (int i = 0; i < dishesInfo.Count; i++)
            {
                dishesInfo[i].Count = dishCount[i];
            }
            return(dishesInfo);
        }
示例#3
0
        public IEnumerable <DishModelShortInfo> Filter(DateTime dateTime, string filter)
        {
            IQueryable <DayDishSet> fromDb;

            if (string.IsNullOrEmpty(filter))
            {
                fromDb = Database.DayDish.QueryToTable.Where(m => m.Date == dateTime.Date).OrderBy(m => m.id);
            }
            else
            {
                //if filter set
                fromDb = Database.DayDish.QueryToTable.Where(m => m.Date == dateTime.Date)
                         .Where(m => m.Dish.Name.ToLower().Contains(filter.ToLower().Trim()))
                         .OrderBy(m => m.id);
            }
            return(UniteDishAndImage.GetDishImagesFromDbAndUnite(Database, fromDb.Select(set => set.Dish).ToList()));
        }