public ActionResult PCMSearch() { var currentUser = (User)Session["CurrentUser"]; var userProvince = -1; var userId = -1; if (currentUser != null) { userId = currentUser.User_Id; if (currentUser.Employees.Any()) { userProvince = currentUser.Employees.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id; } if (currentUser.apl_Social_Worker.Any()) { userProvince = currentUser.apl_Social_Worker.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id; } } // get client list var caseViewModel = new PCMCaseListViewModel { Client_List = new List <Client>(), PCMClients_Case_List = new List <PCMCaseGridMain>() }; SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities(); if (userProvince == -1) { // Logged In User is not assigned to a province, what should happen here? } else { var intakeAssessmentModel = new IntakeAssessmentModel(); var assessments = intakeAssessmentModel.GetListOfPCMIntakeAssessments(userProvince, userId); PCMWorkListModel model = new PCMWorkListModel(); var clientAssessments = model.GetListOfPersonsPCM(); var clientItems = clientAssessments.Select(x => new PCMCaseGridMain() { PersonId = x.Person_Id, FirstName = x.First_Name, LastName = x.Last_Name, IDNumber = x.Identification_Number, AssessmentCount = x.Clients.Any() ? x.Clients.First().Intake_Assessments.Count : 0, PCMNestedItems = !x.Clients.Any() ? new List <PCMCaseGridNested>() : x.Clients.First().Intake_Assessments.Select(y => new PCMCaseGridNested() { PersonId = x.Person_Id, AssessmentId = y.Intake_Assessment_Id, AssessmentDate = y.Assessment_Date, POName = db.Users.Find(y.Assessed_By_Id).Last_Name }).ToList() }).ToList(); caseViewModel.PCMClients_Case_List.AddRange(clientItems); } return(PartialView(caseViewModel)); }
public ActionResult PCMSearch(PCMCaseListViewModel caseViewModel) { var currentUser = (User)Session["CurrentUser"]; var userProvince = -1; var userId = -1; if (currentUser != null) { userId = currentUser.User_Id; if (currentUser.Employees.Any()) { userProvince = currentUser.Employees.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id; } if (currentUser.apl_Social_Worker.Any()) { userProvince = currentUser.apl_Social_Worker.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id; } } caseViewModel.PCMClients_Case_List = new List <PCMCaseGridMain>(); if (userProvince == -1) { // Logged In User is not assigned to a province, what should happen here? } else { var intakeAssessmentModel = new IntakeAssessmentModel(); var assessments = intakeAssessmentModel.GetListOfPCMIntakeAssessments(userProvince, userId); PCMWorkListModel model = new PCMWorkListModel(); SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities(); //var clientAssessments = model.GetListOfPersonsPCM(); var persons = model.GetListOfPersonsPCM(); //var query = from c in clientAssessments select c; var query1 = from p in persons select p; if (!string.IsNullOrEmpty(caseViewModel.Search_First_Name)) { query1 = query1.Where(p => p.First_Name.ToLower().Contains(caseViewModel.Search_First_Name.ToLower())); } if (!string.IsNullOrEmpty(caseViewModel.Search_Last_Name)) { query1 = query1.Where(p => p.Last_Name.ToLower().Contains(caseViewModel.Search_Last_Name.ToLower())); } if (!string.IsNullOrEmpty(caseViewModel.Search_ID_Number)) { query1 = query1.Where(p => p.Identification_Number.Contains(caseViewModel.Search_ID_Number)); } var filteredResults = query1.ToList(); var clientItems = filteredResults.Select(x => new PCMCaseGridMain() { PersonId = x.Person_Id, FirstName = x.First_Name, LastName = x.Last_Name, IDNumber = x.Identification_Number, AssessmentCount = x.Clients.Any() ? x.Clients.First().Intake_Assessments.Count : 0, PCMNestedItems = !x.Clients.Any() ? new List <PCMCaseGridNested>() : x.Clients.First().Intake_Assessments.Select(y => new PCMCaseGridNested() { PersonId = x.Person_Id, AssessmentId = y.Intake_Assessment_Id, AssessmentDate = y.Assessment_Date, POName = db.Users.Find(y.Assessed_By_Id).Last_Name }).ToList() }).ToList().Distinct(); caseViewModel.PCMClients_Case_List.AddRange(clientItems); } return(PartialView(caseViewModel)); }