Пример #1
0
 public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         //假如手机号已被注册,就返回-1
         if (commonService.GetAll().Any(a => a.PhoneNum == phoneNum))
         {
             return(-1);
         }
         //密码盐 可以用生成验证码的那个随机算一个出来
         string          pwdSalt      = CommonHelper.GenerateCaptchaCode(5);
         AdminUserEntity newAdminUser = new AdminUserEntity()
         {
             Name         = name,
             PhoneNum     = phoneNum,
             CityId       = cityId,
             PasswordSalt = pwdSalt,
             PasswordHash = CommonHelper.CalcMd5(password + pwdSalt),
             Email        = email,
         };
         ctx.AdminUsers.Add(newAdminUser);
         ctx.SaveChanges();
         return(newAdminUser.Id);
     }
 }
Пример #2
0
        public long AddNew(HouseAddNewDTO house)
        {
            using (RhDbContext ctx = new RhDbContext())
            {
                HouseEntity houseEntity = new HouseEntity();
                CommonService <AttachmentEntity> attCs = new CommonService <AttachmentEntity>(ctx);
                //拿到传进来的DTO的attachmentIds为主键的房屋配套设施
                var atts = attCs.GetAll().Where(a => house.AttachmentIds.Contains(a.Id));
                foreach (var att in atts)
                {
                    houseEntity.Attachments.Add(att);
                }

                houseEntity.Address          = house.Address;
                houseEntity.Area             = house.Area;
                houseEntity.CommunityId      = house.CommunityId;
                houseEntity.CheckInDateTime  = house.CheckInDateTime;
                houseEntity.Description      = house.Description;
                houseEntity.DecorateStatusId = house.DecorateStatusId;
                houseEntity.Direction        = house.Direction;
                houseEntity.FloorIndex       = house.FloorIndex;
                houseEntity.TotalFloorCount  = house.TotalFloorCount;
                houseEntity.LookableDateTime = house.LookableDateTime;
                houseEntity.MonthRent        = house.MonthRent;
                houseEntity.OwnerName        = house.OwnerName;
                houseEntity.OwnerPhoneNum    = house.OwnerPhoneNum;
                houseEntity.RoomTypeId       = house.RoomTypeId;
                houseEntity.StatusId         = house.StatusId;
                houseEntity.TypeId           = house.TypeId;
                ctx.Houses.Add(houseEntity);
                ctx.SaveChanges();
                return(houseEntity.Id);
            }
        }
Пример #3
0
 public void ResetLoginError(long id)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         var adminUser = commonService.GetById(id);
         adminUser.LoginErrorTimes = 0;
         ctx.SaveChanges();
     }
 }
Пример #4
0
 public long AddNew(string roleName)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         RoleEntity role = new RoleEntity();
         role.Name = roleName;
         ctx.Roles.Add(role);
         ctx.SaveChanges();
         return(role.Id);
     }
 }
Пример #5
0
 public void RecordLoginError(long id)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         var adminUser = commonService.GetById(id);
         adminUser.LoginErrorTimes        = adminUser.LoginErrorTimes++;
         adminUser.LastLoginErrorDateTime = DateTime.Now;
         ctx.SaveChanges();
     }
 }
Пример #6
0
 public void AddNewLog(long adminUserId, string message)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         ctx.AdminUserLogs.Add(new AdminLogEntity()
         {
             AdminUserId = adminUserId,
             Message     = message
         });
         ctx.SaveChanges();
     }
 }
Пример #7
0
 public long AddNewHousePic(HousePicDTO housePic)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         HousePicEntity housePicEntity = new HousePicEntity();
         housePicEntity.Url      = housePic.Url;
         housePicEntity.ThumbUrl = housePic.ThumbUrl;
         housePicEntity.HouseId  = housePic.HouseId;
         ctx.HousePics.Add(housePicEntity);
         ctx.SaveChanges();
         return(housePicEntity.Id);
     }
 }
