Exemple #1
0
        public HttpResponseMessage UpdateUserInfo(string name, string phone, string role, string ou, int id)
        {
            sys_user user = db.Sys_userRepository.Find(id);

            user.UserName = name;
            user.Mobile   = phone;
            db.Sys_userRepository.Update(user, new string[] { "UserName", "Mobile" });
            db.Sys_user_group_relationRepository.DeleteByCondition(e => e.UserID == user.UserID);
            db.Sys_user_role_relationRepository.DeleteByCondition(e => e.UserID == user.UserID);
            foreach (string r in role.Split(','))
            {
                sys_user_role_relation i3 = new sys_user_role_relation
                {
                    RoleID     = r,
                    UserID     = user.UserID,
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                db.Sys_user_role_relationRepository.Insert(i3);
            }
            sys_user_group_relation i4 = new sys_user_group_relation
            {
                OuID       = ou,
                UserID     = user.UserID,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };

            db.Sys_user_group_relationRepository.Insert(i4);

            db.Save();
            var res = new { Result = "OK" };

            return(new Models.JsonpResultAPI <object>(res));
        }
Exemple #2
0
        public HttpResponseMessage SaveUserInfo(string name, string phone, string role, string ou)
        {
            var      res       = new { Result = "OK" };
            string   salt      = Hant.Frame.Helper.EncryptPwd.CreateSalt();
            string   SHA512Pwd = Hant.Frame.Helper.EncryptPwd.CreatePwdHashSHA512("123456", salt);
            string   UserID    = new BLL.Common.Common().GetUserID();
            sys_user i1        = new sys_user
            {
                UserID     = UserID,
                UserName   = name,
                Mobile     = phone,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
                Status     = 1
            };

            db.Sys_userRepository.Insert(i1);
            sys_user_authorization i2 = new sys_user_authorization
            {
                UserID     = UserID,
                LoginName  = name,
                LoginPwd   = SHA512Pwd,
                Salt       = salt,
                LoginType  = (int)LoginType.LoginName,
                Status     = 1,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };

            db.Sys_user_authorizationRepository.Insert(i2);
            foreach (string r in role.Split(','))
            {
                sys_user_role_relation i3 = new sys_user_role_relation
                {
                    RoleID     = r,
                    UserID     = UserID,
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                db.Sys_user_role_relationRepository.Insert(i3);
            }
            sys_user_group_relation i4 = new sys_user_group_relation
            {
                OuID       = ou,
                UserID     = UserID,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };

            db.Sys_user_group_relationRepository.Insert(i4);
            db.Save();
            return(new Models.JsonpResultAPI <object>(res));
        }