Пример #1
0
 public PermissionDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <PermissionEntity> permissionBS = new BaseService <PermissionEntity>(ctx);
         var per = permissionBS.GetById(id);
         return(per == null ? null : ToDTO(per));
     }
 }
Пример #2
0
 public UserDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx);
         var user = bs.GetById(id);
         return(user == null ? null : ToDTO(user));
     }
 }
Пример #3
0
 public IdNameDTO GetbyId(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <IdNameEntity> bs
             = new BaseService <IdNameEntity>(ctx);
         return(ToDTO(bs.GetById(id)));
     }
 }
Пример #4
0
 public void UpdateRole(RoleDTO roleDTO)
 {
     using (MyDbContext dbContext = new MyDbContext())
     {
         BaseService <RoleEntity> baseService = new BaseService <RoleEntity>(dbContext);
         var roleEntity = baseService.GetById(roleDTO.Id);
         roleEntity.Name = roleDTO.Name;
         dbContext.SaveChanges();
     }
 }
Пример #5
0
 public void Update(long id, string name, string description)
 {
     using (MyDbContext dbContext = new MyDbContext())
     {
         BaseService <PermissionEntity> baseService = new BaseService <PermissionEntity>(dbContext);
         var entity = baseService.GetById(id);
         entity.Name        = name;
         entity.Description = description;
         dbContext.SaveChanges();
     }
 }
Пример #6
0
 public PermissionDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <PermissionEntity> bs = new BaseService <PermissionEntity>(ctx);
         var perm = bs.GetById(id);
         if (perm == null)
         {
             return(null);
         }
         return(ToDTO(perm));
     }
 }
Пример #7
0
 public AdminUserDTO GetAdminInfo(long adminId)
 {
     using (ZSZContext context = new ZSZContext())
     {
         BaseService <AdminUserEntity> adbs = new BaseService <AdminUserEntity>(context);
         var admin = adbs.GetById(adminId);
         if (admin == null)
         {
             return(null);
         }
         return(ToDTO(admin));
     }
 }
Пример #8
0
 public CityDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <CityEntity> bs = new BaseService <CityEntity>(ctx);
         var city = bs.GetById(id);
         if (city == null)
         {
             return(null);
         }
         return(ToDTO(city));
     }
 }
Пример #9
0
 public PermissionDTO GetById(long id)
 {
     using (MyDbContext context = new MyDbContext())
     {
         BaseService <PermissionEntity> baseService = new BaseService <PermissionEntity>(context);
         var entity = baseService.GetById(id);
         if (entity == null)
         {
             throw new ArgumentException("没有相关对象");
         }
         return(ToDto(entity));
     }
 }
Пример #10
0
 /// <summary>
 /// 根据用户id获得所有角色
 /// </summary>
 /// <param name="adminUserId"></param>
 /// <returns></returns>
 public RoleDTO[] GetByAdminUserId(long adminUserId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
         var user = bs.GetById(adminUserId);
         if (user == null)
         {
             throw new ArgumentException("不存在的管理员" + adminUserId);
         }
         return(user.Roles.ToList().Select(r => ToDTO(r)).ToArray());
     }
 }
Пример #11
0
 public AdminLogDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminLogEntity> service = new BaseService <AdminLogEntity>(ctx);
         var log = service.GetById(id);
         if (log == null)
         {
             return(null);
         }
         return(ToDTO(log));
     }
 }
Пример #12
0
 public RoleDTO[] GetByAdminUserId(long adminUserId)
 {
     using (ZSZContext context = new ZSZContext())
     {
         BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(context);
         var admin = bs.GetById(adminUserId);
         if (admin == null)
         {
             throw new Exception("不存在id为" + adminUserId + "的用户");
         }
         return(admin.Roles.Select(m => ToDTO(m)).ToArray());
     }
 }
Пример #13
0
 /// <summary>
 /// 根据Id求角色信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public RoleDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <RoleEntity> userBs = new BaseService <RoleEntity>(ctx);
         var user = userBs.GetById(id);
         if (user == null)
         {
             return(null);
             // throw new ArgumentException("不存在Id为" + id + "的管理员");
         }
         return(ToDTO(user));
     }
 }
Пример #14
0
 /// <summary>
 /// 设置用户的城市
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="cityId"></param>
 public void SetUserCityId(long userId, long cityId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx);
         var user = bs.GetById(userId);
         if (user == null)
         {
             throw new ArgumentException("用户id不存在" + userId);
         }
         user.CityId = cityId;
         ctx.SaveChanges();
     }
 }
Пример #15
0
 public void RecordLoginError(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
         var user = bs.GetById(id);
         if (user == null)
         {
             throw new ArgumentException("用户不存在" + id);
         }
         user.LoginErrorTimes++;
         user.LastLoginErrorDateTime = DateTime.Now;
         ctx.SaveChanges();
     }
 }
Пример #16
0
 public void UpdatePermission(long id, string permName, string description)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <PermissionEntity> bs = new BaseService <PermissionEntity>(ctx);
         var perm = bs.GetById(id);
         if (perm == null)
         {
             throw new ArgumentException("id不存在" + id);
         }
         perm.Name        = permName;
         perm.Description = description;
         ctx.SaveChanges();
     }
 }
