Esempio n. 1
0
 public bool AddUser(string userName, string pwd, string ChineseName, bool isLock, bool isAdmin, string loginPc, string memo)
 {
     using (AuthorizeEntities context = new AuthorizeEntities())
     {
         try
         {
             var userAdd = new User();
             userAdd.UserID = Guid.NewGuid();
             userAdd.UserName = userName;
             userAdd.Pwd = pwd;
             userAdd.ChineseName = ChineseName;
             userAdd.IsLock = isLock;
             userAdd.IsAdmin = isAdmin;
             userAdd.LoginPC = loginPc;
             userAdd.Memo = memo;
             context.AddToUser(userAdd);
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Esempio n. 2
0
        public bool ChangePassword(string userName, string password, string newPassword)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
            if (String.IsNullOrEmpty(newPassword)) throw new ArgumentException("Value cannot be null or empty.", "newPassword");

            using (AuthorizeEntities context = new AuthorizeEntities())
            {
                try
                {
                    var user = context.User.FirstOrDefault(i => i.UserName == userName);
                    if (user != null && ValidateUser(userName, password))
                    {
                        user.UserName = userName ?? user.UserName;
                        user.Pwd = newPassword != null ? EncryptPassword(newPassword) : user.Pwd;
                        context.SaveChanges();
                    }
                    else
                    {
                        return false;
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return true;
        }
Esempio n. 3
0
 public object GetDetails(int page, int rows)
 {
     using (AuthorizeEntities context = new AuthorizeEntities())
     {
         try
         {
             var systems = from s in context.Role
                           select new { s.RoleID, s.RoleName, s.Memo, IsLock = s.IsLock ? "启用" : "禁用" };
             return systems.ToArray();
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Esempio n. 4
0
 public object GetDetails(int page, int rows)
 {
     using (AuthorizeEntities context = new AuthorizeEntities())
     {
         try
         {
             var citys = from s in context.City
                           select new { s.CityID, s.CityName, s.IsActive };
             return citys.ToArray();
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Esempio n. 5
0
 public object GetDetails(int page, int rows)
 {
     using (AuthorizeEntities context = new AuthorizeEntities())
     {
         try
         {
             var systems = from s in context.User
                           select new { s.UserID, s.UserName, IsLock = s.IsLock ? "锁定" : "未锁", IsAdmin = s.IsAdmin ? "是" : "否",s.Memo };
             return systems.ToArray();
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Esempio n. 6
0
        public bool delete(string systemId)
        {
            using (AuthorizeEntities context = new AuthorizeEntities())
            {
                try
                {
                    Guid guserId = new Guid(systemId);//从子表开始删除 一直到system表

                    var userid = from userinfo in context.User
                                 where userinfo.UserID == guserId
                                 select userinfo;
                    var userSystem = from usersys in context.UserSystem
                                     where usersys.UserSystemID == guserId
                                     select usersys;
                    var sys = from system in context.System
                              where system.SystemID == guserId
                              select system;
                    if (userid.FirstOrDefault() != null)
                    {
                        context.DeleteObject(userSystem.First());
                        context.SaveChanges();
                    }
                    if (userid.FirstOrDefault() != null)
                    {
                        context.DeleteObject(userid.First());
                        context.SaveChanges();
                    }
                    if (userid.FirstOrDefault() != null)
                    {
                        context.DeleteObject(sys.First().UserSystems);
                        context.SaveChanges();
                    }

                }
                catch (Exception e)
                {
                    throw e;
                }
                return true;
            }
        }
Esempio n. 7
0
        public bool Add(string cityname, bool isactive)
        {
            using (AuthorizeEntities context = new AuthorizeEntities())
            {
                try
                {
                    var citys =new City();
                    citys.CityID=Guid.NewGuid();
                    citys.CityName = cityname;
                    citys.IsActive = isactive;

                    context.AddToCity(citys);
                    context.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Esempio n. 8
0
        public string FindRolesForFunction(string functionId)
        {
            using (AuthorizeEntities context = new AuthorizeEntities())
            {
                Guid fid = new Guid(functionId);

                var roles = context.Role.Where(role
                    => (role.RoleSystems.Where(roleSystem
                        => (roleSystem.RoleModules.Where(roleModule
                            => (roleModule.RoleFunctions.Where(roleFunction
                                => roleFunction.Function.FunctionID == fid)).Count() > 0)).Count() > 0)).Count() > 0);
                var rolenames = roles.Select(i => i.RoleName);

                string result = "";
                foreach (var rolename in rolenames)
                {
                    result += rolename + ",";
                }
                return result;
            }
        }
Esempio n. 9
0
        public bool AddRole(string roleName, string memo, bool islock)
        {
            using (AuthorizeEntities context = new AuthorizeEntities())
            {
                try
                {
                    var roleAdd = new Role();
                    roleAdd.RoleID = Guid.NewGuid();
                    roleAdd.RoleName = roleName;
                    roleAdd.IsLock = islock;
                    roleAdd.Memo = memo;
                    context.AddToRole(roleAdd);
                    context.SaveChanges();

                    return true;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Esempio n. 10
0
        public string FindUsersForFunction(string functionId)
        {
            using (AuthorizeEntities context = new AuthorizeEntities())
            {
                Guid fid = new Guid(functionId);
                var users = context.User.Where(user
                    => (user.UserSystems.Where(userSystem
                        => (userSystem.UserModules.Where(userModule
                            => (userModule.UserFunctions.Where(userFunction
                                => userFunction.Function.FunctionID == fid)).Count() > 0)).Count() > 0)).Count() > 0);
                var usernames = users.Select(i => i.UserName);

                string result = "";
                foreach (var username in usernames)
                {
                    result += username + ",";
                }
                return result;
            }
        }
Esempio n. 11
0
        public bool ValidateUser(string userName, string password)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");

            using (AuthorizeEntities context = new AuthorizeEntities())
            {
                try
                {
                    var adduser = new User();
                    adduser.UserID = Guid.NewGuid();
                    adduser.UserName = userName;
                    adduser.Pwd = EncryptPassword(password);
                    adduser.IsLock = false;
                    adduser.IsAdmin = false;

                    var user = context.User.FirstOrDefault(i => i.UserName == userName);
                    if (user == null)
                    {
                        context.AddToUser(adduser);
                        context.SaveChanges();
                    }
                    return user != null && ComparePassword(password, user.Pwd);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }