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 InsertUser(UserModel model)
        {
            long res = 0;
            // Declare new DataAccess object
            UserDa dataAccess = new UserDa();

            TblUser User = new TblUser();

            User.Email    = model.Email;
            User.UserName = model.UserName;
            User.Password = SafePassword.GetSaltedPassword(model.Password);
            User.Phone    = model.Phone;
            User.IsAdmin  = false;
            // Chưa xác nhận email
            User.Email_Confirm = Constant.ConfirmEmail.CONFIRMED;
            User.Status        = Constant.Status.ACTIVE;

            User.del_flg     = Constant.DeleteFlag.NON_DELETE;
            User.CreatedDate = DateTime.Now;

            res = dataAccess.InsertUser(User);
            return(res);
        }