Beispiel #1
0
        public void AddUser(User user)
        {
            if (user.UID == Guid.Empty)
            {
                user.UID = Guid.NewGuid();
            }

            if (user.Organ == null)
            {
                throw new BusinessObjectLogicException("Invalid Organ!");
            }
            //if (user.Superior == null) throw new BusinessObjectLogicException("Invalid Manager!");

            user.CreateTime = DateTime.Now;
            user.Password   = RandomString.GetPassword();

            using (TranscationHelper trans = TranscationHelper.GetInstance())
            {
                trans.BeginTrans();
                try
                {
                    UserDa.InsertUser(user, trans);

                    foreach (UserRole role in user.Roles)
                    {
                        UserDa.InsertUserRole(role, trans);
                    }

                    trans.CommitTrans();
                }
                catch
                {
                    trans.RollTrans();
                    throw;
                }
            }

            if (user.Superior == null)  // 更新为自己
            {
                user.Superior = new UserBase(user.ItCode);
                UserDa.UpdateUser(user);
            }
        }
Beispiel #2
0
        public long UpdateUser(UserModel model)
        {
            long res = 0;
            // Declare new DataAccess object
            UserDa dataAccess = new UserDa();

            TblUser User = new TblUser();

            User.ID               = model.ID;
            User.UserName         = model.UserName;
            User.Name             = model.Name;
            User.Phone            = model.Phone;
            User.Receive_District = model.Receive_District;
            User.Receive_Address  = model.Receive_Address;
            User.del_flg          = Constant.DeleteFlag.NON_DELETE;
            User.ModifiedDate     = DateTime.Now;

            res = dataAccess.UpdateUser(User);
            return(res);
        }
Beispiel #3
0
        /// <summary>
        /// 更新用户信息,可以更改用户密码
        /// </summary>
        /// <param name="user"></param>
        public void EditUserInfo(string itcode, string password, string firstname, string lastname, string phone)
        {
            User existUser = UserDa.GetUserByItCode(itcode);

            if (existUser == null)
            {
                throw new BusinessObjectLogicException("Invalid User!");
            }
            if (existUser.Disabled)
            {
                throw new BusinessObjectLogicException("User is disabled!");
            }

            if (!String.IsNullOrEmpty(password))
            {
                existUser.Password = password;
            }
            existUser.FirstName = firstname;
            existUser.LastName  = lastname;
            existUser.Phone     = phone;


            UserDa.UpdateUser(existUser);
        }
Beispiel #4
0
        public void EditUser(User user)
        {
            User existUser = UserDa.GetUserByItCode(user.ItCode);

            existUser.Roles.AddRange(UserDa.GetUserRole(existUser.ItCode, null, null));

            if (user == null)
            {
                throw new BusinessObjectLogicException("Invalid User!");
            }
            if (user.Organ == null)
            {
                throw new BusinessObjectLogicException("Invalid Organ!");
            }
            if (user.Superior == null)
            {
                throw new BusinessObjectLogicException("Invalid Manager!");
            }
            if (user.Disabled && existUser.Disabled)
            {
                throw new BusinessObjectLogicException("User is disabled!");
            }

            bool updateUser = false;

            if (existUser.FirstName != user.FirstName ||
                existUser.LastName != user.LastName ||
                existUser.AbbrName != user.AbbrName ||
                existUser.Organ.ID != user.Organ.ID ||
                existUser.Superior.ItCode != user.Superior.ItCode ||
                existUser.Phone != user.Phone ||
                existUser.Disabled != user.Disabled ||
                existUser.Department != user.Department)
            {
                existUser.FirstName  = user.FirstName;
                existUser.LastName   = user.LastName;
                existUser.AbbrName   = user.AbbrName;
                existUser.Organ      = user.Organ;
                existUser.Superior   = user.Superior;
                existUser.Phone      = user.Phone;
                existUser.Disabled   = user.Disabled;
                existUser.Department = user.Department;

                updateUser = true;
            }

            List <UserRole> rolesAdd = new List <UserRole>();
            List <UserRole> rolesDel = new List <UserRole>();

            //foreach (UserRole role in existUser.Roles)
            //{
            //    if (!user.Roles.Exists(r => (r.Role == role.Role && r.BU == role.BU)))
            //        rolesDel.Add(role);
            //    //if (!user.Roles.Exists(delegate(UserRole r) { return r.Role == role.Role && r.BU == role.BU; }))
            //    //{ }
            //}
            //foreach (UserRole role in user.Roles)
            //{
            //    if (!existUser.Roles.Exists(r => (r.Role == role.Role && r.BU == role.BU)))
            //        rolesAdd.Add(role);
            //}

            // 如果没有实际更改
            if (!updateUser && rolesAdd.Count == 0 && rolesDel.Count == 0)
            {
                return;
            }

            using (TranscationHelper trans = TranscationHelper.GetInstance())
            {
                trans.BeginTrans();
                try
                {
                    if (updateUser)
                    {
                        UserDa.UpdateUser(existUser, trans);
                    }

                    foreach (UserRole role in rolesDel)
                    {
                        UserDa.DeleteUserRole(role, trans);
                    }
                    foreach (UserRole role in rolesAdd)
                    {
                        UserDa.InsertUserRole(role, trans);
                    }

                    trans.CommitTrans();
                }
                catch
                {
                    trans.RollTrans();
                    throw;
                }
            }
        }