/// <summary>
        /// web 访问控制器
        /// 错误拦截
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public T Visit <T>(EnumUserRole userrole, Func <T> action)
        {
            return(action.Invoke());

            try
            {
                int currentuserrole = -2;
                if (UserLoginInfo.CurrentUserLoginInfo != null && UserLoginInfo.CurrentUserLoginInfo.UserModel != null)
                {
                    currentuserrole = UserLoginInfo.CurrentUserLoginInfo.UserModel.userrole;
                }
                string Number = UserLoginInfo.CurrentUserLoginInfo.UserModel.userstaffno;
                if ((int)userrole == (int)currentuserrole || (int)userrole == -1)
                {
                    ViewBag.Role   = currentuserrole;
                    ViewBag.Number = Number;
                    return(action.Invoke());
                }
                else
                {
                    throw new Exception("无权访问!");
                }
            }
            catch (Exception exp)
            {
                //异常返回
                throw exp;
            }
        }
Exemple #2
0
 //Get all collections
 public IEnumerable <volunteer_profile> Get(EnumUserRole role, string status)
 {
     if (status == "pending")
     {
         if (role == EnumUserRole.Approver1)
         {
             return(Context.volunteer_profile.Where(x =>
                                                    (x.IsRejected == null || !x.IsRejected.Value) &&
                                                    (x.IsApprovedAtLevel1 == null || !x.IsApprovedAtLevel1.Value)
                                                    ).ToList());
         }
         if (role == EnumUserRole.Approver2)
         {
             return(Context.volunteer_profile.Where(x =>
                                                    (x.IsRejected == null || !x.IsRejected.Value)
                                                    &&
                                                    (x.IsApprovedAtLevel1 != null && x.IsApprovedAtLevel1.Value) &&
                                                    (x.IsApprovedAtLevel2 == null || !x.IsApprovedAtLevel2.Value)
                                                    ).ToList());
         }
         if (role == EnumUserRole.Approver3)
         {
             return(Context.volunteer_profile.Where(x =>
                                                    (x.IsRejected == null || !x.IsRejected.Value)
                                                    &&
                                                    (x.IsApprovedAtLevel1 != null && x.IsApprovedAtLevel1.Value) &&
                                                    x.IsApprovedAtLevel2 != null && x.IsApprovedAtLevel2.Value &&
                                                    (x.IsApprovedAtLevel3 == null || !x.IsApprovedAtLevel3.Value)
                                                    ).ToList());
         }
     }
     if (status == "approved")
     {
         return(Context.volunteer_profile.Where(x =>
                                                x.IsApprovedAtLevel1 != null && x.IsApprovedAtLevel1.Value &&
                                                x.IsApprovedAtLevel2 != null && x.IsApprovedAtLevel2.Value &&
                                                x.IsApprovedAtLevel3 != null && x.IsApprovedAtLevel3.Value &&
                                                (x.IsRejected == null || x.IsRejected.Value == false)
                                                ).ToList());
     }
     else
     {
         //if (role == EnumUserRole.Approver2)
         //    return Context.volunteer_profile.Where(x =>
         //       x.IsRejected != null && x.IsRejected.Value
         //       && (x.IsApprovedAtLevel1 == null || !x.IsApprovedAtLevel1.Value)
         //       ).ToList();
         //if (role == EnumUserRole.Approver3)
         //    return Context.volunteer_profile.Where(x =>
         //        x.IsRejected != null && x.IsRejected.Value
         //       && x.IsApprovedAtLevel1 != null && x.IsApprovedAtLevel1.Value
         //      ).ToList();
         return(Context.volunteer_profile.Where(x =>
                                                x.IsRejected != null && x.IsRejected.Value).ToList());
     }
 }