Пример #8
0
        public int MarkDeleted(long id)
        {
            T en = GetById(id);

            if (en != null)
            {
                en.IsDeleted = true;
                return(_dbContext.SaveChanges());
            }
            else
            {
                return(-1);
            }
        }
Пример #9
0
 public void SetUserCityId(long userId, long cityId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <UserEntity> cs = new CommonService <UserEntity>(ctx);
         UserEntity user = cs.GetById(userId);
         if (user == null)
         {
             throw new ArgumentException("用户不存在 " + userId);
         }
         user.CityId = cityId;
         ctx.SaveChanges();
     }
 }
Пример #10
0
        public void Update(long roleId, string roleName)
        {
            using (RhDbContext ctx = new RhDbContext())
            {
                CommonService <RoleEntity> cs = new CommonService <RoleEntity>(ctx);
                var role = cs.GetById(roleId);
                if (role == null)
                {
                    throw new ArgumentException("此角色不存在");
                }

                role.Name = roleName;
                ctx.SaveChanges();
            }
        }
Пример #11
0
 public long AddNew(string typeName, string name)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         IdNameEntity idName = new IdNameEntity()
         {
             Name     = name,
             TypeName = typeName
         };
         //TODO:检查重复的情况
         ctx.IdNames.Add(idName);
         ctx.SaveChanges();
         return(idName.Id);
     }
 }
Пример #12
0
 public void IncrLoginError(long id)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <UserEntity> cs = new CommonService <UserEntity>(ctx);
         UserEntity user = cs.GetById(id);
         if (user == null)
         {
             throw new ArgumentException("用户不存在 " + id);
         }
         user.LastLoginErrorDateTime = DateTime.Now;
         user.LoginErrorTimes++;
         ctx.SaveChanges();
     }
 }
Пример #13
0
        public void UpdatePermission(long id, string permName, string description)
        {
            using (RhDbContext ctx = new RhDbContext())
            {
                CommonService <PermissionEntity> cs = new CommonService <PermissionEntity>(ctx);
                var permEntity = cs.GetById(id);
                if (permEntity == null)
                {
                    throw new ArgumentException("id不存在  " + id);
                }

                permEntity.Name        = permName;
                permEntity.Description = description;
                ctx.SaveChanges();
            }
        }
Пример #14
0
        public long AddNew(long?userId, string name, string phoneNum, long houseId, DateTime visitDate)
        {
            HouseAppointmentEntity ha = new HouseAppointmentEntity();

            ha.UserId    = userId;
            ha.Name      = name;
            ha.PhoneNum  = phoneNum;
            ha.Status    = "未处理"; //这个忘了
            ha.HouseId   = houseId;
            ha.VisitDate = visitDate;
            using (RhDbContext ctx = new RhDbContext())
            {
                ctx.HouseAppointments.Add(ha);
                ctx.SaveChanges();
                return(ha.Id);
            }
        }
Пример #15
0
        public void UpdatePwd(long userId, string newPassword)
        {
            using (RhDbContext ctx = new RhDbContext())
            {
                CommonService <UserEntity> cs = new CommonService <UserEntity>(ctx);
                UserEntity user = cs.GetById(userId);
                if (user == null)
                {
                    throw new ArgumentException("用户不存在 " + userId);
                }

                string salt = CommonHelper.GenerateCaptchaCode(5);
                user.PasswordSalt = salt;
                user.PasswordHash = CommonHelper.CalcMd5(salt + newPassword);
                ctx.SaveChanges();
            }
        }
Пример #16
0
        public void AddRoleIds(long adminUserId, long[] roleIds)
        {
            using (RhDbContext ctx = new RhDbContext())
            {
                CommonService <AdminUserEntity> adminUserCs = new CommonService <AdminUserEntity>(ctx);
                var adminUser = adminUserCs.GetById(adminUserId);
                if (adminUser == null)
                {
                    throw new ArgumentException("管理员用户Id不存在 " + adminUserId);
                }
                CommonService <RoleEntity> roleCs = new CommonService <RoleEntity>(ctx);
                var roles = roleCs.GetAll().Where(a => roleIds.Contains(a.Id)).ToList().ToArray();
                foreach (var role in roles)
                {
                    adminUser.Roles.Add(role);
                }

                ctx.SaveChanges();
            }
        }
