public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            AdminUserEntity user = new AdminUserEntity();

            user.CityId   = cityId;
            user.Email    = email;
            user.Name     = name;
            user.PhoneNum = phoneNum;
            string salt = CommonHelper.CreateVerifyCode(5);

            user.PasswordSalt =/* new Random().Next(10000).ToString();*/
                                salt;
            string pwdHash = CommonHelper.CalcMD5(salt + password);

            user.PasswordHash = pwdHash;
            using (ZSZDbContext ctx = new ZSZDbContext()) {
                BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
                bool exist = bs.GetAll().Any(u => u.PhoneNum == user.PhoneNum);
                if (exist)
                {
                    throw new ArgumentException("手机号已经存在");
                }
                ctx.AdminUsers.Add(user);
                ctx.SaveChanges();
                return(user.Id);
            }
        }
        private AdminUserDTO ToDto(AdminUserEntity user)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.RoleId = user.Roles.Select(u => u.Id).ToArray();
            dto.CityId = user.CityId;
            if (user.City != null)
            {
                dto.CityName = user.City.Name;//需要Include提升性能
                //总部(北京)、上海分公司、广州分公司、北京分公司
            }
            else
            {
                dto.CityName = "总部";
            }

            dto.CreateDateTime         = user.CreateDateTime;
            dto.Email                  = user.Email;
            dto.Id                     = user.Id;
            dto.LastLoginErrorDateTime = user.LastLoginErrorDateTime;
            dto.LoginErrorTimes        = user.LoginErroeTimes;
            dto.Name                   = user.Name;
            dto.PhoneNum               = user.PhoneNum;
            dto.RoleName               = user.Roles.Select(u => u.Name).ToArray();
            return(dto);
        }
Beispiel #3
0
        public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            AdminUserEntity adminAdd = new AdminUserEntity();

            adminAdd.Name     = name;
            adminAdd.PhoneNum = phoneNum;
            adminAdd.Email    = email;
            adminAdd.CityId   = cityId;
            //Passwordhash=md5(salt+用户输入密码)
            string salt = CommonHelper.GenerateCaptchaCode(4);//盐值

            adminAdd.PasswordSalt = salt;
            adminAdd.PasswordHash = CommonHelper.CalMD5(salt + password);
            using (ZSZDbContext ctx = new Service.ZSZDbContext())
            {
                BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
                bool exsits = bs.GetAll().Any(u => u.PhoneNum == phoneNum);
                if (exsits)
                {
                    throw new ArgumentException("手机号已存在!");
                }
                ctx.AdminUsers.Add(adminAdd);
                ctx.SaveChanges();
                return(adminAdd.Id);
            }
        }
        public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            AdminUserEntity user = new AdminUserEntity();

            user.Name     = name;
            user.PhoneNum = phoneNum;
            user.Email    = email;
            user.CityId   = cityId;
            string salt = CommonHelper.CreateVerifyCode(5);//取5位字符作为盐

            user.PasswordSalt = salt;
            string pwdHash = CommonHelper.CalcMD5(salt + password);

            user.PasswordHash = pwdHash;
            using (MyDbContext ctx = new MyDbContext())
            {
                //要判断手机号是否已经存在
                BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
                bool exists = bs.GetAll().Any(e => e.PhoneNum == phoneNum);
                if (exists == true)
                {
                    throw new ArgumentException("手机号已经存在");
                }
                ctx.AdminUsers.Add(user);
                ctx.SaveChanges();
                return(user.Id);
            }
        }
Beispiel #5
0
        public long AddAdminUser(string name, string phoneNum,
                                 string password, string email, long?cityId)
        {
            AdminUserEntity user = new AdminUserEntity();

            user.CityId = cityId;
            user.Email  = email;
            user.Name   = name;
            if (isPhoneNumeExistent(phoneNum))
            {
                throw new ArgumentException("手机号已经存在" + phoneNum);
            }
            user.PhoneNum = phoneNum;
            string salt = CommonHelper.CreateVerifyCode(5);//盐

            user.PasswordSalt = salt;
            //Md5(盐+用户密码)
            string pwdHash = CommonHelper.CalcMD5(salt + password);

            user.PasswordHash = pwdHash;
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                BaseService <AdminUserEntity> bs
                    = new BaseService <AdminUserEntity>(ctx);
                ctx.AdminUsers.Add(user);
                ctx.SaveChanges();
                return(user.Id);
            }
        }
Beispiel #6
0
        public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            AdminUserEntity user = new AdminUserEntity();

            user.Name     = name;
            user.PhoneNum = phoneNum;
            user.Email    = email;
            user.CityId   = cityId;
            string salt = CommonHelper.GetCaptcha(5);

            user.PasswordSalt = salt;
            user.PasswordHash = CommonHelper.GetMD5(salt + password);
            using (MyDbContext dbc = new MyDbContext())
            {
                CommonService <AdminUserEntity> cs = new CommonService <AdminUserEntity>(dbc);
                bool exists = cs.GetAll().Any(a => a.PhoneNum == phoneNum);
                if (exists)
                {
                    throw new ArgumentException("手机号:" + phoneNum + "已经存在");
                }
                else
                {
                    dbc.AdminUsers.Add(user);
                    dbc.SaveChanges();
                    return(user.Id);
                }
            }
        }
Beispiel #7
0
        private AdminUserDTO ToDTO(AdminUserEntity user)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                AdminUserDTO dto = new AdminUserDTO();
                dto.CityId = user.CityId;
                if (user.City != null)
                {
                    dto.CityName = user.City.Name;//需要Include提升性能
                }
                else
                {
                    dto.CityName = "总部";
                }

                dto.CreateDateTime         = user.CreateDateTime;
                dto.Email                  = user.Email;
                dto.Id                     = user.Id;
                dto.LastLoginErrorDateTime = user.LastLoginErrorDateTime;
                dto.LoginErrorTimes        = user.LoginErrorTimes;
                dto.Name                   = user.Name;
                dto.PhoneNum               = user.PhoneNum;
                return(dto);
            }
        }