Exemple #3
0
        public static bool HasRights(uint actionRights, EnumUserRole role)
        {
            if (roleActions.ContainsKey(role))
            {
                var items = roleActions[role];

                if (Hierarchy.HasRights(actionRights, items))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #4
0
        /// <summary>
        /// UserRoleGetList
        /// </summary>
        /// <param name="">pEnumUserRole</param>
        /// <returns>ArrayList</returns>
        ///
        public ArrayList UserRoleGetList(EnumUserRole pEnumUserRole)
        {
            ArrayList     items = null;
            bool          bConn = false;
            SqlConnection conn  = getDBConnection();

            if (conn != null)
            {
                BusUserRole busUserRole = null;
                busUserRole = new BusUserRole(conn);
                items       = busUserRole.Get(pEnumUserRole);
                // close the db connection
                bConn     = CloseConnection(conn);
                _hasError = busUserRole.HasError;
                if (busUserRole.HasError)
                {
                    // error
                    ErrorCode error = new ErrorCode();
                }
            }
            return(items);
        }
Exemple #5
0
 /// <summary>
 /// web 访问控制器
 /// 错误拦截
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public T Visit <T>(EnumUserRole userrole, Func <T> action)
 {
     try
     {
         string role   = UserRole;
         string Number = UserNumber;
         if ((int)userrole == Convert.ToInt32(role) || (int)userrole == -1)
         {
             ViewBag.Role   = role;
             ViewBag.Number = Number;
             return(action.Invoke());
         }
         else
         {
             throw new Exception("无权访问!");
         }
     }
     catch (Exception exp)
     {
         //异常返回
         throw exp;
     }
 }
Exemple #6
0
        /// <summary>
        ///     Gets all UserRole objects
        ///     <remarks>
        ///         Returns UserRole objects in an array list
        ///         using the given criteria
        ///     </remarks>
        ///     <retvalue>ArrayList containing UserRole object</retvalue>
        /// </summary>
        public ArrayList Get(long pLngUserRoleID, DateTime pDtBeginDateCreated, DateTime pDtEndDateCreated, string pStrCode, string pStrDescription, string pStrVisibleCode)
        {
            UserRole data = null;

            _arrlstEntities = new ArrayList();
            EnumUserRole enumUserRole = new EnumUserRole(_conn);

            enumUserRole.SP_ENUM_NAME     = (!string.IsNullOrEmpty(SP_ENUM_NAME)) ? SP_ENUM_NAME : enumUserRole.SP_ENUM_NAME;
            enumUserRole.UserRoleID       = pLngUserRoleID;
            enumUserRole.BeginDateCreated = pDtBeginDateCreated;
            enumUserRole.EndDateCreated   = pDtEndDateCreated;
            enumUserRole.Code             = pStrCode;
            enumUserRole.Description      = pStrDescription;
            enumUserRole.VisibleCode      = pStrVisibleCode;
            enumUserRole.EnumData();
            while (enumUserRole.hasMoreElements())
            {
                data = (UserRole)enumUserRole.nextElement();
                _arrlstEntities.Add(data);
            }
            enumUserRole = null;
            ArrayList.ReadOnly(_arrlstEntities);
            return(_arrlstEntities);
        }
        private ActionResult RedirectToPortal(EnumUserRole userRole, user user)
        {
            switch (userRole)
            {
            case EnumUserRole.SuperAdmin:
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("DashBoard", "Home"));

            case EnumUserRole.Coordinator:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                var oCordinator = new CoordinatorRepository().GetByUserId(user.Id);
                if (oCordinator.IsProfileComplete == null || !oCordinator.IsProfileComplete.Value)
                {
                    return(RedirectToAction("CoordinatorProfile", "Coordinator"));
                }
                var cu = Session["user"] as ContextUser;
                if (cu != null)
                {
                    cu.PhotoPath    = oCordinator.PhotoPath;
                    Session["user"] = cu;
                }
                return(RedirectToAction("Index", "Session"));
            }

            case EnumUserRole.Volunteer:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(AfterExternalLoginCallBack(user.FirstName + user.LastName, user.Email, user.Id.ToString(), "user", "", user.FirstName + " " + user.LastName));
            }

            case EnumUserRole.Participant:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                var participant = new ParticipiantRepository().GetByUserId(user.Id);

                if (participant.IsProfileComplete == null || !participant.IsProfileComplete.Value)
                {
                    return(RedirectToAction("ParticipantProfile", "Participant"));
                }
                var cu = Session["user"] as ContextUser;
                if (cu != null)
                {
                    cu.PhotoPath    = participant.PhotoPath;
                    Session["user"] = cu;
                }
                return(RedirectToAction("Index", "Session"));
            }

            case EnumUserRole.Approver1:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("Index", "Supervisor"));
            }

            case EnumUserRole.Approver2:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("Index", "Supervisor"));
            }

            case EnumUserRole.Approver3:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("Index", "Supervisor"));
            }

            case EnumUserRole.Funder:
            {
                if (!user.FirstLogin)
                {
                    return(RedirectToAction("UpdatePassword"));
                }
                return(RedirectToAction("Index", "Report"));
            }

            default:
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemple #8
0
 /// <summary>
 ///     Gets all UserRole objects
 ///     <remarks>
 ///         Returns ArrayList containing object passed in
 ///     </remarks>
 ///     <param name="o">UserRole to be returned</param>
 ///     <retvalue>ArrayList containing UserRole object</retvalue>
 /// </summary>
 public ArrayList Get(EnumUserRole o)
 {
     return(Get(o.UserRoleID, o.BeginDateCreated, o.EndDateCreated, o.Code, o.Description, o.VisibleCode));
 }
 /// <summary>
 /// web 访问控制器
 /// 错误拦截
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public ActionResult Visit(EnumUserRole role, Func <ActionResult> action)
 {
     return(this.Visit <ActionResult>(role, action));
 }