public DropBoxController(ICategoryRepositoryDB categoryRepository, IItemsRepositoryDB itemsRepository, IHostingEnvironment env) { this.categoryRepository = categoryRepository; this.itemsRepository = itemsRepository; //auxCivm.Categories = categoryRepository.GetAll().ToList(); auxCivm.Categories = categoryRepository.GetAll().ToList(); auxCivm.Items = itemsRepository.GetAll().ToList(); var task = Task.Run((Func <Task>)DropBoxController.Run); civm.GroupTags = new List <String>(); task.Wait(); if (task.IsCompleted) { try{ foreach (DropBoxCategory c in auxCivm.Categories) { categoryRepository.Save(c); } foreach (DropBoxItems i in auxCivm.Items) { itemsRepository.Save(i); } foreach (DropBoxCategory c in auxCivmRemove.Categories) { categoryRepository.Delete(c); } foreach (DropBoxItems i in auxCivmRemove.Items) { itemsRepository.Delete(i); } }catch (Exception e) { } civm.Categories = categoryRepository.GetAll().ToList(); civm.Items = itemsRepository.GetAll(); ivm.Categories = categoryRepository.GetAll().ToList(); this.hostingEnv = env; } }
public AdminController(ICategoryRepository categoryRepository, IItemsRepository itemsRepository, ICategoryRepositoryDB categoryRepositoryDB, IItemsRepositoryDB itemsRepositoryDB, IHostingEnvironment env) { this.categoryRepository = categoryRepository; this.itemsRepository = itemsRepository; this.categoryRepositoryDB = categoryRepositoryDB; this.itemsRepositoryDB = itemsRepositoryDB; civm.Categories = categoryRepository.GetAll().ToList(); civm.Items = itemsRepository.GetAll(); ivm.Categories = categoryRepository.GetAll().ToList(); civmDB.Categories = categoryRepositoryDB.GetAll().ToList(); civmDB.Items = itemsRepositoryDB.GetAll(); ivmDB.Categories = categoryRepositoryDB.GetAll().ToList(); this.hostingEnv = env; }
public IActionResult Index(String sortOrder, String searchString, String[] format) { ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewData["FormatSortParm"] = sortOrder == "Format" ? "format_desc" : "Format"; ViewData["DescriptionSortParm"] = sortOrder == "Description" ? "description_desc" : "Description"; ViewData["TagsSortParm"] = sortOrder == "Tags" ? "tags_desc" : "Tags"; ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date"; ViewData["CurrentFilter"] = searchString; List <Boolean> madeTrue = new List <Boolean>(); foreach (DropBoxItems i in civm.Items) { civm.GroupTags.Add(i.Tags); } civm.GroupTags = civm.GroupTags.Distinct().ToList(); foreach (DropBoxCategory c in categoryRepository.GetAll()) { madeTrue.Add(false); } try{ if (!String.IsNullOrEmpty(format[0])) { int k = 0; int n = 0; ViewData["FormatFilter"] = format; List <DropBoxItems> aux = new List <DropBoxItems>(); List <DropBoxCategory> category = categoryRepository.GetAll().ToList(); foreach (var selection in format) { foreach (DropBoxItems i in itemsRepository.GetAll()) { if (i.Format.Equals(selection)) { aux.Add(i); } } k = categoryRepository.Size(); for (int j = n; j < k && madeTrue[n] == false; j++) { if (category[j].CategoryType.Equals(selection)) { categoryRepository.Get(category[j].CategoryID).Selected = true; madeTrue[n] = true; } else { categoryRepository.Get(category[j].CategoryID).Selected = false; n++; } } n++; } for (int j = 0; j < categoryRepository.Size(); j++) { categoryRepository.Get(category[j].CategoryID).Selected = madeTrue[j]; } civm.Items = aux; } else { foreach (DropBoxCategory c in categoryRepository.GetAll()) { categoryRepository.Get(c.CategoryID).Selected = false; } } }catch (Exception e) { } var items = civm.Items; if (!String.IsNullOrEmpty(searchString)) { items = items.Where(s => s.Title.ToLower().Contains(searchString.ToLower()) || s.Tags.ToLower().Contains(searchString.ToLower())); } switch (sortOrder) { case "name_desc": items = items.OrderByDescending(s => s.Title); break; case "Format": items = items.OrderBy(s => s.Format); break; case "format_desc": items = items.OrderByDescending(s => s.Format); break; case "Description": items = items.OrderBy(s => s.Description); break; case "description_desc": items = items.OrderByDescending(s => s.Description); break; case "Tags": items = items.OrderBy(s => s.Tags); break; case "tags_desc": items = items.OrderByDescending(s => s.Tags); break; case "Date": items = items.OrderBy(s => s.date); break; case "date_desc": items = items.OrderByDescending(s => s.date); break; default: items = items.OrderBy(s => s.Title); break; } civm.Items = items; return(View(civm)); }