public ActionResult Result(string selectedOrgs, string selectedPrimary, int currentrecord, bool selectExisting) { if (selectedOrgs == "---") { return(null); } if (selectedPrimary == "---" || selectedPrimary == "0") { return(null); } var selectionStrings = selectedOrgs.Split(','); var selections = new int[selectionStrings.Count()]; for (var i = 0; i < selectionStrings.Count(); i++) { selections[i] = int.Parse(selectionStrings[i]); } var selectedPrimaryAsInt = int.Parse(selectedPrimary); var organisations = (from orgs in _context.Organisations.AsQueryable() where selections.Any(i => orgs.OrganisationId.Equals(i)) select orgs).ToList(); var myOrganisations = organisations.Select( organisation => new MyOrganisation { Name = organisation.Name, Value = organisation.OrganisationId }) .ToList(); List <int> participantsIds = null; if (currentrecord != 0) { var currentUser = _context.UserLoginInformations.Find(currentrecord); participantsIds = currentUser.GetFacilityIdsInUserFacilityList(); } var nodes = new List <MyNode>(); foreach (var @org in myOrganisations) { var myFacilities = @org.GetAllMatchingFacilities(); if (myFacilities.Count() == 1 && selectionStrings.Count() == 1) { nodes.Add(null); } else { MyUser user = new MyUser(); user.ParentFacilityId = selectedPrimaryAsInt; MyFacility facility = user.GetParentFacility(); if ((facility.ParentOrganisationId == @org.Value && myFacilities.Count() != 1) || (facility.ParentOrganisationId != @org.Value && myFacilities.Count() > 0)) { var orgNode = new MyNode() { text = org.Name, value = org.Value, icon = "glyphicon glyphicon-home", backColor = "#ffffff", color = "#428bca", nodetype = MyNodeType.Organisation }; orgNode.nodes = new List <MyNode>(); foreach (var @fac in myFacilities) { if (@fac.Value != selectedPrimaryAsInt) { var facNode = new MyNode { parent = orgNode.value, text = fac.Name, value = fac.Value, icon = "glyphicon glyphicon-th-list", backColor = "#ffffff", color = "#66512c", nodetype = MyNodeType.Facility }; if (participantsIds != null && selectExisting) { if (ChatGroupController.CheckIfMatchingMyFacilityExists(participantsIds, facNode) != null) { facNode.state = new state { @checked = true, disabled = false, expanded = true, selected = false }; } } orgNode.nodes.Add(facNode); } } nodes.Add(orgNode); } } } return(Json(nodes, JsonRequestBehavior.AllowGet)); }
public ActionResult Result(int currentrecord) { FacilityMaster @facility = _context.FacilityMasters.Find(currentrecord); Organisation currentOrganisation = @facility.OOrganisation; List <int> participantsIds = null; if (currentrecord != 0) { List <UserLoginInformation> usersInDb = new List <UserLoginInformation>(); usersInDb.AddRange(@facility.GetAssocaitedFacilityAdmins()); participantsIds = usersInDb.Select(x => x.USERID).ToList(); } List <MyNode> nodes = new List <MyNode>(); MyOrganisation @org = new MyOrganisation(); @org.Name = currentOrganisation.Name; @org.Value = currentOrganisation.OrganisationId; MyNode orgNode = new MyNode { text = org.Name, value = org.Value, icon = "glyphicon glyphicon-home", backColor = "#ffffff", color = "#428bca", //state = new state() { @checked = true, disabled = false, expanded = true, selected = false }, nodetype = MyNodeType.Organisation }; List <MyFacility> facilities = new List <MyFacility> { new MyFacility { Name = @facility.FacilityMasterName, ParentOrganisationId = @facility.OrganisationId, Value = @facility.FacilityMasterId } }; if (facilities.Count > 0) { orgNode.nodes = new List <MyNode>(); foreach (MyFacility @fac in facilities) { MyNode facNode = new MyNode { parent = orgNode.value, text = fac.Name, value = fac.Value, icon = "glyphicon glyphicon-th-list", backColor = "#ffffff", color = "#66512c", //state = new state() { @checked = true, disabled = false, expanded = true, selected = false }, nodetype = MyNodeType.Facility }; List <MyUser> users = @fac.GetAllMatchingUsers(); if (users != null && users.Count > 0) { facNode.nodes = new List <MyNode>(); foreach (MyUser @user in users) { MyNode userNode = new MyNode { parent = facNode.value, text = user.Name, value = user.Value, icon = "glyphicon glyphicon-user", backColor = "#ffffff", color = "#31708f", nodetype = MyNodeType.User }; if (ChatGroupController.CheckIfMatchingMyUserExists(participantsIds, userNode) != null) { userNode.state = new state { @checked = true, disabled = false, expanded = true, selected = false }; } facNode.nodes.Add(userNode); } } orgNode.nodes.Add(facNode); } } nodes.Add(orgNode); return(Json(nodes, JsonRequestBehavior.AllowGet)); }
public ActionResult SubResults(String selections) { var responseNodes = JsonConvert.DeserializeObject <List <MyNode> >(selections); var resultFacilities = new List <MyFacility>(); var resultOrgs = new List <MyOrganisation>(); foreach (var @node in responseNodes) { var facility = new MyFacility { Name = @node.text, Value = @node.value, ParentOrganisationId = @node.parent }; var organisation = ChatGroupController.GetMatchingOrganisation(resultOrgs, facility.GetParentOrganisation()); if (organisation == null) { resultOrgs.Add(facility.GetParentOrganisation()); } resultFacilities.Add(facility); } foreach (var @myFacility in resultFacilities) { foreach (var @organisation in resultOrgs) { if (ChatGroupController.GetMatchingFacilty(@organisation.TempFacilities, @myFacility) == null && ChatGroupController.GetMatchingFacilty(@organisation.GetAllMatchingFacilities(), @myFacility) != null) { @organisation.TempFacilities.Add(@myFacility); } } } var nodes = new List <MyNode>(); foreach (var @org in resultOrgs) { var orgNode = new MyNode { text = org.Name, value = org.Value, icon = "glyphicon glyphicon-home", backColor = "#ffffff", color = "#428bca", nodetype = MyNodeType.Organisation }; var facilities = @org.TempFacilities; if (facilities != null && facilities.Count > 0) { orgNode.nodes = new List <MyNode>(); foreach (var @fac in facilities) { var facNode = new MyNode { text = fac.Name, value = fac.Value, icon = "glyphicon glyphicon-th-list", backColor = "#ffffff", color = "#66512c", parent = org.Value, nodetype = MyNodeType.Facility }; orgNode.nodes.Add(facNode); } } nodes.Add(orgNode); } return(Json(nodes, JsonRequestBehavior.AllowGet)); }