Beispiel #8
0
        public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                AdminUserEntity user = new AdminUserEntity();
                user.CityId       = cityId;
                user.Email        = email;
                user.Name         = name;
                user.PhoneNum     = phoneNum;
                user.PasswordSalt = CommonHelper.GenerateCaptchaCode(6);//盐
                user.PasswordHash = GetPasswordHash(user.PasswordSalt, password);

                //检查手机号是否存在:使用基类服务,已经筛选掉了被删除的
                CommonService <AdminUserEntity> service = new CommonService <AdminUserEntity>(ctx);
                if (service.GetAll().Any(u => u.PhoneNum.Equals(phoneNum)))
                {
                    //抛出异常
                    throw new ArgumentException("手机号已经存在:" + phoneNum);
                }

                ctx.AdminUsers.Add(user);
                ctx.SaveChanges();

                return(user.Id);
            }
        }
Beispiel #9
0
        private AdminUserDTO ToDTO(AdminUserEntity user)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.CreateDateTime = user.CreateDateTime;
            dto.Id             = user.Id;
            dto.Name           = user.Name;
            dto.PhoneNum       = user.PhoneNum;
            return(dto);
        }
Beispiel #10
0
 /// <summary>
 /// 根据id获取AdminUserDTO
 /// </summary>
 /// <param name="id">id</param>
 /// <returns></returns>
 public AdminUserDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> service = new BaseService <AdminUserEntity>(ctx);
         AdminUserEntity user = service.GetAll().Include(u => u.City).AsNoTracking().SingleOrDefault(u => u.Id == id);
         if (user == null)
         {
             return(null);
         }
         return(ToDTO(user));
     }
 }
Beispiel #11
0
        public AdminUserDTO ToDTO(AdminUserEntity adminUserEntity)
        {
            AdminUserDTO adminUserDTO = new AdminUserDTO();

            adminUserDTO.Id                     = adminUserEntity.Id;
            adminUserDTO.Name                   = adminUserEntity.Name;
            adminUserDTO.PhoneNum               = adminUserEntity.PhoneNum;
            adminUserDTO.Email                  = adminUserEntity.Emai;
            adminUserDTO.CreateDateTime         = adminUserEntity.CreateTime;
            adminUserDTO.LoginErrorTimes        = adminUserEntity.LoginErrorTimes;
            adminUserDTO.LastLoginErrorDateTime = adminUserEntity.LastLoginErrorDateTime;
            adminUserDTO.CityId                 = adminUserEntity.CityId;
            adminUserDTO.CityName               = adminUserEntity.CityEntity.Name;
            return(adminUserDTO);
        }
Beispiel #12
0
        public long AddAdminUser(string name, string phoneNum, string password)
        {
            AdminUserEntity adminEf = new AdminUserEntity();

            adminEf.Name     = name;
            adminEf.PhoneNum = phoneNum;
            string salt = CommonHelper.CreateVerifyCode(5);//盐

            adminEf.PasswordSalt = salt;
            //Md5(盐+用户密码)
            string pwdHash = CommonHelper.CalcMD5(password + salt);//处理后的密码

            adminEf.PasswordHash = pwdHash;
            using (ZSZContext context = new ZSZContext())
            {
                context.AdminUsers.Add(adminEf);
                context.SaveChanges();
                return(adminEf.Id);
            }
        }
Beispiel #13
0
        private AdminUserDTO ToDTO(AdminUserEntity user)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.Id       = user.Id;
            dto.Name     = user.Name;
            dto.PhoneNum = user.PhoneNum;
            dto.CityId   = user.CityId;
            if (user.City != null)
            {
                dto.CityName = user.City.Name;
            }
            else
            {
                dto.CityName = "总部";
            }
            dto.CreateDateTime = user.CreateDateTime;
            dto.Email          = user.Email;
            return(dto);
        }
Beispiel #14
0
        public void AddRoleIds(long adminUserId, long[] roleIds)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                BaseService <AdminUserEntity> adminBS = new BaseService <AdminUserEntity>(ctx);
                AdminUserEntity user = adminBS.GetById(adminUserId);
                if (user == null)
                {
                    throw new ArgumentException("用户不存在" + adminUserId);
                }
                if (roleIds != null)
                {
                    BaseService <RoleEntity> roleBS = new BaseService <RoleEntity>(ctx);
                    var roles = roleBS.GetAll().Where(u => roleIds.Contains(u.Id)).ToArray();
                    foreach (var role in roles)
                    {
                        user.Roles.Add(role);
                    }
                }

                ctx.SaveChanges();
            }
        }
Beispiel #15
0
        private AdminUserDTO ToDTO(AdminUserEntity user)
        {
            AdminUserDTO dto = new AdminUserDTO();

            dto.CityId = user.CityId;
            if (user.City != null)
            {
                dto.CityName = user.City.Name;//需要Include提升性能
                //如鹏总部(北京)、如鹏网上海分公司、如鹏广州分公司、如鹏北京分公司
            }
            else
            {
                dto.CityName = "总部";
            }

            dto.CreateDateTime         = user.CreateDateTime;
            dto.Email                  = user.Email;
            dto.Id                     = user.Id;
            dto.LastLoginErrorDateTime = user.LastLoginErrorDateTime;
            dto.LoginErrorTimes        = user.LoginErrorTimes;
            dto.Name                   = user.Name;
            dto.PhoneNum               = user.PhoneNum;
            return(dto);
        }