Пример #17
0
 /// <summary>
 /// 更新用户的密码
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="newPassword"></param>
 public void UpdatePwd(long userId, string newPassword)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx);
         var user = bs.GetById(userId);
         if (user == null)
         {
             throw new ArgumentException("用户id不存在" + userId);
         }
         string salt = user.PasswordSalt;
         string hash = Common.CommonHelper.CalMD5(salt + newPassword);
         user.PasswordHash = hash;
         ctx.SaveChanges();
     }
 }
Пример #18
0
 public void ResetLoginError(long id)
 {
     using (MyDbContext ctx = new MyDbContext())
     {
         BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx);
         //检查手机号不能重复
         var user = bs.GetById(id);
         if (user == null)
         {
             throw new ArgumentException("用户不存在");
         }
         user.LoginErrorTimes        = 0;
         user.LastLoginErrorDateTime = null;
         ctx.SaveChanges();
     }
 }
Пример #19
0
 public void UpdatePermissionsByRoleId(long roleId, long[] permissionIds)
 {
     using (MyDbContext dbContext = new MyDbContext())
     {
         BaseService <RoleEntity> roleBaseService = new BaseService <RoleEntity>(dbContext);
         var roleEntity = roleBaseService.GetById(roleId);
         roleEntity.PermissionEntities.Clear();
         BaseService <PermissionEntity> permissionBaseService = new BaseService <PermissionEntity>(dbContext);
         var permissionList = permissionBaseService.GetAll().Where(x => permissionIds.Contains(x.Id)).ToArray();
         foreach (var permissionObj in permissionList)
         {
             roleEntity.PermissionEntities.Add(permissionObj);
         }
         dbContext.SaveChanges();
     }
 }
Пример #20
0
 /// <summary>
 /// 记录一次登录失败
 /// </summary>
 /// <param name="id">用户id</param>
 public void IncrLoginError(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         //检查手机号不能重复
         BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx);
         var user = bs.GetById(id);
         if (user == null)
         {
             throw new ArgumentException("用户不存在 " + id);
         }
         //设置登录错误次数
         user.LoginErrorTimes++;
         //设置登录错误时间
         user.LastLoginErrorDateTime = DateTime.Now;
         ctx.SaveChanges();
     }
 }
Пример #21
0
 /// <summary>
 /// 修改前台用户的密码
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="newPassword"></param>
 public void UpdatePwd(long userId, string newPassword)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         //检查手机号不能重复
         BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx);
         var user = bs.GetById(userId);
         if (user == null)
         {
             throw new ArgumentException("用户不存在 " + userId);
         }
         string salt    = user.PasswordSalt;// CommonHelper.CreateVerifyCode(5);
         string pwdHash = CommonHelper.CalcMD5(salt + newPassword);
         user.PasswordHash = pwdHash;
         user.PasswordSalt = salt;
         ctx.SaveChanges();
     }
 }
Пример #22
0
 public void AddPermIds(long roleId, long[] permIds)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <RoleEntity> roleBS = new BaseService <RoleEntity>(ctx);
         var role = roleBS.GetById(roleId);
         if (role == null)
         {
             throw new ArgumentException("roleId不存在" + roleId);
         }
         BaseService <PermissionEntity> permBS = new BaseService <PermissionEntity>(ctx);
         var perms = permBS.GetAll().Where(p => permIds.Contains(p.Id)).ToArray();
         foreach (var item in perms)
         {
             role.Permissions.Add(item);
         }
         ctx.SaveChanges();
     }
 }
Пример #23
0
 public void AddRoleIds(long adminUserId, long[] roleIds)
 {
     using (MyDbContext ctx = new MyDbContext())
     {
         BaseService <AdminUserEntity> userBS = new BaseService <AdminUserEntity>(ctx);
         var user = userBS.GetById(adminUserId);
         if (user == null)
         {
             throw new ArgumentException("用户不存在" + adminUserId);
         }
         BaseService <RoleEntity> roleBS = new BaseService <RoleEntity>(ctx);
         var roles = roleBS.GetAll().Where(r => roleIds.Contains(r.Id)).ToArray();
         foreach (var role in roles)
         {
             user.Roles.Add(role);
         }
         ctx.SaveChanges();
     }
 }
Пример #24
0
 /// <summary>
 ///  为某个用户更新角色
 /// </summary>
 /// <param name="adminUserId"></param>
 /// <param name="roleIds"></param>
 public void UpdateRoleIds(long adminUserId, long[] roleIds)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
         var adminUser = bs.GetById(adminUserId);
         if (adminUser == null)
         {
             throw new ArgumentException("不存在Id为" + adminUserId + "的管理员");
         }
         adminUser.Roles.Clear();
         BaseService <RoleEntity> roleBs = new BaseService <RoleEntity>(ctx);
         var roles = roleBs.GetAll().Where(r => roleIds.Contains(r.Id)).ToArray();
         foreach (var role in roles)
         {
             adminUser.Roles.Add(role);
         }
         ctx.SaveChanges();
     }
 }
