Пример #1
0
        /**
         * is a user authorized for this entity permission (VIEW, PROJECT, 17)?
         *
         */
        public static bool IsUserAuthorized(User user, int permission, int entity, int targetId)
        {
            if (CanViewAny && permission == 1)
                return true;

            bool isAuth = true; /*user.Permissions.Where(p => p.PermissionTypeId >= permission &&
                                               p.EntityTypeId == entity &&
                                               p.EntityRowId == targetId).Any();
                           */

            //throw new Exception(user.Id + " - " + permission + " - " + entity + " - " + targetId + " - result = " + isAuth);
            return isAuth;
        }
Пример #2
0
        public bool isOwnerOrEditor(User user)
        {
            if (user.Id == this.Owner.Id)
                return true;

            foreach (var editor in this.Editors)
            {
                if (editor.Id == user.Id)
                    return true;
            }

            //superusers
            if (user.Id == SUPERUSER_KEN || user.Id == SUPERUSER_COLETTE || user.Id == SUPERUSER_GEORGE || user.Id == SUPERUSER_STACY)
                return true;

            return false;
        }
Пример #3
0
 public static bool IsUserInRole(User user, string role)
 {
     throw new NotImplementedException();
 }
Пример #4
0
 internal void Update(GZJContext context, string action)
 {
     var user = context.Users.SingleOrDefault(t => t.UserCode == UserCode);
     if (action == "edit")
     {
         if (null == user)
             throw new Exception("无此用户信息");
         user.UserName = UserName;
         user.DepartmentId = DepartmentId;
         user.Memo = Memo;
         user.UserPass = UserPass;
         user.UserState = UserState;
         user.ContactPhone = ContactPhone;
         user.IsAdmin = IsAdmin;
     }
     else if (action == "addnew")
     {
         if (user != null)
             throw new Exception("该登陆用户账号名称已被注册,请重新输入新的用户账号");
         user = new User
         {
             UserCode = UserCode,
             UserName = UserName,
             Memo = Memo,
             UserState=UserState,
             IsAdmin=IsAdmin,
             UserPass = UserPass,
             ContactPhone = ContactPhone,
             DepartmentId = DepartmentId
         };
         context.Users.Add(user);
     }
     else if (action == "remove")
     {
         //删除用户
         if (user == null)
             throw new Exception("该用户信息并不存在,无法删除!");
         if (user.AnnounceResults.Count > 0)
             throw new Exception("该用户通告通知结果中存在!");
         if (user.Announces.Count > 0)
             throw new Exception("该用户通告中存在");
         if (user.ArchivePaies.Count > 0)
             throw new Exception("该用户付款存档中存在");
         if (user.Archives.Count > 0)
             throw new Exception("该用户存档中存在");
         if (user.CreatedLeaseholders.Count > 0)
             throw new Exception("该用户创建承租人信息中存在");
         if (user.Houses.Count > 0)
             throw new Exception("该用户创建房源时存在");
         if (user.UpdatedLeaseHolders.Count > 0)
             throw new Exception("该用户更新房源信息时存在");
         context.Users.Remove(user);
     }
 }