Пример #17
0
 public long AddPermission(string permName, string description)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <PermissionEntity> cs = new CommonService <PermissionEntity>(ctx);
         var exists = cs.GetAll().Any(a => a.Name == permName);
         if (exists)
         {
             throw new ArgumentException("此权限项已存在");
         }
         PermissionEntity permissionEntity = new PermissionEntity()
         {
             Name        = permName,
             Description = description
         };
         ctx.Permissions.Add(permissionEntity);
         ctx.SaveChanges();
         return(permissionEntity.Id);
     }
 }
Пример #18
0
        public void AddPermIds(long roleId, long[] permIds)
        {
            using (RhDbContext ctx = new RhDbContext())
            {
                CommonService <RoleEntity> roleCs = new CommonService <RoleEntity>(ctx);
                RoleEntity role = roleCs.GetById(roleId);
                if (role == null)
                {
                    throw new ArgumentException("roleId不存在 " + roleId);
                }
                CommonService <PermissionEntity> permCs = new CommonService <PermissionEntity>(ctx);
                var perms = permCs.GetAll().Where(a => permIds.Contains(a.Id)).ToArray();
                foreach (var perm in perms)
                {
                    role.Permissions.Add(perm);
                }

                ctx.SaveChanges();
            }
        }
Пример #19
0
 public void UpdateAdminUser(long id, string name, string phoneNum, string password, string email, long?cityId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         var adminUser = commonService.GetById(id);
         if (adminUser == null)
         {
             throw new ArgumentException("找不到id为" + id + "的管理员");
         }
         adminUser.Name     = name;
         adminUser.PhoneNum = phoneNum;
         if (!string.IsNullOrEmpty(password))
         {
             adminUser.PasswordHash = CommonHelper.CalcMd5(password + adminUser.PasswordSalt);
         }
         adminUser.Email  = email;
         adminUser.CityId = cityId;
         ctx.SaveChanges();
     }
 }
Пример #20
0
 //新增或更改配置信息
 public void SetValue(string name, string value)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <SettingEntity> cs = new CommonService <SettingEntity>(ctx);
         var settingEntity = cs.GetAll().SingleOrDefault(a => a.Name == name);
         if (settingEntity == null) //没有则新增
         {
             ctx.Settings.Add(new SettingEntity()
             {
                 Name  = name,
                 Value = value
             });
         }
         else
         {
             settingEntity.Value = value;
         }
         ctx.SaveChanges();
     }
 }
Пример #21
0
 public long AddNew(string cityName)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <CityEntity> baseService = new CommonService <CityEntity>(ctx);
         //判断是否存在任何一条数据满足 c.Name == cityName
         //即存在这样一个名字的城市
         //如果只是判断“是否存在”,那么用Any效率比Where().count()效率
         if (baseService.GetAll().Any(c => c.Name == cityName))
         {
             throw new ArgumentException("城市已存在");
         }
         CityEntity city = new CityEntity
         {
             Name = cityName
         };
         ctx.Cities.Add(city);
         ctx.SaveChanges();
         return(city.Id);
     }
 }
Пример #22
0
 public long AddNew(string phoneNum, string password)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         //检查手机号不能重复
         CommonService <UserEntity> cs = new CommonService <UserEntity>(ctx);
         bool exists = cs.GetAll().Any(a => a.PhoneNum == phoneNum);
         if (exists)
         {
             throw new ArgumentException("手机号已存在");
         }
         string     salt    = CommonHelper.GenerateCaptchaCode(5);
         string     pwdHash = CommonHelper.CalcMd5(salt + password);
         UserEntity user    = new UserEntity();
         user.PhoneNum     = phoneNum;
         user.PasswordSalt = salt;
         user.PasswordHash = pwdHash;
         ctx.Users.Add(user);
         ctx.SaveChanges();
         return(user.Id);
     }
 }