private FoodsCategoriesVM ViewModel(string txt, bool descending, SortFoodCategory sortOrder) { var foodCategory = NHibernateHelperCore.GetEntities <FoodCategory>(); var foodCategoryVM = new List <FoodCategoryVM>(); if (!string.IsNullOrWhiteSpace(txt)) { txt = txt.ToLower(); foodCategoryVM = foodCategory.Where(compare => compare.Name.ToLower().Contains(txt)) .Select(a => new FoodCategoryVM() { Name = a.Name, Id = a.Id }).ToList(); } else { foodCategoryVM = foodCategory.Select(a => new FoodCategoryVM() { Name = a.Name, Id = a.Id }).ToList(); } foodCategoryVM = sortOrder switch { SortFoodCategory.Name when !descending => foodCategoryVM.OrderBy(s => s.Name).ToList(), SortFoodCategory.Name when descending => foodCategoryVM.OrderByDescending(s => s.Name).ToList(), _ => foodCategoryVM.OrderByDescending(s => s.Name).ToList(), }; var foodsCategoriesVM = new FoodsCategoriesVM() { FoodsCategories = foodCategoryVM, Descending = descending, Sort = sortOrder, Admin = User.IsInRole(NHibernateHelperCore.RoleAdmin) }; return(foodsCategoriesVM); }
public IActionResult Index(string txt, bool descending, SortFoodCategory sortOrder) { var result = NHibernateHelperCore.GetSingleOrDefault <User>(a => a.Email == "*****@*****.**"); if (result == null) { var createAdmin = new User { Name = "Дмитрий", Role = Role.Admin, Email = "*****@*****.**", Password = "******" }; NHibernateHelperCore.SaveOrUpdate(createAdmin); } var foodsCategoriesVM = ViewModel(txt, descending, sortOrder); return(View(foodsCategoriesVM)); }
public IActionResult IndexAJAX(string txt, bool descending, SortFoodCategory sortOrder) { var foodsCategoriesVM = ViewModel(txt, descending, sortOrder); return(Json(foodsCategoriesVM)); }