Beispiel #1
0
        public List <AssetNodeVM> GetAssetNodeVMs(OrganisationalStructureLookup reference)
        {
            List <AssetNode> assetNodes = new List <AssetNode>();

            assetNodes = _context.AssetNodes.Where(id => (id.TenantId == reference.TenantId) && (id.ClientId == reference.ClientId)).ToList();

            assetNodes.OrderBy(a => a.Height);

            List <AssetNodeVM> assetNodesVM = new List <AssetNodeVM>();

            foreach (var item in assetNodes)
            {
                assetNodesVM.Add(new AssetNodeVM()
                {
                    //Code = item.Code,
                    RootAssetNodeId   = item.RootAssetNodeId,
                    DateStamp         = item.DateStamp,
                    Name              = item.Name,
                    AssetNodeId       = item.AssetNodeId,
                    ParentAssetNodeId = item.ParentAssetNodeId,
                    Reference         = item.Reference,
                    Height            = item.Height,
                    NodeId            = item.AssetNodeId,
                    ClientId          = item.ClientId,
                    TenantId          = item.TenantId,
                    Size              = item.Size
                });
            }

            List <AssetNodeVM> assetNodesVMOrdered = assetNodesVM.OrderBy(id => id.AssetNodeId).ToList();

            return(assetNodesVMOrdered);
        }
        public List <OrganizationVM> GetOrganizationVMs(OrganisationalStructureLookup reference)
        {
            var orginisations = _context.Organizations.Where(a => (a.TenantId == reference.TenantId) && (a.ClientId == reference.ClientId)).OrderBy(a => a.Height).ToList();

            List <OrganizationVM> orginisationsVM = new List <OrganizationVM>();

            foreach (var item in orginisations)
            {
                orginisationsVM.Add(new OrganizationVM()
                {
                    //Code = item.Code,
                    RootOrganizationId = item.RootOrganizationId,
                    DateStamp          = item.DateStamp,
                    Name                 = item.Name,
                    OrganizationId       = item.OrganizationId,
                    ParentOrganizationId = item.ParentOrganizationId,
                    Reference            = item.Reference,
                    Height               = item.Height,
                    NodeId               = item.OrganizationId,
                    TenantId             = item.TenantId
                                           //NodeType = 1 /*Type = 1 if organization*/
                });
            }

            return(orginisationsVM);
        }
Beispiel #3
0
        public IActionResult GetClientEmployees([FromBody] OrganisationalStructureLookup model)
        {
            if (model == null)
            {
                return(BadRequest("Make sure the form is filled correctly."));
            }
            try
            {
                List <ClientEmployee> clientEmployees = _context.ClientEmployees.Where(id => (id.ClientId == model.ClientId) && (id.TenantId == model.TenantId)).ToList();
                List <Employee>       employees       = new List <Employee>();

                foreach (var item in clientEmployees)
                {
                    employees.Add(_context.Employees.FirstOrDefault(id => (id.EmployeeId == item.EmployeeId)));
                }

                return(Ok(employees));
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened. " + Ex.Message));
            }
        }
Beispiel #4
0
        public IActionResult GetClientEmployeesForKickOff([FromBody] OrganisationalStructureLookup model)
        {
            if (model == null)
            {
                return(BadRequest("Make sure the form is filled correctly."));
            }
            try
            {
                List <ClientEmployee> clientEmployees = _context.ClientEmployees.Where(id => (id.ClientId == model.ClientId) && (id.TenantId == model.TenantId)).ToList();
                List <Employee>       lEmployees      = new List <Employee>();

                foreach (var item in clientEmployees)
                {
                    lEmployees.Add(_context.Employees.FirstOrDefault(id => (id.EmployeeId == item.EmployeeId)));
                }

                var employees = lEmployees.Select(result => new
                {
                    EmployeeId    = result.EmployeeId,
                    Name          = result.Name,
                    Surname       = result.Surname,
                    Email         = result.Email,
                    Title         = result.Title,
                    IsParticipant = GetParticipantStatus(result.EmployeeId, model.ProjectId),
                    //Root = _context.AssetNodes.FirstOrDefault(id => id.RootAssetNodeId == _context.AssetNodes.FirstOrDefault(id => id.AssetNodeId == result.AssetNodeId).RootAssetNodeId).Name,
                    Organization = GetOrganizationName(result.AssetNodeId),
                    Reeference   = _contextUsers.Users.FirstOrDefault(id => id.Id == result.Reference).FirstName
                });

                return(Ok(employees));
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened! " + Ex.Message));
            }
        }
