示例#1
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="employeeId"></param>
        public int Add(int employeeId, string username, string passwd)
        {
            using (ChooseDishesEntities entities = new ChooseDishesEntities()) {
                Employee employee = entities.Employee.Find(employeeId);
                if (null == employee)
                {
                    throw new ServiceException("无法找到对应的员工,编号为:【" + employeeId + "】");
                }
                int      authorId  = SubjectUtils.GetAuthenticationId();
                UserInfo _UserInfo = new UserInfo();

                _UserInfo.EmployeeId = employeeId;
                if (null != username || null != passwd)
                {
                    _UserInfo.Username = username;
                    _UserInfo.Salt     = CryptoUtils.GetSalt();
                    _UserInfo.Password = CryptoUtils.MD5Encrypt(passwd);
                    _UserInfo.CreateBy = SubjectUtils.GetAuthenticationId();
                }
                _UserInfo.CreateDatetime = DateTime.Now;
                entities.UserInfo.Add(_UserInfo);
                try
                {
                    entities.SaveChanges();
                    Log.A(Loggers.USER_NEW, authorId, _UserInfo.UserId);
                }catch (DbEntityValidationException e) {
                    throw new ServiceException(e.Message);
                }
                return(_UserInfo.UserId);
            }
        }