public MyOrganisation GetParentOrganisation() { var res = _context.Organisations.Where(x => x.OrganisationId == ParentOrganisationId && x.Status == 1) .Select(x => new { x.Name, x.OrganisationId }) .Single(); MyOrganisation facility = new MyOrganisation { Name = res.Name, Value = res.OrganisationId, }; return(facility); }
public ActionResult SubResults(String selections) { List <MyNode> responseNodes = JsonConvert.DeserializeObject <List <MyNode> >(selections); List <MyUser> resultUsers = new List <MyUser>(); List <MyOrganisation> resultOrgs = new List <MyOrganisation>(); foreach (MyNode @node in responseNodes) { MyUser user = new MyUser { Name = @node.text, Value = @node.value, ParentFacilityId = @node.parent }; MyOrganisation organisation = GetMatchingOrganisation(resultOrgs, user.GetParentFacility().GetParentOrganisation()); if (organisation == null) { resultOrgs.Add(user.GetParentFacility().GetParentOrganisation()); } resultUsers.Add(user); } foreach (MyUser @myUser in resultUsers) { foreach (MyOrganisation @organisation in resultOrgs) { if (GetMatchingFacilty(@organisation.TempFacilities, @myUser.GetParentFacility()) == null && GetMatchingFacilty(@organisation.GetAllMatchingFacilities(), @myUser.GetParentFacility()) != null) { @organisation.TempFacilities.Add(@myUser.GetParentFacility()); } } } foreach (MyUser @myUser in resultUsers) { foreach (MyOrganisation organisation in resultOrgs) { foreach (MyFacility facility in organisation.TempFacilities) { if (CheckIfUserBelongsToAFacilty(facility.GetAllMatchingUsers(), @myUser) != null) { @facility.TempUsers.Add(@myUser); } } } } List <MyNode> nodes = new List <MyNode>(); foreach (MyOrganisation @org in resultOrgs) { MyNode orgNode = new MyNode { text = org.Name, value = org.Value, icon = "glyphicon glyphicon-home", backColor = "#ffffff", color = "#428bca", nodetype = MyNodeType.Organisation }; List <MyFacility> facilities = @org.TempFacilities; if (facilities != null && facilities.Count > 0) { orgNode.nodes = new List <MyNode>(); foreach (MyFacility @fac in facilities) { MyNode facNode = new MyNode { text = fac.Name, value = fac.Value, icon = "glyphicon glyphicon-th-list", backColor = "#ffffff", color = "#66512c", parent = org.Value, nodetype = MyNodeType.Facility }; List <MyUser> users = @fac.TempUsers; if (users != null && users.Count > 0) { facNode.nodes = new List <MyNode>(); foreach (MyUser @user in users) { MyNode userNode = new MyNode { text = user.Name, value = user.Value, icon = "glyphicon glyphicon-user", backColor = "#ffffff", color = "#31708f", parent = fac.Value, nodetype = MyNodeType.User }; facNode.nodes.Add(userNode); } } orgNode.nodes.Add(facNode); } } nodes.Add(orgNode); } return(Json(nodes, JsonRequestBehavior.AllowGet)); }
public static MyOrganisation GetMatchingOrganisation(List <MyOrganisation> organisations, MyOrganisation organisation) { return(organisations.FirstOrDefault(each => @each.Value == organisation.Value)); }
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) { List <MyNode> responseNodes = JsonConvert.DeserializeObject <List <MyNode> >(selections); List <MyFacility> resultFacilities = new List <MyFacility>(); List <MyOrganisation> resultOrgs = new List <MyOrganisation>(); foreach (MyNode @node in responseNodes) { MyFacility facility = new MyFacility { Name = @node.text, Value = @node.value, ParentOrganisationId = @node.parent }; MyOrganisation organisation = ChatGroupController.GetMatchingOrganisation(resultOrgs, facility.GetParentOrganisation()); if (organisation == null) { resultOrgs.Add(facility.GetParentOrganisation()); } resultFacilities.Add(facility); } foreach (MyFacility @myFacility in resultFacilities) { foreach (MyOrganisation @organisation in resultOrgs) { if (ChatGroupController.GetMatchingFacilty(@organisation.TempFacilities, @myFacility) == null && ChatGroupController.GetMatchingFacilty(@organisation.GetAllMatchingFacilities(), @myFacility) != null) { @organisation.TempFacilities.Add(@myFacility); } } } List <MyNode> nodes = new List <MyNode>(); foreach (MyOrganisation @org in resultOrgs) { MyNode orgNode = new MyNode { text = org.Name, value = org.Value, icon = "glyphicon glyphicon-home", backColor = "#ffffff", color = "#428bca", nodetype = MyNodeType.Organisation }; List <MyFacility> facilities = @org.TempFacilities; if (facilities != null && facilities.Count > 0) { orgNode.nodes = new List <MyNode>(); foreach (MyFacility @fac in facilities) { MyNode 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)); }