public async Task <IActionResult> Index() { var query = await baseAsyncFolderRepo.GetAllAsync(includeproperty : source => source .Include(cd => cd.CustData) .ThenInclude(hl => hl.PrjHelixes1) .Include(cd => cd.CustData) .ThenInclude(hl => hl.PrjVelocities1) .Include(cd => cd.CustData) .ThenInclude(hl => hl.PrjVelocities2) ); return(View(query)); }
public async Task <IActionResult> GetRelatedCif(int boxid, string accountno, string custidn) { int a = boxid; if (String.IsNullOrEmpty(accountno) && String.IsNullOrEmpty(custidn)) { return(NotFound()); } if (!String.IsNullOrEmpty(accountno) && String.IsNullOrEmpty(custidn)) { var acc = await baseAsyncCustAccRepo.GetByConditionAsync(filter : ac => ac.CustAccountNo == accountno, includeProperties : "CustRelDataEntries"); var allcifs = await baseAsyncCustDataRepo.GetAllAsync(); var accountcifs = new HashSet <string>(acc.CustRelDataEntries.Select(cf => cf.CustCIFNo)); ViewData["AccountNo"] = acc.CustAccountNo; var viewModel = new List <AssignedAccountData>(); foreach (var cif in allcifs) { viewModel.Add(new AssignedAccountData { CIFNo = cif.CIFNo.Trim(), CIFCustomerName = cif.CustomerName ?? "", Assigned = accountcifs.Contains(cif.CIFNo), BoxID = boxid }); } var model = viewModel.Where(a => a.Assigned == true).ToList(); return(View("GetRelatedCif", model)); } if (String.IsNullOrEmpty(accountno) && !String.IsNullOrEmpty(custidn)) { var allcifs = await baseAsyncCustDataRepo.GetAllAsync(filter : cd => cd.CustomerIDN.Contains(custidn) || cd.CustomerName.Contains(custidn)); var viewModel = new List <AssignedAccountData>(); foreach (var cif in allcifs) { viewModel.Add(new AssignedAccountData { CIFNo = cif.CIFNo.Trim(), CIFCustomerName = cif.CustomerName ?? "", BoxID = boxid }); } var model = viewModel.ToList(); return(View("GetRelatedCif", model)); } return(View()); }
// GET: BookController //[AllowAnonymous] // [Authorize(Roles = "Administrators,WebAppAdmins,WebAppPowerUsers,WebAppEditors,WebAppContributors,WebAppViewers")] public async Task <ActionResult> Index(int?id, int?folderid, string searchBox, string searchCreator, string sortOrder, DateTime?searchDateFrom, DateTime?searchDateTo, int?pageNumber) { #region Shared Parameters var viewmodel = new BoxFolderDocIndexData(); ViewData["BoxSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date"; ViewData["CreatorSortParm"] = sortOrder == "Creator" ? "creator_desc" : "Creator"; ViewData["searchBox"] = searchBox ?? ""; ViewData["searchCreator"] = searchCreator ?? ""; ViewData["searchDateFrom"] = (searchDateFrom == null) ?"" : searchDateFrom.Value.ToString("yyyy-MM-dd"); ViewData["searchDateTo"] = (searchDateTo == null) ? "" : searchDateTo.Value.ToString("yyyy-MM-dd"); ViewData["BoxID"] = (id == null)?0:id.Value; viewmodel.PageSize = 10; #endregion #region SearchFunctionality #region All Boxes if ((searchDateFrom == null && searchDateTo == null) && (String.IsNullOrEmpty(searchBox) && String.IsNullOrEmpty(searchCreator))) { viewmodel.Boxes = await baseAsyncBoxRepo.GetAllAsync( // no filters applied includeproperty : source => source .Include(bc => bc.BoxCreator) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjHelixes1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities2) ); } #endregion #region Search By Box OR Creator whithout Date restriction if ((searchDateFrom == null && searchDateTo == null) && ( (!String.IsNullOrEmpty(searchBox) && String.IsNullOrEmpty(searchCreator)) || (String.IsNullOrEmpty(searchBox) && !String.IsNullOrEmpty(searchCreator)) ) ) { viewmodel.Boxes = await baseAsyncBoxRepo.GetAllAsync( filter : bx => bx.BoxCreator.CreatorName.Contains(searchCreator) || bx.BoxDescription.Contains(searchBox), includeproperty : source => source .Include(bc => bc.BoxCreator) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjHelixes1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities2) ); viewmodel.Boxes = viewmodel.Boxes.OrderBy(bx => bx.DateBoxCreated); } #endregion #region Search By Box AND Creator whithout Date restriction if ( (searchDateFrom == null && searchDateTo == null) && ( !String.IsNullOrEmpty(searchBox) && !String.IsNullOrEmpty(searchCreator)) ) { viewmodel.Boxes = await baseAsyncBoxRepo.GetAllAsync( filter : bx => bx.BoxCreator.CreatorName.Contains(searchBox) && bx.BoxDescription.Contains(searchBox), includeproperty : source => source .Include(bc => bc.BoxCreator) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjHelixes1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities2) ); viewmodel.Boxes = viewmodel.Boxes.OrderBy(bx => bx.DateBoxCreated); } #endregion #region Search By Creator in specific Date if (!String.IsNullOrEmpty(searchCreator) && (searchDateFrom != null && searchDateTo == null) || (searchDateFrom == null && searchDateTo != null) //maybe not needed ) { viewmodel.Boxes = await baseAsyncBoxRepo.GetAllAsync( filter : bx => bx.DateBoxCreated.Date.Equals(searchDateFrom) && bx.BoxCreator.CreatorName.Contains(searchCreator), includeproperty : source => source .Include(bc => bc.BoxCreator) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjHelixes1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities2) ); } #endregion #region Search in specific Date if (String.IsNullOrEmpty(searchCreator) && (searchDateFrom != null && searchDateTo == null) ) { viewmodel.Boxes = await baseAsyncBoxRepo.GetAllAsync( filter : bx => bx.DateBoxCreated.Date.Equals(searchDateFrom), includeproperty : source => source .Include(bc => bc.BoxCreator) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjHelixes1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities2) ); } #endregion #region Search By Creator in a range of Dates if ( !String.IsNullOrEmpty(searchCreator) && (searchDateFrom != null && searchDateTo != null) ) { viewmodel.Boxes = await baseAsyncBoxRepo.GetAllAsync( filter : bx => (bx.DateBoxCreated.Date >= searchDateFrom && bx.DateBoxCreated.Date <= searchDateTo) && bx.BoxCreator.CreatorName.Contains(searchCreator), includeproperty : source => source .Include(bc => bc.BoxCreator) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjHelixes1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities2) ); viewmodel.Boxes = viewmodel.Boxes.OrderBy(bx => bx.DateBoxCreated); } #endregion #region Search By a range of Dates if ( String.IsNullOrEmpty(searchCreator) && (searchDateFrom != null && searchDateTo != null) ) { viewmodel.Boxes = await baseAsyncBoxRepo.GetAllAsync( filter : bx => bx.DateBoxCreated.Date >= searchDateFrom && bx.DateBoxCreated.Date <= searchDateTo, includeproperty : source => source .Include(bc => bc.BoxCreator) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjHelixes1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities1) .Include(fl => fl.Folders) .ThenInclude(ct => ct.CustData) .ThenInclude(hl => hl.PrjVelocities2) ); viewmodel.Boxes = viewmodel.Boxes.OrderBy(bx => bx.DateBoxCreated); } #endregion #endregion #region SortFunctionality ViewData["sortOrder"] = sortOrder ?? ""; if (!String.IsNullOrEmpty(sortOrder)) { switch (sortOrder) { case "name_desc": viewmodel.Boxes = viewmodel.Boxes.OrderByDescending(b => b.BoxDescription); break; case "Date": viewmodel.Boxes = viewmodel.Boxes.OrderBy(b => b.DateBoxCreated); break; case "date_desc": viewmodel.Boxes = viewmodel.Boxes.OrderByDescending(b => b.DateBoxCreated); break; case "Creator": viewmodel.Boxes = viewmodel.Boxes.OrderBy(b => b.BoxCreator.CreatorName); break; case "creator_desc": viewmodel.Boxes = viewmodel.Boxes.OrderByDescending(b => b.BoxCreator.CreatorName); break; default: viewmodel.Boxes = viewmodel.Boxes.OrderBy(b => b.BoxDescription); break; } // sort pagination viewmodel.CountedBoxes = viewmodel.Boxes.Count(); viewmodel.CurrentPage = pageNumber ?? 1; viewmodel.TotalPages = (int)Math.Ceiling(viewmodel.CountedBoxes / (double)viewmodel.PageSize); viewmodel.Boxes = viewmodel.Boxes.Skip((viewmodel.CurrentPage - 1) * viewmodel.PageSize).Take(viewmodel.PageSize); return(View(viewmodel)); } #endregion #region EnhanceViewModel if (id != null) { ViewData["BoxID"] = id.Value; ViewData["BoxDescription"] = viewmodel.Boxes.Where(b => b.ID == id).Select(d => d.BoxDescription).FirstOrDefault().ToString(); TempData["BoxID"] = id.Value; TempData["BoxDescription"] = viewmodel.Boxes.Where(b => b.ID == id).Select(d => d.BoxDescription).FirstOrDefault().ToString(); viewmodel.Boxes = viewmodel.Boxes.Where(b => b.ID == id); var alt = viewmodel.Boxes.Where(b => b.ID == id).Single().Folders; if (alt.Any()) { viewmodel.Folders = viewmodel.Boxes .Where(b => b.ID == id) .Single().Folders; return(View(viewmodel)); } } if (folderid != null) { ViewData["FolderID"] = folderid.Value; } #endregion #region Pagination viewmodel.CountedBoxes = viewmodel.Boxes.Count(); viewmodel.CurrentPage = pageNumber ?? 1; viewmodel.TotalPages = (int)Math.Ceiling(viewmodel.CountedBoxes / (double)viewmodel.PageSize); viewmodel.Boxes = viewmodel.Boxes.Skip((viewmodel.CurrentPage - 1) * viewmodel.PageSize).Take(viewmodel.PageSize); #endregion return(View(viewmodel)); }