Ejemplo n.º 1
0
        private List <FlatObject> UpdateStruct(int ParentId, RecursiveObject obj)
        {
            var fos = new List <FlatObject>();

            fos.Add(new FlatObject()
            {
                Id       = obj.Id,
                ParentId = ParentId
            });
            obj.ParentId = ParentId;
            foreach (RecursiveObject child in obj.children)
            {
                fos.AddRange(UpdateStruct(obj.Id, child));
            }
            return(fos);
        }
Ejemplo n.º 2
0
        public JsonResult GetOrgStructure()
        {
            var currentUser = new User();

            if ((Session["CurrentUser"] == null) && (Request.Cookies[FormsAuthentication.FormsCookieName] != null))
            {
                var authUser = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;

                var userModel = new UserModel();
                currentUser = userModel.GetSpecificUser(authUser);
            }
            else
            {
                if (Session["CurrentUser"] != null)
                {
                    var loggedInUser = (User)Session["CurrentUser"];

                    var userModel = new UserModel();
                    currentUser = userModel.GetSpecificUser(loggedInUser.User_Id);
                }
            }
            var userId = -1;

            if (currentUser != null)
            {
                userId = currentUser.User_Id;
            }
            var    facilityID      = orgChart.GetFacilityIdByUserID(userId);
            string teamLeader      = ConfigurationManager.AppSettings["TeamLeaderRole"];
            string facilityManager = ConfigurationManager.AppSettings["CenterManagerRole"];
            string careWorker      = ConfigurationManager.AppSettings["CareWorkerRole"];

            using (SDIIS_DatabaseEntities _context = new SDIIS_DatabaseEntities())
            {
                List <TempUser> usersAll = (from u in _context.Users
                                            join e in _context.Employees on u.User_Id equals e.User_Id
                                            join f in _context.apl_Cyca_Facility on e.Facility_Id equals f.Facility_Id
                                            where e.Facility_Id == facilityID &&
                                            (u.Roles.Any(r => r.Description == teamLeader) ||
                                             u.Roles.Any(r => r.Description == facilityManager) ||
                                             u.Roles.Any(r => r.Description == careWorker))
                                            select new TempUser
                {
                    user = u,
                    emp = e
                }).ToList();
                List <FlatObject> users = (from u in usersAll
                                           select new FlatObject()
                {
                    Name = u.user.First_Name + " " + u.user.Last_Name,
                    Id = u.emp.Employee_Id,
                    ParentId = u.emp.CYCA_Supervisor ?? 0,
                    Facility = String.Join(" ", u.user.Roles.Where(r => r.Description.Contains("CYCA")).Select(r => r.Description).ToArray()).Replace("CYCA-", "")
                }
                                           ).Distinct().ToList();

                foreach (FlatObject u in users)
                {
                    if (u.ParentId == -1)
                    {
                        u.ParentId = 0;
                    }
                    if (u.Facility.Contains(facilityManager.Replace("CYCA-", "")))
                    {
                        u.className = "FacilityManager";
                    }
                }
                var filteredUsers = users.ToList();
                List <FlatObject> childRecords   = new List <FlatObject>();
                List <FlatObject> parentRecords  = new List <FlatObject>();
                List <FlatObject> siblingRecords = new List <FlatObject>();


                //Get All Child Records
                foreach (FlatObject u in filteredUsers)
                {
                    childRecords.AddRange(GetAllChildren(u.Id, users, 0));
                    parentRecords.AddRange(GetAllParent(u.ParentId, users, 0));
                    siblingRecords.AddRange(users.Where(uu => uu.ParentId == u.ParentId && uu.ParentId > 0));
                }
                filteredUsers.AddRange(childRecords);
                filteredUsers.AddRange(parentRecords);
                filteredUsers.AddRange(siblingRecords);


                var final = filteredUsers.Distinct().ToList();

                //Get All Parent Records


                var recursiveObjects = FillRecursive(final, 0, 1);

                var overallParent = new RecursiveObject()
                {
                    Id       = 0,
                    Name     = "0. All",
                    Facility = "Department of Social Development",
                    ParentId = -1,
                    Role     = "",
                    Level    = "0",
                    children = new List <RecursiveObject>()
                };

                //Get All Parent Records
                if (CircularList != null)
                {
                    if (CircularList.Count > 0)
                    {
                        overallParent.Circulars = new List <FlatObject>();
                        overallParent.Circulars.AddRange(CircularList);
                    }
                }

                overallParent.children.AddRange(recursiveObjects);
                return(Json(overallParent, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 3
0
        public JsonResult SaveStructure(RecursiveObject org)
        {
            var currentUser = new User();

            if ((Session["CurrentUser"] == null) && (Request.Cookies[FormsAuthentication.FormsCookieName] != null))
            {
                var authUser = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;

                var userModel = new UserModel();
                currentUser = userModel.GetSpecificUser(authUser);
            }
            else
            {
                if (Session["CurrentUser"] != null)
                {
                    var loggedInUser = (User)Session["CurrentUser"];

                    var userModel = new UserModel();
                    currentUser = userModel.GetSpecificUser(loggedInUser.User_Id);
                }
            }
            var userId = -1;

            if (currentUser != null)
            {
                userId = currentUser.User_Id;
            }
            var facilityID = orgChart.GetFacilityIdByUserID(userId);

            List <FlatObject> fos = new List <FlatObject>();

            foreach (RecursiveObject child in org.children)
            {
                fos.AddRange(UpdateStruct(org.Id, child));
            }

            using (SDIIS_DatabaseEntities _context = new SDIIS_DatabaseEntities())
            {
                var users = _context.Employees.Where(e => e.Facility_Id == facilityID).ToList();
                foreach (FlatObject fo in fos)
                {
                    if (fo.Id > 0)
                    {
                        var u = users.Where(uu => uu.Employee_Id == fo.Id).Single();
                        if (u.CYCA_Supervisor != fo.ParentId && fo.ParentId >= 0)
                        {
                            if (fo.ParentId > 0)
                            {
                                u.CYCA_Supervisor = fo.ParentId;
                            }
                            else
                            {
                                u.CYCA_Supervisor = null;
                            }
                            _context.SaveChanges();
                        }
                    }
                }
            }
            return(Json(new { success = "success" }));
        }