Ejemplo n.º 1
0
        public FoodsItemsExtraVM ViewModel(int id, bool descending, SortFoodItemExtra sortOrder)
        {
            var foodItemExtra = NHibernateHelperCore.GetEntities <FoodItemExtra>(a => a.FoodCategory.Id == id);

            var foodItemExtraVM = foodItemExtra.Select(a => new FoodItemExtraVM()
            {
                Id             = a.Id,
                Name           = a.Name,
                Price          = a.Price,
                FoodCategoryId = id
            }).ToList();

            foodItemExtraVM = sortOrder switch
            {
                SortFoodItemExtra.Name when !descending => foodItemExtraVM.OrderBy(s => s.Name).ToList(),
                SortFoodItemExtra.Name when descending => foodItemExtraVM.OrderByDescending(s => s.Name).ToList(),
                SortFoodItemExtra.Price when !descending => foodItemExtraVM.OrderBy(s => s.Price).ToList(),
                SortFoodItemExtra.Price when descending => foodItemExtraVM.OrderByDescending(s => s.Price).ToList(),
                _ => foodItemExtraVM.OrderByDescending(s => s.Name).ToList(),
            };

            var foodsItemsExtraVm = new FoodsItemsExtraVM()
            {
                FoodsItemsExtra = foodItemExtraVM,
                FoodCategoryId  = id,
                Descending      = descending,
                Sort            = sortOrder,
                Admin           = User.IsInRole(NHibernateHelperCore.RoleAdmin)
            };

            return(foodsItemsExtraVm);
        }
Ejemplo n.º 2
0
        public IActionResult IndexAJAX(int id, bool descending, SortFoodItemExtra sortOrder)
        {
            var foodsItemsExtraVm = ViewModel(id, descending, sortOrder);

            return(Json(foodsItemsExtraVm));
        }