Ejemplo n.º 1
0
        public AttachmentDTO[] GetAttachments(long houseId)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                CommonService <HouseEntity> houseBS
                    = new CommonService <HouseEntity>(ctx);
                var house = houseBS.GetAll().Include(a => a.Attachments)
                            .AsNoTracking().SingleOrDefault(h => h.Id.Equals(houseId));

                if (house == null)
                {
                    throw new ArgumentException("houseId" + houseId + "不存在");
                }
                return(house.Attachments.Select(a => ToDTO(a)).ToArray());
            }
        }
Ejemplo n.º 2
0
 public void UpdatePermission(long id, string permName, string description)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <PermissionEntity> permBS
             = new BaseService <PermissionEntity>(ctx);
         var permission = permBS.GetById(id);
         if (permission == null)
         {
             throw new ArgumentException("permission不存在" + id);
         }
         permission.Name        = permName;
         permission.Description = description;
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public AdminUserDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         CommonService <AdminUserEntity> bs
             = new CommonService <AdminUserEntity>(ctx);
         var user = bs.GetAll().Include(u => u.City)
                    .AsNoTracking().SingleOrDefault(u => u.Id.Equals(id));
         //var user = bs.GetById(id); 没机会使用include了,DTO需要返回城市信息
         if (user == null)
         {
             return(null);//不抛异常,由调用者决定处理方式
         }
         return(ToDTO(user));
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 记录用户登录次数
 /// </summary>
 /// <param name="id"></param>
 public long?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();
         return(user.LoginErrorTimes);
     }
 }
Ejemplo n.º 5
0
 public long AddNew(long?userId, string name, string phoneNum, long houseId, DateTime visitDate)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         HouseAppointmentEntity houseApp = new HouseAppointmentEntity();
         houseApp.HouseId   = houseId;
         houseApp.Name      = name;
         houseApp.PhoneNum  = phoneNum;
         houseApp.Status    = "未处理";
         houseApp.UserId    = userId;
         houseApp.VisitDate = visitDate;
         ctx.HouseAppointments.Add(houseApp);
         ctx.SaveChanges();
         return(houseApp.Id);
     }
 }
Ejemplo n.º 6
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();
     }
 }
Ejemplo n.º 7
0
        /*
         * private CommunityDTO ToDTO(CommunityEntity en)
         * {
         *  CommunityDTO dto = new CommunityDTO();
         *  dto.bui
         * }*/

        /// <summary>
        /// 根据区域id获得所有的小区
        /// </summary>
        /// <param name="regionId">区域id</param>
        /// <returns></returns>
        public CommunityDTO[] GetByRegionId(long regionId)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                BaseService <CommunityEntity> bs
                    = new BaseService <CommunityEntity>(ctx);
                var cities = bs.GetAll().AsNoTracking()
                             .Where(c => c.RegionId == regionId);
                //下面这段也可以to dto
                return(cities.Select(c => new CommunityDTO {
                    BuiltYear = c.BuiltYear,
                    CreateDateTime = c.CreateDateTime, Id = c.Id, Location = c.Location,
                    Name = c.Name, RegionId = c.RegionId, Traffic = c.Traffic
                }).ToArray());
            }
        }
Ejemplo n.º 8
0
 public bool CheckLogin(string phoneNum, string password)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
         var theUser = bs.GetAll().SingleOrDefault(u => u.PhoneNum == phoneNum);
         if (theUser == null)
         {
             return(false);
         }
         string dbHash   = theUser.PasswordHash;
         string userHash = CommonHelper.CalcMD5(theUser.PasswordSalt + password);
         //与数据库数据比较是否一致
         return(dbHash == userHash);
     }
 }
Ejemplo n.º 9
0
 public void ResetLoginError(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        = 0;
         user.LastLoginErrorDateTime = null;
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 获得某个房子的所有的配套设施
 /// </summary>
 /// <param name="houseId">房子的id</param>
 /// <returns></returns>
 public AttachmentDTO[] GetAttachments(long houseId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <HouseEntity> houseBS
             = new BaseService <HouseEntity>(ctx);
         //先获id为houseId的房子延迟加载Attachments(房子的配套设施)的属性
         var house = houseBS.GetAll().Include(a => a.Attachments)
                     .AsNoTracking().SingleOrDefault(h => h.Id == houseId);
         if (house == null)
         {
             throw new ArgumentException("houseId" + houseId + "不存在");
         }
         //一个房子有多个配套设施
         return(house.Attachments.ToList().Select(a => ToDTO(a)).ToArray());
     }
 }
Ejemplo n.º 11
0
 public long AddNew(string cityName)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <CityEntity> bs = new BaseService <CityEntity>(ctx);
         var exist = bs.GetAll().Any(p => p.Name == cityName);
         if (exist)
         {
             throw new ArgumentException("城市已存在");
         }
         CityEntity c = new CityEntity();
         c.Name = cityName;
         ctx.Cities.Add(c);
         ctx.SaveChanges();
         return(c.Id);
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 新增城市
 /// </summary>
 /// <param name="cityName"></param>
 /// <returns></returns>
 public long AddNew(string cityName)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <CityEntity> service = new BaseService <CityEntity>(ctx);
         bool exist = service.GetAll().Any(u => u.Name == cityName);
         if (exist)
         {
             throw new ArgumentException("城市名已存在");
         }
         CityEntity city = new CityEntity();
         city.Name = cityName;
         ctx.Cities.Add(city);
         ctx.SaveChanges();
         return(city.Id);
     }
 }
