Пример #1
0
        internal IEnumerable <Recipe> GetRecipes(RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages)
        {
            using (MyBuyListDBContext context = new MyBuyListDBContext(DBUtils.GetConnection()))
            {
                try
                {
                    DataLoadOptions dlo = new DataLoadOptions();
                    dlo.LoadWith <Recipe>(r => r.User);
                    DataContext.LoadOptions = dlo;

                    var count = (from r in DataContext.Recipes
                                 select r).Count();

                    totalPages = count / pageSize + (count % pageSize > 0 ? 1 : 0);

                    var list = from r in DataContext.Recipes
                               select r;


                    switch (orderBy)
                    {
                    case RecipeOrderEnum.Name:
                        list = list.OrderBy(r => r.RecipeName);
                        break;

                    case RecipeOrderEnum.Publisher:
                        list = list.OrderBy(r => r.User.DisplayName);
                        break;

                    case RecipeOrderEnum.LastUpdate:
                        list = list.OrderByDescending(r => r.ModifiedDate);
                        break;
                    }

                    // paging
                    var list2 = list.Skip((page - 1) * pageSize).Take(pageSize);

                    return(list2.ToList());
                }
                catch
                {
                    totalPages = 0;
                    return(null);
                }
            }
        }
Пример #2
0
        internal IEnumerable <Recipe> GetRecipes(RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages)
        {
            using (DataContext)
            {
                try
                {
                    var count = (from r in DataContext.Recipes
                                 select r).Count();

                    totalPages = count / pageSize + (count % pageSize > 0 ? 1 : 0);

                    var list = from r in DataContext.Recipes
                               select r;


                    switch (orderBy)
                    {
                    case RecipeOrderEnum.Name:
                        list = list.OrderBy(r => r.RecipeName);
                        break;

                    case RecipeOrderEnum.Publisher:
                        list = list.OrderBy(r => r.User.DisplayName);
                        break;

                    case RecipeOrderEnum.LastUpdate:
                        list = list.OrderByDescending(r => r.ModifiedDate);
                        break;
                    }

                    // paging
                    var list2 = list.Skip((page - 1) * pageSize).Take(pageSize);

                    return(list2.ToList());
                }
                catch
                {
                    totalPages = 0;
                    return(null);
                }
            }
        }
Пример #3
0
 public IEnumerable <Menu> GetMenusEx(RecipeDisplayEnum display, int userId, string freeText, int?categoryId, int?diners, int[] menuCats, RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages, out int numMenus)
 {
     return(new MenusDA().GetMenusEx(display, userId, freeText, categoryId, diners, menuCats, orderBy, page, pageSize, out totalPages, out numMenus));
 }
Пример #4
0
 public IEnumerable <Menu> GetMenus(int userid, RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages)
 {
     return(new MenusDA().GetMenus(userid, orderBy, page, pageSize, out totalPages));
 }
Пример #5
0
 public IEnumerable <Recipe> GetRecipesEx(RecipeDisplayEnum display, int userId, string freeText, int?categoryId, int?servings, int[] recipeCats, RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages, out int numRecipes)
 {
     return(new RecipesDA().GetRecipesEx(display, userId, freeText, categoryId, servings, recipeCats, orderBy, page, pageSize, out totalPages, out numRecipes));
 }
Пример #6
0
 public IEnumerable <Recipe> GetRecipes(RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages)
 {
     return(new RecipesDA().GetRecipes(orderBy, page, pageSize, out totalPages));
 }
Пример #7
0
        internal List <Recipe> GetRecipesEx(RecipeDisplayEnum display, int userId, string freeText, int?categoryId, int?servings, int[] recipeCats, RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages, out int numRecipes)
        {
            using (MyBuyListDBContext context = new MyBuyListDBContext(DBUtils.GetConnection()))
            {
                try
                {
                    List <Recipe> recipesList = null;

                    switch (display)
                    {
                    case RecipeDisplayEnum.All:
                        recipesList = GetAllRecipes(userId).ToList();
                        break;

                    case RecipeDisplayEnum.MyRecipes:
                        if (!string.IsNullOrEmpty(freeText))
                        {
                            recipesList = GetUserRecipesList(userId).Where(r => r.RecipeName.Contains(freeText)).ToList();
                        }
                        else
                        {
                            recipesList = GetUserRecipesList(userId).ToList();
                        }
                        break;

                    case RecipeDisplayEnum.MyFavoriteRecipes:
                        if (!string.IsNullOrEmpty(freeText))
                        {
                            recipesList = GetUserFavoritesRecipes(userId).Where(r => r.RecipeName.Contains(freeText)).ToList();
                        }
                        else
                        {
                            recipesList = GetUserFavoritesRecipes(userId).ToList();
                        }
                        break;

                    case RecipeDisplayEnum.ByCategory:
                        if (categoryId.HasValue)
                        {
                            recipesList = this.GetRecipesByCategory(categoryId.Value, userId).ToList();
                        }
                        else
                        {
                            recipesList = this.GetAllRecipes(userId).ToList();
                        }
                        break;

                    case RecipeDisplayEnum.BySearchSimple:
                        recipesList = GetRecipesListByFreeText(freeText).ToList();
                        break;

                    case RecipeDisplayEnum.BySearchAdvanced:
                        recipesList = this.GetRecipesListByComplexSearch(freeText, servings, recipeCats, userId).ToList();
                        break;
                    }

                    var count = (from r in recipesList
                                 select r).Count();

                    numRecipes = count;

                    totalPages = count / pageSize + (count % pageSize > 0 ? 1 : 0);

                    var list = from r in recipesList
                               select r;


                    switch (orderBy)
                    {
                    case RecipeOrderEnum.Name:
                        list = list.OrderBy(r => r.RecipeName);
                        break;

                    case RecipeOrderEnum.Publisher:
                        list = list.OrderBy(r => r.User.DisplayName);
                        break;

                    case RecipeOrderEnum.LastUpdate:
                        list = list.OrderByDescending(r => r.ModifiedDate);
                        break;
                    }

                    // paging
                    var list2 = list.Skip((page - 1) * pageSize).Take(pageSize);

                    return(list2.ToList());
                }
                catch
                {
                    totalPages = 0;
                    numRecipes = 0;
                    return(null);
                }
            }
        }
Пример #8
0
 internal IEnumerable <Menu> GetMenusEx(RecipeDisplayEnum display, int userId, string freeText, int?categoryId, int?diners, int[] menuCats, RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages, out int numMenus)
 {
     return(DataFacade.Instance.GetMenusEx(display, userId, freeText, categoryId, diners, menuCats, orderBy, page, pageSize, out totalPages, out numMenus));
 }
Пример #9
0
 internal IEnumerable <Menu> GetMenus(int userid, RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages)
 {
     return(DataFacade.Instance.GetMenus(userid, orderBy, page, pageSize, out totalPages));
 }
Пример #10
0
 internal IEnumerable <Recipe> GetRecipesEx(RecipeDisplayEnum display, int userId, string freeText, int?categoryId, int?servings, int[] recipeCats, RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages, out int numRecipes)
 {
     return(DataFacade.Instance.GetRecipesEx(display, userId, freeText, categoryId, servings, recipeCats, orderBy, page, pageSize, out totalPages, out numRecipes));
 }
Пример #11
0
 internal IEnumerable <Recipe> GetRecipes(RecipeOrderEnum orderBy, int page, int pageSize, out int totalPages)
 {
     return(DataFacade.Instance.GetRecipes(orderBy, page, pageSize, out totalPages));
 }