Beispiel #5
0
        public IActionResult GetTree(OrganisationalStructureLookup reference)
        {
            List <Tree1> data     = new List <Tree1>();
            Tree1        rootTree = null;

            List <OrganizationVM> organizations = new OrganizationService(_context, _contextUsers).GetOrganizationVMs(reference);

            foreach (var org in organizations.Where(a => a.Height == 1))
            {
                rootTree              = new Tree1();
                rootTree.Name         = org.Name;
                rootTree.Children     = new List <Tree1>();
                rootTree.NodeId       = org.OrganizationId;
                rootTree.ParentNodeId = org.ParentOrganizationId;
                //rootTree.NodeType = org.NodeType;
                rootTree.Checked = false;

                data.Add(rootTree);

                var allChildrens = organizations.Where(a => a.RootOrganizationId == org.OrganizationId).OrderBy(p => p.Height).OrderBy(p => p.ParentOrganizationId).ToList();

                if (allChildrens.Count > 0)
                {
                    var maxHeight = allChildrens.Max(a => a.Height);

                    Tree1        currntParent = rootTree;
                    List <Tree1> parents      = new List <Tree1>();

                    for (int i = 2; i <= maxHeight; i++)
                    {
                        Tree1 treeBranch    = null;
                        Tree1 currentParent = null;

                        var t = allChildrens.OrderBy(h => h.Height).ToList();

                        var parentIds = t.Where(a => a.Height == i).Select(a => a.ParentOrganizationId).Distinct().ToList();

                        foreach (var id in parentIds)
                        {
                            foreach (var child in t.Where(a => a.Height == i && a.ParentOrganizationId == id))
                            {
                                treeBranch              = new Tree1();
                                treeBranch.NodeId       = child.OrganizationId;
                                treeBranch.ParentNodeId = child.ParentOrganizationId;
                                treeBranch.Name         = child.Name;
                                treeBranch.Children     = new List <Tree1>();
                                treeBranch.Checked      = false;

                                parents.Add(treeBranch);

                                if (child.ParentOrganizationId != rootTree.NodeId)
                                {
                                    currentParent = parents.FirstOrDefault(a => a.NodeId == child.ParentOrganizationId);
                                }

                                if (currentParent != null)
                                {
                                    currentParent.Children.Add(treeBranch);
                                }
                                else
                                {
                                    rootTree.Children.Add(treeBranch);
                                }
                            }
                            if (currentParent != null)
                            {
                                rootTree = currentParent;
                            }
                            else
                            {
                                rootTree = treeBranch;
                            }
                        }
                    }
                }
            }

            return(Ok(data));
        }
Beispiel #6
0
        public IActionResult GetOrgStructure(OrganisationalStructureLookup reference)
        {
            List <OrgStructure> data     = new List <OrgStructure>();
            OrgStructure        rootTree = null;

            List <AssetNodeVM> assetNodes = new AssetNodeService(_context, _contextUsers).GetAssetNodeVMs(reference);

            AssetNodeVM assetNodeVM = assetNodes.FirstOrDefault(id => id.Height == 1);

            if (assetNodeVM == null)
            {
                if (assetNodes.Count > 0)
                {
                    int firstHeight = assetNodes[0].Height - 1;
                    List <AssetNodeVM> assetNodesTemp = new List <AssetNodeVM>();
                    int flyRoot = assetNodes[0].AssetNodeId;
                    foreach (var an in assetNodes)
                    {
                        AssetNodeVM assetNodeVM1 = new AssetNodeVM();
                        assetNodeVM1                 = an;
                        assetNodeVM1.Height          = assetNodeVM1.Height - firstHeight;
                        assetNodeVM1.RootAssetNodeId = flyRoot;
                        assetNodesTemp.Add(assetNodeVM1);
                    }

                    assetNodes = new List <AssetNodeVM>();
                    assetNodes = assetNodesTemp;
                }
            }



            foreach (var asd in assetNodes.Where(a => a.Height == 1))
            {
                rootTree              = new OrgStructure();
                rootTree.Name         = asd.Name;
                rootTree.NodeId       = asd.AssetNodeId;
                rootTree.Subordinates = new List <OrgStructure>();
                rootTree.Designation  = "(" + asd.Size + ")";


                data.Add(rootTree);

                var allChildrens = assetNodes.Where(a => a.RootAssetNodeId == asd.AssetNodeId)
                                   .OrderBy(p => p.Height).OrderBy(p => p.ParentAssetNodeId).ToList();

                if (allChildrens.Count > 0)
                {
                    var maxHeight = allChildrens.Max(a => a.Height);

                    OrgStructure        currntParent = rootTree;
                    List <OrgStructure> parents      = new List <OrgStructure>();

                    for (int i = 2; i <= maxHeight; i++)
                    {
                        OrgStructure treeBranch    = null;
                        OrgStructure currentParent = null;

                        var t = allChildrens.OrderBy(h => h.Height).ToList();

                        var parentIds = t.Where(a => a.Height == i).Select(a => a.ParentAssetNodeId).Distinct().ToList();

                        foreach (var id in parentIds)
                        {
                            foreach (var child in t.Where(a => a.Height == i && a.ParentAssetNodeId == id))
                            {
                                treeBranch              = new OrgStructure();
                                treeBranch.Name         = child.Name;
                                treeBranch.NodeId       = child.NodeId;
                                treeBranch.Subordinates = new List <OrgStructure>();
                                treeBranch.Designation  = "(" + child.Size + ")";

                                parents.Add(treeBranch);

                                if (child.ParentAssetNodeId != rootTree.NodeId)
                                {
                                    currentParent = parents.FirstOrDefault(a => a.NodeId == child.ParentAssetNodeId);
                                }

                                if (currentParent != null)
                                {
                                    currentParent.Subordinates.Add(treeBranch);
                                }
                                else
                                {
                                    rootTree.Subordinates.Add(treeBranch);
                                }
                            }
                            if (currentParent != null)
                            {
                                rootTree = currentParent;
                            }
                            else
                            {
                                rootTree = treeBranch;
                            }
                        }
                    }
                }
            }

            return(Ok(data));
        }
