public ActionResult Result(string selectedOrgs, string selectedPrimary, int currentrecord, bool selectExisting)
        {
            if (selectedOrgs == "---")
            {
                return(null);
            }
            if (selectedPrimary == "---" || selectedPrimary == "0")
            {
                return(null);
            }
            string[] selectionStrings = selectedOrgs.Split(',');
            int[]    selections       = new int[selectionStrings.Count()];
            for (int i = 0; i < selectionStrings.Count(); i++)
            {
                selections[i] = int.Parse(selectionStrings[i]);
            }

            int selectedPrimaryAsInt = int.Parse(selectedPrimary);

            List <Organisation> organisations = (from orgs in _context.Organisations.AsQueryable()
                                                 where selections.Any(i => orgs.OrganisationId.Equals(i))
                                                 select orgs).ToList();

            List <MyOrganisation> myOrganisations = organisations.Select(organisation => new MyOrganisation {
                Name = organisation.Name, Value = organisation.OrganisationId
            }).ToList();

            List <int> participantsIds = null;

            if (currentrecord != 0)
            {
                UserLoginInformation currentUser = _context.UserLoginInformations.Find(currentrecord);
                participantsIds = currentUser.GetFacilityIdsInUserFacilityList();
            }
            List <MyNode> nodes = new List <MyNode>();

            foreach (MyOrganisation @org in myOrganisations)
            {
                MyNode orgNode = new MyNode
                {
                    text      = org.Name,
                    value     = org.Value,
                    icon      = "glyphicon glyphicon-home",
                    backColor = "#ffffff",
                    color     = "#428bca",
                    nodetype  = MyNodeType.Organisation
                };
                List <MyFacility> myFacilities = @org.GetAllMatchingFacilities();
                if (myFacilities != null && myFacilities.Count > 0)
                {
                    orgNode.nodes = new List <MyNode>();
                    foreach (MyFacility @fac in myFacilities)
                    {
                        if (@fac.Value != selectedPrimaryAsInt)
                        {
                            MyNode 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));
        }
예제 #2
0
        public ActionResult Result(int currentrecord)
        {
            Organisation currentOrganisation = _context.Organisations.Find(currentrecord);
            List <int>   participantsIds     = null;

            if (currentrecord != 0)
            {
                List <UserLoginInformation> usersInDb = new List <UserLoginInformation>();

                foreach (FacilityMaster @facility in currentOrganisation.GetAssocaitedFacilities())
                {
                    usersInDb.AddRange(@facility.GetAssocaitedOrganisationAdmins());
                }

                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 = @org.GetAllMatchingFacilities();

            if (facilities != null && 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));
        }