Ejemplo n.º 13
0
 public long AddNew(string cityName)
 {
     using (ZSZDbContext context = new ZSZDbContext())
     {
         BaseService <CityEntity> service = new BaseService <CityEntity>(context);
         bool isExists = service.GetAll().Any(p => p.Name == cityName);
         if (isExists)
         {
             throw new AggregateException("城市已经存在!");
         }
         CityEntity city = new CityEntity();
         city.Name = cityName;
         context.Cities.Add(city);
         context.SaveChanges();
         return(city.Id);
     }
 }
Ejemplo n.º 14
0
 public string GetValue(string name)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx);
         var setting = bs.GetAll().Where(s => s.Name == name).SingleOrDefault();
         if (setting == null)
         {
             return(null);
             //throw new ArgumentException("配置项Name不存在");
         }
         else
         {
             return(setting.Value);
         }
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// 新增房子的图片
        /// </summary>
        /// <param name="housePic">图片的dto对象</param>
        /// <returns></returns>
        public long AddNewHousePic(HousePicDTO housePic)
        {
            HousePicEntity entity = new HousePicEntity();

            //房子的id
            entity.HouseId = housePic.HouseId;
            //房子缩略图地址
            entity.ThumbUrl = housePic.ThumbUrl;
            //房子图片地址
            entity.Url = housePic.Url;
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                ctx.HousePics.Add(entity);
                ctx.SaveChanges();
                return(entity.Id);
            }
        }
Ejemplo n.º 16
0
 public string GetValue(string name)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx);
         var setting = bs.GetAll().AsNoTracking()
                       .SingleOrDefault(s => s.Name == name);
         if (setting == null)//没有
         {
             return(null);
         }
         else
         {
             return(setting.Value);
         }
     }
 }
Ejemplo n.º 17
0
 public long AddNew(string roleName)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <RoleEntity> service = new BaseService <RoleEntity>(ctx);
         var exist = service.GetAll().Any(u => u.Name == roleName);
         if (exist)
         {
             throw new ArgumentException("角色名字已经存在" + roleName);
         }
         RoleEntity entity = new RoleEntity();
         entity.Name = roleName;
         ctx.Roles.Add(entity);
         ctx.SaveChanges();
         return(entity.Id);
     }
 }
Ejemplo n.º 18
0
 public long AddNew(string roleName)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx);
         bool exists = bs.GetAll().Any(r => r.Name == roleName);
         if (exists)
         {
             throw new ArgumentException("角色名字已经存在" + roleName);
         }
         RoleEntity role = new RoleEntity();
         role.Name = roleName;
         ctx.Roles.Add(role);
         ctx.SaveChanges();
         return(role.Id);
     }
 }
Ejemplo n.º 19
0
 public HouseAppointmentDTO[] GetPagedData(long cityId, string status, int pageSize, int currentIndex)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         CommonService <HouseAppointmentEntity> bs
             = new CommonService <HouseAppointmentEntity>(ctx);
         var apps = bs.GetAll().Include(a => a.House)
                    .Include(nameof(HouseAppointmentEntity.House) + "." + nameof(HouseEntity.Community))
                    .Include(a => a.FollowAdminUser)
                    .Include(nameof(HouseAppointmentEntity.House) + "." + nameof(HouseEntity.Community) + "." + nameof(CommunityEntity.Region))
                    .AsNoTracking()
                    .Where(a => a.House.Community.Region.CityId == cityId && a.Status == status)
                    .OrderByDescending(a => a.CreateDateTime)
                    .Skip(currentIndex).Take(pageSize);
         return(apps.Select(a => ToDTO(a)).ToArray());
     }
 }
Ejemplo n.º 20
0
 public HousePicDTO[] GetPics(long houseId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         CommonService <HousePicEntity> bs = new CommonService <HousePicEntity>(ctx);
         return(bs.GetAll().AsNoTracking().Where(p => p.HouseId == houseId)
                .Select(p => new HousePicDTO
         {
             CreateDateTime = p.CreateDateTime,
             HouseId = p.HouseId,
             Id = p.Id,
             ThumbUrl = p.ThumbUrl,
             Url = p.Url
         })
                .ToArray());
     }
 }
