public ActionResult Edit([Bind(Prefix = "publicId")] string Folder_ID, string[] EditList) { //THERE IS A BUG IF THE EditList CARRIES TOO MANY OBJECTS List <PublicVM> publicModel = null; publicModel = publicRepository.SelectAll(Folder_ID, "Admin").Where(doc => EditList.Contains(doc.Document_ID.ToString())).GroupBy(x => x.Document_ID).Select(x => x.First()).ToList(); return(PartialView("_EditTable", publicModel)); }
public ActionResult Edit([Bind(Prefix = "folderId")] string Folder_ID, string[] EditList) { TempData.Keep("Folder_Id"); //***THERE IS A BUG IF THE EditList CARRIES TOO MANY OBJECTS*** //Theory: string array size is causing some issue List <PublicVM> publicModel = null; // maybe move outside of action? publicModel = publicRepository.SelectAll(Folder_ID, "Admin") .Where(doc => EditList.Contains(doc.Document_ID.ToString())) .GroupBy(x => x.Document_ID) .Select(x => x.First()) .ToList(); return(PartialView("_EditTable", publicModel)); }
public ActionResult Index([Bind(Prefix = "folderId")] string Folder_ID, string navBarGroup = null, string navBarItem = null, string sort = null, string searchTerm = null, string IssueYearMinRange = "-1", string IssueYearMaxRange = "", string IssueMonthMinRange = "", string IssueMonthMaxRange = "") { //**GLOBAL VARIABLES //TempData can be used to send data between controllers and views through one request, .keep() is used to continue keeping after one request //persist client name, id, search term, inputted dates TempData.Keep("Client_Name"); TempData.Keep("Client_Id"); TempData.Keep("Folder_Id"); TempData.Keep("Role"); TempData.Keep("RoleButton"); //***Pseudo save state immitation TempData.Keep("SearchTerm"); TempData.Keep("YearRange"); //will carry an array with allowable issue date years for custom dropdown list //JACKIE TempData["IssueYearMinRange"] = IssueYearMinRange; TempData["IssueYearMaxRange"] = IssueYearMaxRange; TempData["IssueMonthMinRange"] = IssueMonthMinRange; TempData["IssueMonthMaxRange"] = IssueMonthMaxRange; //ViewData["goodSearch"] = false means seachterm will return an empty result ViewData["goodSearch"] = true; //do i still need this var? //ViewData["currentNav"] used to populate view's link route value for navBarGroup, which in turn populates navBarGroup variable. Used to save navBarGroup state ViewData["currentNav"] = null; //declare and instantiate the original full PublicVM data for the client IEnumerable <PublicVM> publicModel = null; //Admin should default see all data, while typical user should just see 1 year DateTime issueDateMin = ((string)TempData["Role"] == "Admin") ? today.AddYears(-30) : today.AddYears(-1); DateTime?issueDateMax = null; TempData["Version"] = System.Configuration.ConfigurationManager.AppSettings["Versioning"]; //removing whitespaces from end of search term to use before querying if (searchTerm != null) { searchTerm = searchTerm.Trim(); } //**POPULATING MAIN MODEL, second conditional is for no doc reference documents, a unique westland condition try { //right now, publicModel is full of units of DocReference x DocId publicModel = cacheprovider.GetOrSet( Folder_ID, () => publicRepository .SelectAll(Folder_ID, TempData["Role"].ToString()) //find a way to cache this initial load .Where(n => n.EffectiveDate != null || n.EffectiveDate == null && n.RefNumber == null || n.EffectiveDate == null && n.RefNumber != null), TempData["Role"].ToString() ); //added a caching mechanism where on initial load, the model will be cached for 10 mins. //if no cache, it will run the default call to the db } catch { //the clientId should always exist. if it doesnt, i would assume the user shouldnt be here, which is why i issue an exception NoResultException exception = new NoResultException("The client may not exist or does not have any available documents."); exception.HelpLink = "Please check over the provided information and try again."; exception.Data["Folder ID"] = Folder_ID; throw exception; } //needs to be checked seperately because cant select by DocId until after deciding if we are searching by documentId or policy //can possibly combine into navBarGroupFilter if (navBarGroup != "policy") { publicModel = publicModel.GroupBy(x => x.Document_ID).Select(x => x.First()); } //should only be run on initial load of page if (!Request.IsAjaxRequest()) { //count of total records unfiltered of this client ViewData["allRecordsCount"] = publicModel.Count(); //maybe should return view here already since overall count is already 0 if (publicModel.Count() == 0) { //maybe reword exception message NoResultException exception = new NoResultException("The client does not have any available records."); exception.HelpLink = "Please check over the provided information and try again."; exception.Data["Folder ID"] = Folder_ID; throw exception; } //creating the options for the dropdown list TempData["YearRange"] = YearRangePopulate(RetrieveYear(publicModel, true), RetrieveYear(publicModel, false)); //**Populating the navbar, put into function populateNavBar(publicModel); //pretty much should only be the initial synchronous load to come in here ViewData["SortOrder"] = sortAscending; publicModel = publicModel .OrderByDescending(r => r.IssueDate) .ThenByDescending(r => r.ArchiveTime) .Where(r => r.IssueDate >= issueDateMin) .ToList(); ViewData["currentRecordsCount"] = publicModel.Count(); return(View(publicModel)); } else { //If user inputs only one custom year and maybe one/two months, what should happen? if (String.IsNullOrEmpty(IssueYearMaxRange)) { //entered in two scenarios: 1) regular minIssueDate input and custom date where only minIssueDate is filled int yearInput = (string.IsNullOrEmpty(IssueYearMinRange)) ? Int32.Parse(today.AddYears(-1).Year.ToString()) : Int32.Parse(IssueYearMinRange); issueDateMin = (yearInput > 0) ? issueDateMin = new DateTime(yearInput, 1, 1) : issueDateMin = today.AddYears(yearInput); yearInput = (yearInput > 0) ? yearInput - DateTime.Now.Year : yearInput; } else if (!String.IsNullOrEmpty(IssueYearMinRange) && !String.IsNullOrEmpty(IssueYearMaxRange)) { //custom dates issueDateMin = FormatDate(IssueYearMinRange, IssueMonthMinRange, true); issueDateMax = FormatDate(IssueYearMaxRange, IssueMonthMaxRange, false); } else { //no input for min date under CUSTOM inputs //min would be oldest issue date available IssueMonthMaxRange = (String.IsNullOrEmpty(IssueMonthMaxRange)) ? "12" : IssueMonthMaxRange; issueDateMin = DateTime.ParseExact(String.Format("01/01/1985"), "d", CultureInfo.InvariantCulture); issueDateMax = FormatDate(IssueYearMaxRange, IssueMonthMaxRange, false); } //**STARTING ACTUAL FILTERING/SORTING OF MODEL** //*filtering by category/doctype/policy if (navBarGroup != null) { publicModel = navBarGroupFilter(publicModel, navBarGroup, navBarItem); } //*filtering by date and search conditions if (TempData["Role"].ToString() == "Admin") { //checks if the date filter and search term will return any results //The admin search will also search for document Id within the same input (so checks tbl_Document.Description and tbl_Document.Document_Id) if (!publicModel.Any(r => (r.IssueDate >= issueDateMin) && (issueDateMax == null || r.IssueDate <= issueDateMax) && (searchTerm == null || r.Description.ToLower().Contains(searchTerm.ToLower()) || r.Document_ID.ToString().Contains(searchTerm)))) { //ViewData["goodSearch"] equals false means no records is found ViewData["goodSearch"] = false; } else { publicModel = publicModel.Where(r => (r.IssueDate >= issueDateMin) && (issueDateMax == null || r.IssueDate <= issueDateMax) && (searchTerm == null || ((bool)ViewData["goodSearch"] ? r.Description.ToLower().Contains(searchTerm.ToLower()) || r.Document_ID.ToString().Contains(searchTerm) == true : true))); TempData["SearchTerm"] = searchTerm; } } else { //checks if the date filter and search term will return any results publicModel = publicModel.Where(r => (r.IssueDate >= issueDateMin) && (issueDateMax == null || r.IssueDate <= issueDateMax) && (searchTerm == null || ((bool)ViewData["goodSearch"] ? r.Description.ToLower().Contains(searchTerm.ToLower()) == true : true))); } ViewData["currentRecordsCount"] = publicModel.Count(); if (publicModel.Count() == 0) //not sure if needed { ViewData["goodSearch"] = false; } TempData["SearchTerm"] = searchTerm; //not sure if needed //*sorting data publicModel = SortModel(publicModel, sort); //**ENDING FILTERING OF MODEL** if (publicModel != null) { ViewData["SortOrder"] = sortAscending; return(PartialView("_PublicTable", publicModel)); } else { return(HttpNotFound()); } } }
public ActionResult Index([Bind(Prefix = "folderId")] string Folder_ID, string navBarGroup = null, string navBarItem = null, string filter = null, string searchTerm = null, string IssueYearMinRange = "", string IssueYearMaxRange = "", bool Admin = false, string IssueMonthMinRange = "", string IssueMonthMaxRange = "") { //**GLOBAL VARIABLES //TempData can be used to send data between controllers and views through one request, .keep() is used to continue keeping after one request //persist client name, id, search term, inputted dates TempData.Keep("Client_Name"); TempData.Keep("Client_Id"); TempData.Keep("Folder_Id"); TempData.Keep("Role"); TempData.Keep("RoleButton"); //***Pseudo save state immitation TempData.Keep("SearchTerm"); TempData.Keep("YearRange"); //will carry an array with allowable issue date years for custom dropdown list //ViewData["goodSearch"] = false means seachterm will return an empty result ViewData["goodSearch"] = true; //do i still need this var? //ViewData["currentNav"] used to populate view's link route value for navBarGroup, which in turn populates navBarGroup variable. Used to save navBarGroup state ViewData["currentNav"] = null; //DateTime issueDateMin = today.AddYears(-1); //appropriate place? //DateTime issueDateMax = today; //appropriate place? DateTime issueDateMin = ((string)TempData["Role"] == "Admin") ? today.AddYears(-30) : today.AddYears(-1); DateTime issueDateMax = today; if (searchTerm != null) { searchTerm = searchTerm.Trim(); } //declare and instantiate the original full PublicVM data for the client IEnumerable <PublicVM> publicModel = null; //**POPULATING MAIN MODEL, second conditional is for no doc reference documents, a unique westland condition try { publicModel = publicRepository .SelectAll(Folder_ID, TempData["Role"].ToString()) .Where(n => n.EffectiveDate != null || n.EffectiveDate == null && n.RefNumber == null || n.EffectiveDate == null && n.RefNumber != null); //right now, publicModel is full of units of DocReference x DocId } catch { TempData.Clear(); TempData["error_info"] = "The client does not have any available records."; TempData["importance"] = false; return(RedirectToAction("Index", "ErrorHandler", null)); } //needs to be checked seperately because cant select by DocId until after deciding if we are searching by documentId or policy //can possibly combine into navBarGroupFilter if (navBarGroup != "policy") { publicModel = publicModel.GroupBy(x => x.Document_ID).Select(x => x.First()); } //should only be run on initial load of page if (!Request.IsAjaxRequest()) { //count of total records unfiltered of this client ViewData["allRecordsCount"] = publicModel.Count(); //maybe should return view here already since overall count is alreadt 0 if (publicModel.Count() == 0) { TempData["error_info"] = "The client does not have any available records."; TempData["importance"] = true; return(RedirectToAction("Index", "ErrorHandler", null)); } //creating the options for the dropdown list TempData["YearRange"] = YearRangePopulate(RetrieveYear(publicModel, true), RetrieveYear(publicModel, false)); //**Populating the navbar, put into function populateNavBar(publicModel); //pretty much should only be the initial synchronous load to come in here ViewData["SortOrder"] = sortAscending; publicModel = publicModel .OrderByDescending(r => r.IssueDate) .Where(r => (r.IssueDate >= issueDateMin) && (r.IssueDate <= issueDateMax)) .ToList(); ViewData["currentRecordsCount"] = publicModel.Count(); return(View(publicModel)); } else { //If user inputs only one custom year and maybe one/two months, what should happen? if (String.IsNullOrEmpty(IssueYearMaxRange)) { //if ((string)TempData["Role"] == "Admin") { // IssueYearMinRange = "1975"; //} //entered in two scenarios: 1) regular minIssueDate input and custom date where only minIssueDate is filled int yearInput = (string.IsNullOrEmpty(IssueYearMinRange)) ? Int32.Parse(today.AddYears(-1).Year.ToString()) : Int32.Parse(IssueYearMinRange); issueDateMin = (yearInput > 0) ? issueDateMin = new DateTime(yearInput, 1, 1) : issueDateMin = today.AddYears(yearInput); yearInput = (yearInput > 0) ? yearInput - DateTime.Now.Year : yearInput; // bug, sometimes issueDateMin should be relative to full year, not to today } else if (!String.IsNullOrEmpty(IssueYearMinRange) && !String.IsNullOrEmpty(IssueYearMaxRange)) { //custom dates issueDateMin = FormatDate(IssueYearMinRange, IssueMonthMinRange, true); issueDateMax = FormatDate(IssueYearMaxRange, IssueMonthMaxRange, false); } else { //no input for min date under CUSTOM inputs //min would be oldest issue date available IssueMonthMaxRange = (String.IsNullOrEmpty(IssueMonthMaxRange)) ? "12" : IssueMonthMaxRange; issueDateMin = DateTime.ParseExact(String.Format("01/01/1985"), "d", CultureInfo.InvariantCulture); issueDateMax = FormatDate(IssueYearMaxRange, IssueMonthMaxRange, false); } //**STARTING ACTUAL FILTERING/SORTING OF MODEL** //*filtering by category/doctype/policy if (navBarGroup != null) { publicModel = navBarGroupFilter(publicModel, navBarGroup, navBarItem); } //*filtering by date and search conditions if (TempData["Role"].ToString() == "Admin") { //checks if the date filter and search term will return any results //The admin search will also search for document Id within the same input (so checks tbl_Document.Description and tbl_Document.Document_Id) if (!publicModel.Any(r => (r.IssueDate >= issueDateMin) && (r.IssueDate <= issueDateMax) && (searchTerm == null || r.Description.ToLower().Contains(searchTerm.ToLower()) || r.Document_ID.ToString().Contains(searchTerm)))) { //ViewData["goodSearch"] = false means no records is found ViewData["goodSearch"] = false; } else { publicModel = publicModel.Where(r => (r.IssueDate >= issueDateMin) && (r.IssueDate <= issueDateMax) && (searchTerm == null || ((bool)ViewData["goodSearch"] ? r.Description.ToLower().Contains(searchTerm.ToLower()) || r.Document_ID.ToString().Contains(searchTerm) == true : true))); TempData["SearchTerm"] = searchTerm; } } else { //checks if the date filter and search term will return any results publicModel = publicModel.Where(r => (r.IssueDate >= issueDateMin) && (r.IssueDate <= issueDateMax) && (searchTerm == null || ((bool)ViewData["goodSearch"] ? r.Description.ToLower().Contains(searchTerm.ToLower()) == true : true))); } ViewData["currentRecordsCount"] = publicModel.Count(); if (publicModel.Count() == 0) //not sure if needed { ViewData["goodSearch"] = false; } TempData["SearchTerm"] = searchTerm; //not sure if needed //*sorting data publicModel = FilterModel(publicModel, filter); //**ENDING FILTERING OF MODEL** if (publicModel != null) { ViewData["SortOrder"] = sortAscending; return(PartialView("_PublicTable", publicModel)); } else { return(HttpNotFound()); } } }