Пример #25
0
 public void UpdateAdminUser(long id, string name, string phoneNum, string password, string email, long?cityId)
 {
     using (MyDbContext ctx = new MyDbContext())
     {
         BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
         //先查询再更新
         var user = bs.GetById(id);
         if (user == null)
         {
             throw new ArgumentException("用户不存在");
         }
         //EF会判断内容有没有改变,内容变了的会更新,内容不变的不更新
         user.Name         = name;
         user.PhoneNum     = phoneNum;
         user.PasswordHash = CommonHelper.CalcMD5(user.PasswordSalt + password);
         user.Email        = email;
         user.CityId       = cityId;
         ctx.SaveChanges();
     }
 }
Пример #26
0
 public AdminLogDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminLogEntity> bs = new BaseService <AdminLogEntity>(ctx);
         var log = bs.GetById(id);
         if (log == null)
         {
             return(null);
         }
         AdminLogDTO dto = new AdminLogDTO();
         dto.AdminUserId       = log.AdminUserId;
         dto.AdminUserName     = log.AdminUser.Name;
         dto.AdminUserPhoneNum = log.AdminUser.PhoneNum;
         dto.CreateDateTime    = log.CreateDateTime;
         dto.Id      = log.Id;
         dto.Message = log.Message;
         return(dto);
     }
 }
Пример #27
0
        /// <summary>
        /// 预约看房抢单(乐观锁)
        /// </summary>
        /// <param name="adminUserId">用户的id</param>
        /// <param name="houseAppointmentId">预约看房的id</param>
        /// <returns>bool(抢单成功或者失败)</returns>
        public bool Follow(long adminUserId, long houseAppointmentId)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                BaseService <HouseAppointmentEntity> bs =
                    new BaseService <HouseAppointmentEntity>(ctx);
                //先获得id为houseAppointmentId的预约看房
                var app = bs.GetById(houseAppointmentId);
                if (app == null)
                {
                    throw new ArgumentException("不存在的订单id");
                }
                //FollowAdminUserId不为null,说明要么是自己已经抢过,要么是已经早早的
                //被别人抢了
                if (app.FollowAdminUserId != null)
                {
                    return(app.FollowAdminUserId == adminUserId);

                    /*
                     * if(app.FollowAdminUserId==adminUserId)
                     * {
                     *  return true;
                     * }
                     * else
                     * {
                     *  return false;
                     * }*/
                }
                //如果/FollowAdminUserId为null,说明有抢的机会
                app.FollowAdminUserId = adminUserId;
                try
                {
                    ctx.SaveChanges();
                    return(true);
                }//如果ctx.SaveChanges()时抛出DbUpdateConcurrencyException说明抢单失败(乐观锁)
                catch (DbUpdateConcurrencyException)
                {
                    return(false);
                }
            }
        }
Пример #28
0
        public void UpdateAdminUser(long id, string name, string phoneNum, string password)
        {
            using (ZSZContext ct = new ZSZContext())
            {
                BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ct);
                //先查询出来,再做更新
                var admin = bs.GetById(id);
                if (admin == null)
                {
                    throw new Exception("不存在id为" + id + "的管理员");
                }
                admin.Name     = name;
                admin.PhoneNum = phoneNum;
                if (!string.IsNullOrEmpty(password))
                {
                    admin.PasswordHash = CommonHelper.CalcMD5(password + admin.PasswordSalt);
                }

                ct.SaveChanges();
            }
        }
Пример #29
0
 /// <summary>
 /// 修改某个角色的权限,思想,先把原来的权限清空,给它重新添加权限
 /// </summary>
 /// <param name="roleId"></param>
 /// <param name="permIds"></param>
 public void UpdatePermIds(long roleId, long[] permIds)
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <RoleEntity> roleBs = new BaseService <RoleEntity>(ctx);
         var role = roleBs.GetById(roleId);
         if (role == null)
         {
             throw new ArgumentException("角色不存在" + roleId);
         }
         //把原来的权限清空
         role.Permissions.Clear();
         BaseService <PermissionEntity> permBs = new BaseService <PermissionEntity>(ctx);
         var perms = permBs.GetAll().Where(p => permIds.Contains(p.Id)).ToList();
         foreach (var p in perms)
         {
             role.Permissions.Add(p);
         }
         ctx.SaveChanges();
     }
 }
Пример #30
0
 public void UpdateAdminUser(long id, string name, string phoneNum,
                             string password, string email, long?cityId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> bs
             = new BaseService <AdminUserEntity>(ctx);
         var user = bs.GetById(id);
         if (user == null)
         {
             throw new ArgumentException("找不到id=" + id + "的管理员");
         }
         user.Name         = name;
         user.PhoneNum     = phoneNum;
         user.Email        = email;
         user.PasswordHash =
             CommonHelper.CalcMD5(user.PasswordSalt + password);
         user.CityId = cityId;
         ctx.SaveChanges();
     }
 }