Exemplo n.º 1
0
        protected void AddDeptHeadRoleToUserWithDateCheck(object sender, System.Timers.ElapsedEventArgs e)
        {
            List <Department>      depwithdelegateslist = new List <Department>();
            List <Department>      deplist      = new List <Department>();
            List <DDelegateDetail> delegatelist = new List <DDelegateDetail>();
            List <DateTime>        startdates   = new List <DateTime>();
            List <DateTime>        enddates     = new List <DateTime>();

            using (SA45Team12AD entities = new SA45Team12AD())
            {
                //get list of current delegates
                delegatelist = entities.DDelegateDetails.ToList();
                deplist      = entities.Departments.ToList();
                foreach (Department u in deplist)
                {
                    if (u.HasDelegate == 1)
                    {
                        depwithdelegateslist.Add(u);
                    }
                }

                if (depwithdelegateslist != null)
                {
                    foreach (Department u in depwithdelegateslist)
                    {
                        delegatelist.Add(RequisitionLogic.GetLatestDelegate(u.DeptID));
                    }
                    foreach (DDelegateDetail u in delegatelist)
                    {
                        //get username for delegates
                        string username = DisbursementLogic.GetUserName(u.DepartmentHeadDelegate, u.DepartmentID);
                        //add depthead role to user after checking period
                        if (DateTime.Today >= u.StartDate && DateTime.Today <= u.EndDate && Roles.IsUserInRole(username, "Employee"))
                        {
                            RequisitionLogic.AddDeptHeadRoleToUser(u.DepartmentHeadDelegate, u.DepartmentID);
                        }
                    }
                }
            }
            RemoveDeptHeadRoleFromUserWithDateCheck(sender, e);
        }