示例#1
0
        public IActionResult Index()
        {
            var result = _dashboardRepository.GetCounts(this.loginUserId, this.isAdmin);

            result.TotalCategories = _categoryRepository.GetList(this.loginUserId, this.isAdmin).Count;
            result.TotalMenuItems  = _menuItemRepository.GetList(this.loginUserId, this.isAdmin).Count;
            result.TotalMenu       = _menuRepository.GetList(this.loginUserId, this.isAdmin).Count;

            return(View(result));
        }
        public IActionResult GetList(DataTableAjaxPostModel param)
        {
            int recordsTotal = 0;
            var result       = _menuItemRepository.GetList(this.loginUserId, isAdmin);

            if (result.Any())
            {
                recordsTotal = result.Count;

                if (param.conceptId > 0)
                {
                    result = result.Where(x => x.MenuItemConcepts.Any(x => x.ConceptId == param.conceptId)).ToList();
                }

                if (param.categoryId > 0)
                {
                    result = result.Where(x => x.CategoryId == param.categoryId).ToList();
                }

                if (param.menuItemId > 0)
                {
                    result = result.Where(x => x.Id == param.menuItemId).ToList();
                }


                if (param.status == Helper.Active)
                {
                    result = result.Where(x => x.Status).ToList();
                }
                else if (param.status == Helper.Inactive)
                {
                    result = result.Where(x => !x.Status).ToList();
                }

                result.ForEach(x => x.ConceptName = string.Join(", ", x.MenuItemConcepts.Select(x => x.ConceptName).ToList()));

                if (!string.IsNullOrEmpty(param.search.value))
                {
                    var search = param.search.value;
                    result = result.Where(x => x.PLU.ToLower().Contains(search.ToLower()) ||
                                          x.Name.ToLower().Contains(search.ToLower()) ||
                                          x.ConceptName.ToLower().Contains(search.ToLower()) ||
                                          x.CategoryName.ToLower().Contains(search.ToLower()) ||
                                          x.Currency.ToLower().Contains(search.ToLower()) ||
                                          x.Price.ToString().Contains(search.ToLower()) ||
                                          x.LabelEN.ToLower().Contains(search.ToLower()) ||
                                          x.LabelAR.ToLower().Contains(search.ToLower())
                                          ).ToList();
                }
            }

            string order    = Convert.ToString(param.order[0].column);
            string orderDir = param.order[0].dir;

            switch (order)
            {
            case "0":
                result = orderDir.Equals("DESC", StringComparison.CurrentCultureIgnoreCase) ? result.OrderByDescending(p => p.PLU).ToList() : result.OrderBy(p => p.PLU).ToList();
                break;

            case "1":
                result = orderDir.Equals("DESC", StringComparison.CurrentCultureIgnoreCase) ? result.OrderByDescending(p => p.Name).ToList() : result.OrderBy(p => p.Name).ToList();
                break;

            case "2":
                result = orderDir.Equals("DESC", StringComparison.CurrentCultureIgnoreCase) ? result.OrderByDescending(p => p.ConceptName).ToList() : result.OrderBy(p => p.ConceptName).ToList();
                break;

            case "3":
                result = orderDir.Equals("DESC", StringComparison.CurrentCultureIgnoreCase) ? result.OrderByDescending(p => p.CategoryName).ToList() : result.OrderBy(p => p.CategoryName).ToList();
                break;

            case "4":
                result = orderDir.Equals("DESC", StringComparison.CurrentCultureIgnoreCase) ? result.OrderByDescending(p => p.Currency).ToList() : result.OrderBy(p => p.Currency).ToList();
                break;

            case "5":
                result = orderDir.Equals("DESC", StringComparison.CurrentCultureIgnoreCase) ? result.OrderByDescending(p => p.Price).ToList() : result.OrderBy(p => p.Price).ToList();
                break;

            case "6":
                result = orderDir.Equals("DESC", StringComparison.CurrentCultureIgnoreCase) ? result.OrderByDescending(p => p.LabelEN).ToList() : result.OrderBy(p => p.LabelEN).ToList();
                break;

            case "7":
                result = orderDir.Equals("DESC", StringComparison.CurrentCultureIgnoreCase) ? result.OrderByDescending(p => p.LabelAR).ToList() : result.OrderBy(p => p.LabelAR).ToList();
                break;

            default:
                result = result.OrderByDescending(p => p.Id).ToList();
                break;
            }

            var data = result;

            if (param.length > 0)
            {
                data = result.Skip(param.start).Take(param.length).ToList();
            }

            return(Json(new
            {
                draw = param.draw,
                recordsFiltered = result.Count,
                recordsTotal = recordsTotal,
                data = data
            }));
        }
示例#3
0
        public IActionResult Index(int Id = 0)
        {
            var menu = new Menu_VM();

            ViewBag.ConceptsList = new SelectList(conceptsList, "Id", "ConceptName");
            if (Id > 0)
            {
                menu = _menuRepository.Get(Id, this.loginUserId, isAdmin);
                if (menu == null)
                {
                    return(RedirectToAction("List", "Menu"));
                }
                else
                {
                    menuItemList = _menuItemRepository.GetList(this.loginUserId, isAdmin).Where(x => x.Status && x.MenuItemConcepts.Any(x => x.ConceptId == menu.ConceptId)).ToList();
                    if (menuItemList.Any())
                    {
                        categoryList = menuItemList.Select(x => new Category_VM()
                        {
                            Id   = x.CategoryId,
                            Name = x.CategoryName
                        }).DistinctBy(x => x.Name).ToList();

                        categoryList.Add(new Category_VM {
                            Id = 0, Name = "All"
                        });
                    }


                    ViewBag.MenuItems  = new SelectList(menuItemList, "Id", "Name");
                    ViewBag.Categories = new SelectList(categoryList.OrderBy(x => x.Id), "Id", "Name");
                    ViewData["Title"]  = "Edit";
                    return(View(menu));
                }
            }
            else
            {
                if (conceptsList.Any())
                {
                    if (SelectedConceptId > 0)
                    {
                        menuItemList   = _menuItemRepository.GetList(this.loginUserId, isAdmin).Where(x => x.Status && x.MenuItemConcepts.Any(x => x.ConceptId == SelectedConceptId)).ToList();
                        menu.ConceptId = SelectedConceptId;
                    }
                    else
                    {
                        menuItemList = _menuItemRepository.GetList(this.loginUserId, isAdmin).Where(x => x.Status && x.MenuItemConcepts.Any(x => x.ConceptId == conceptsList[0].Id)).ToList();
                    }

                    if (menuItemList.Any())
                    {
                        categoryList = menuItemList.Select(x => new Category_VM()
                        {
                            Id   = x.CategoryId,
                            Name = x.CategoryName
                        }).DistinctBy(x => x.Name).ToList();
                        categoryList.Add(new Category_VM {
                            Id = 0, Name = "All"
                        });
                    }
                }

                ViewBag.MenuItems  = new SelectList(menuItemList, "Id", "Name");
                ViewBag.Categories = new SelectList(categoryList.OrderBy(x => x.Id), "Id", "Name");
                ViewData["Title"]  = "Add";
                return(View(menu));
            }
        }