Ejemplo n.º 21
0
 public void Update(long roleId, string roleName)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx);
         bool exists = bs.GetAll().Any(r => r.Name == roleName && r.Id != roleId);
         if (exists)
         {
             throw new ArgumentException("数据不正确");
         }
         RoleEntity role = new RoleEntity();
         role.Id = roleId;
         ctx.Entry(role).State = System.Data.Entity.EntityState.Unchanged;
         role.Name             = roleName;
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 22
0
 public bool CheckLogin(string phoneNum, string password)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx);
         //除了错不可怕,最怕的是有错但是表面“风平浪静”
         var user = bs.GetAll().SingleOrDefault(u => u.PhoneNum == phoneNum);
         if (user == null)
         {
             return(false);
         }
         string dbHash   = user.PasswordHash;
         string userHash = CommonHelper.CalcMD5(user.PasswordSalt + password);
         //比较数据库中的PasswordHash是否和MD5(salt+用户输入密码)一直
         return(userHash == dbHash);
     }
 }
Ejemplo n.º 23
0
 public long AddPermission(string permName, string description)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <PermissionEntity> permBS = new BaseService <PermissionEntity>(ctx);
         bool exists = permBS.GetAll().Any(p => p.Name == permName);
         if (exists)
         {
             throw new ArgumentException("权限项已经存在");
         }
         PermissionEntity perm = new PermissionEntity();
         perm.Description = description;
         perm.Name        = permName;
         ctx.Permissions.Add(perm);
         ctx.SaveChanges();
         return(perm.Id);
     }
 }
Ejemplo n.º 24
0
 public HouseDTO[] GetAll()
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <HouseEntity> houseBS = new BaseService <HouseEntity>(ctx);
         var houses = houseBS.GetAll()
                      .Include(h => h.Attachments).Include(h => h.Community)
                      .Include(nameof(HouseEntity.Community) + "." + nameof(CommunityEntity.Region)
                               + "." + nameof(RegionEntity.City))
                      .Include(nameof(HouseEntity.Community) + "." + nameof(CommunityEntity.Region))
                      .Include(h => h.DecorateStatus)
                      .Include(h => h.HousePics)
                      .Include(h => h.RoomType)
                      .Include(h => h.Status)
                      .Include(h => h.Type);
         return(houses.ToList().Select(h => ToDTO(h)).ToArray());
     }
 }
Ejemplo n.º 25
0
        public bool HasPermission(long adminUserId, string permissionName)
        {
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                CommonService <AdminUserEntity> bs
                    = new CommonService <AdminUserEntity>(ctx);
                //var user = bs.GetById(adminUserId);//没法使用include
                var user = bs.GetAll().Include(u => u.City).Single(u => u.Id.Equals(adminUserId));
                if (user == null)
                {
                    throw new ArgumentException("找不到id=" + adminUserId + "的用户");
                }

                //Roles前面使用include连接查询出来了,不存在延迟加载
                return(user.Roles.SelectMany(r => r.Permissions)
                       .Any(p => p.Name == permissionName));
            }
        }
Ejemplo n.º 26
0
 public AdminUserDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> bs
             = new BaseService <AdminUserEntity>(ctx);
         //这里不能用bs.GetById(id);因为无法Include、AsNoTracking()等
         var user = bs.GetAll().Include(u => u.City)
                    .AsNoTracking().SingleOrDefault(u => u.Id == id);
         //.AsNoTracking().Where(u=>u.Id==id).SingleOrDefault();
         //var user = bs.GetById(id); 用include就不能用GetById
         if (user == null)
         {
             return(null);
         }
         return(ToDTO(user));
     }
 }
Ejemplo n.º 27
0
 public HousePicDTO[] GetPics(long houseId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <HousePicEntity> bs = new Service.BaseService <Entities.HousePicEntity>(ctx);
         var housePics           = bs.GetAll().Where(h => h.HouseId == houseId);
         List <HousePicDTO> list = new List <HousePicDTO>();
         foreach (var housePic in housePics)
         {
             HousePicDTO dto = new HousePicDTO();
             dto.Url      = housePic.Url;
             dto.ThumbUrl = housePic.Url;
             dto.Id       = housePic.Id;
             list.Add(dto);
         }
         return(list.ToArray());
     }
 }
Ejemplo n.º 28
0
 public long AddPermission(string permName, string description)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <PermissionEntity> permissionBS = new BaseService <PermissionEntity>(ctx);
         var exist = permissionBS.GetAll().Any(u => u.Name == permName);
         if (exist)
         {
             throw new ArgumentException("权限项已经存在");
         }
         PermissionEntity entity = new PermissionEntity();
         entity.Name        = permName;
         entity.Description = description;
         ctx.Permissions.Add(entity);
         ctx.SaveChanges();
         return(entity.Id);
     }
 }
Ejemplo n.º 29
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();
     }
 }
Ejemplo n.º 30
0
 /// <summary>
 /// 检查用户登录
 /// </summary>
 /// <param name="phoneNum">手机号码</param>
 /// <param name="password">密码</param>
 /// <returns></returns>
 public bool CheckLogin(string phoneNum, string password)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <AdminUserEntity> service = new BaseService <AdminUserEntity>(ctx);
         var user = service.GetAll().SingleOrDefault(u => u.PhoneNum == phoneNum);
         if (user == null)
         {
             return(false);
         }
         string pwdHash = CommonHelper.CaclMD5(user.PasswordSalt + password);
         if (pwdHash == user.PasswordHash)
         {
             return(true);
         }
         return(false);
     }
 }