示例#1
0
 private IUserService GetUser(Data.User entity)
 {
     return(new UserService(entity, _UserRepository, this));
 }
示例#2
0
        public IUserService Register(IRegisterInfo info)
        {
            ExceptionHelper.ThrowIfNull(info, "info");
            ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(info.Mobile), "mobile", "手机格式不正确");
            ExceptionHelper.ThrowIfTrue(!StringRule.VerifyEmail(info.Email), "email", "邮箱格式不正确");
            ExceptionHelper.ThrowIfTrue(!StringRule.VerifyPassword(info.Password), "password", "密码格式不正确,密码长度为6-20位");
            ExceptionHelper.ThrowIfNullOrWhiteSpace(info.Name, "name", "名称不能为空");
            ExceptionHelper.ThrowIfNullOrWhiteSpace(info.Company, "company", "公司不能为空");
            ExceptionHelper.ThrowIfNullOrWhiteSpace(info.AreaNo, "areaNo", "没有选择地区");
            ExceptionHelper.ThrowIfNullOrWhiteSpace(info.Address, "address", "地址不能为空");
            ExceptionHelper.ThrowIfNullOrWhiteSpace(info.IndustryNo, "industryNo", "没有选择行业类别");

            ExceptionHelper.ThrowIfTrue(!IsUsableMobile(info.Mobile), "mobile", "此手机号已经被注册");
            ExceptionHelper.ThrowIfTrue(!IsUsableEmail(info.Email), "email", "此邮箱已经被注册");
            using (var scope = new System.Transactions.TransactionScope())
            {
                _MobileManager.Verify(info.Code, info.Mobile);
                var entity = new Data.User
                {
                    address = info.Address.SafeTrim(),
                    area_no = info.AreaNo.SafeTrim(),
                    industry_no = info.IndustryNo.SafeTrim(),
                    company = info.Company.Trim(),
                    email = info.Email.Trim(),
                    employees_count_type = info.EmployeesCountRange,
                    is_purchaser = info.IsPurchaser,
                    mobile = info.Mobile.Trim(),
                    name = info.Name.Trim(),
                    neet_invoice = info.NeetInvoice,
                    tel = info.Tel == null ? null : info.Tel.Trim(),
                    pwd = new Security.MD5().Encrypt(info.Password.Trim()),
                    last_login_date = DateTime.Now,
                    register_date = DateTime.Now,
                    enabled = true,
                };
                _UserRepository.Add(entity);
                _UserRepository.SaveChanges();
                scope.Complete();

                return GetUser(entity);
            }
        }