Beispiel #7
0
        public IActionResult GetAssetNodeTree(OrganisationalStructureLookup reference)
        {
            List <Tree1> data     = new List <Tree1>();
            Tree1        rootTree = null;

            List <AssetNodeVM> assetNodes = new AssetNodeService(_context, _contextUsers).GetAssetNodeVMs(reference);

            AssetNodeVM assetNodeVM = assetNodes.FirstOrDefault(id => id.Height == 1);

            if (assetNodeVM == null)
            {
                if (assetNodes.Count > 0)
                {
                    int firstHeight = assetNodes[0].Height - 1;
                    List <AssetNodeVM> assetNodesTemp = new List <AssetNodeVM>();
                    int flyRoot = assetNodes[0].AssetNodeId;
                    foreach (var an in assetNodes)
                    {
                        AssetNodeVM assetNodeVM1 = new AssetNodeVM();
                        assetNodeVM1                 = an;
                        assetNodeVM1.Height          = assetNodeVM1.Height - firstHeight;
                        assetNodeVM1.RootAssetNodeId = flyRoot;
                        assetNodesTemp.Add(assetNodeVM1);
                    }

                    assetNodes = new List <AssetNodeVM>();
                    assetNodes = assetNodesTemp;
                }
            }



            foreach (var asd in assetNodes.Where(a => a.Height == 1))
            {
                rootTree              = new Tree1();
                rootTree.Name         = string.Format("{0} ({1})", asd.Name, asd.Size);
                rootTree.Children     = new List <Tree1>();
                rootTree.NodeId       = asd.AssetNodeId;
                rootTree.ParentNodeId = asd.ParentAssetNodeId;
                //rootTree.NodeType = asd.NodeType;
                rootTree.Checked = false;

                data.Add(rootTree);

                var allChildrens = assetNodes.Where(a => a.RootAssetNodeId == asd.AssetNodeId)
                                   .OrderBy(p => p.Height).OrderBy(p => p.ParentAssetNodeId).ToList();

                if (allChildrens.Count > 0)
                {
                    var maxHeight = allChildrens.Max(a => a.Height);

                    Tree1        currntParent = rootTree;
                    List <Tree1> parents      = new List <Tree1>();

                    for (int i = 2; i <= maxHeight; i++)
                    {
                        Tree1 treeBranch    = null;
                        Tree1 currentParent = null;

                        var t = allChildrens.OrderBy(h => h.Height).ToList();

                        var parentIds = t.Where(a => a.Height == i).Select(a => a.ParentAssetNodeId).Distinct().ToList();

                        foreach (var id in parentIds)
                        {
                            foreach (var child in t.Where(a => a.Height == i && a.ParentAssetNodeId == id))
                            {
                                treeBranch              = new Tree1();
                                treeBranch.NodeId       = child.AssetNodeId;
                                treeBranch.ParentNodeId = child.ParentAssetNodeId;
                                //treeBranch.NodeType = child.NodeType;
                                treeBranch.Name     = string.Format("{0} ({1})", child.Name, child.Size);
                                treeBranch.Children = new List <Tree1>();
                                treeBranch.Checked  = false;

                                parents.Add(treeBranch);

                                if (child.ParentAssetNodeId != rootTree.NodeId)
                                {
                                    currentParent = parents.FirstOrDefault(a => a.NodeId == child.ParentAssetNodeId);
                                }

                                if (currentParent != null)
                                {
                                    currentParent.Children.Add(treeBranch);
                                }
                                else
                                {
                                    rootTree.Children.Add(treeBranch);
                                }
                            }
                            if (currentParent != null)
                            {
                                rootTree = currentParent;
                            }
                            else
                            {
                                rootTree = treeBranch;
                            }
                        }
                    }
                }
            }

            return(Ok(data));
        }
Beispiel #8
0
        public IActionResult GetAssets(OrganisationalStructureLookup reference)
        {
            List <AssetNode> assetNodes = _context.AssetNodes.Where(id => (id.ClientId == reference.ClientId) && (id.TenantId == reference.TenantId)).ToList();

            return(Ok(assetNodes));
        }