Пример #1
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);
            }
        }
Пример #2
0
        public void Update(HouseDTO house)
        {
            using (RhDbContext ctx = new RhDbContext())
            {
                CommonService <HouseEntity> cs = new CommonService <HouseEntity>(ctx);
                HouseEntity houseEntity        = cs.GetById(house.Id);
                houseEntity.Address = house.Address;
                houseEntity.Area    = house.Area;
                houseEntity.Attachments.Clear(); //先删掉再添加
                var atts = ctx.Attachments.Where(a => a.IsDeleted == false && house.AttachmentIds.Contains(a.Id));
                foreach (var att in atts)
                {
                    houseEntity.Attachments.Add(att);
                }

                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.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;
                houseEntity.TotalFloorCount  = house.TotalFloorCount;

                ctx.SaveChanges();
            }
        }
Пример #3
0
 public AttachmentDTO[] GetAll()
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         return(ctx.Attachments.Where(a => a.IsDeleted == false).AsNoTracking().ToList().Select(a => Entity2DTO(a)).ToArray());
     }
 }
Пример #4
0
 /// <summary>
 /// 带看人 抢单
 /// </summary>
 /// <param name="adminUserId">带看人ID</param>
 /// <param name="houseAppointmentId">预约单Id</param>
 /// <returns></returns>
 public bool Follow(long adminUserId, long houseAppointmentId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <HouseAppointmentEntity> cs = new CommonService <HouseAppointmentEntity>(ctx);
         var appointment = cs.GetById(houseAppointmentId);
         if (appointment == null)
         {
             throw new ArgumentException("不存在的订单Id");
         }
         //如果已有带看人,判断是否为当前用户
         if (appointment.FollowAdminUserId != null)
         {
             return(appointment.FollowAdminUserId == adminUserId);
         }
         //如果/FollowAdminUserId为null,说明有抢的机会
         appointment.FollowAdminUserId = adminUserId;
         appointment.FollowDateTime    = DateTime.Now;
         try
         {
             ctx.SaveChanges();
             return(true);
         }//如果抛出DbUpdateConcurrencyException说明抢单失败(乐观锁)
         catch (DbUpdateConcurrencyException)
         {
             return(false);
         }
     }
 }
Пример #5
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);
     }
 }
Пример #6
0
 public void MarkDelete(long roleId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <RoleEntity> cs = new CommonService <RoleEntity>(ctx);
         cs.MarkDeleted(roleId);
     }
 }
Пример #7
0
 public RegionDTO[] GetAll(long cityId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <RegionEntity> cs = new CommonService <RegionEntity>(ctx);
         return(cs.GetAll().Where(a => a.CityId == cityId).ToList().Select(a => Entity2DTO(a)).ToArray());
     }
 }
Пример #8
0
 public long GetTotalCount(long cityId, long typeId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <HouseEntity> cs = new CommonService <HouseEntity>(ctx);
         return(cs.GetAll().LongCount(a => a.Community.Region.CityId == cityId && a.TypeId == typeId));
     }
 }
Пример #9
0
 //软删除。TODO 这里是不是应该返回是否删除成功呢?
 public void MarkDeleted(long adminUserId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         commonService.MarkDeleted(adminUserId);
     }
 }
Пример #10
0
 public RoleDTO[] GetAll()
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <RoleEntity> cs = new CommonService <RoleEntity>(ctx);
         return(cs.GetAll().ToList().Select(a => Entity2DTO(a)).ToArray());
     }
 }
Пример #11
0
 public void DeleteHousePic(long housePicId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <HousePicEntity> cs = new CommonService <HousePicEntity>(ctx);
         cs.MarkDeleted(housePicId);
     }
 }
Пример #12
0
 public CityDTO[] GetAll()
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <CityEntity> commonService = new CommonService <CityEntity>(ctx);
         return(commonService.GetAll().AsNoTracking().ToList().Select(Entity2DTO).ToArray());
     }
 }
Пример #13
0
 public IdNameDTO GetById(long id)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <IdNameEntity> cs = new CommonService <IdNameEntity>(ctx);
         return(Entity2DTO(cs.GetById(id)));
     }
 }
Пример #14
0
 public void MarkDelete(long id)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <IdNameEntity> cs = new CommonService <IdNameEntity>(ctx);
         cs.MarkDeleted(id);
     }
 }
Пример #15
0
 public PermissionDTO GetByName(string name)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <PermissionEntity> cs = new CommonService <PermissionEntity>(ctx);
         var perm = cs.GetAll().SingleOrDefault(a => a.Name == name);
         return(perm == null ? null : Entity2DTO(perm));
     }
 }
Пример #16
0
 public RoleDTO GetByName(string roleName)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <RoleEntity> cs = new CommonService <RoleEntity>(ctx);
         var role = cs.GetAll().SingleOrDefault(a => a.Name == roleName);
         return(role == null ? null : Entity2DTO(role));
     }
 }
Пример #17
0
 public UserDTO GetById(long id)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <UserEntity> cs = new CommonService <UserEntity>(ctx);
         UserEntity user = cs.GetById(id);
         return(user == null ? null : Entity2DTO(user));
     }
 }
Пример #18
0
 public RoleDTO GetById(long roleId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <RoleEntity> cs = new CommonService <RoleEntity>(ctx);
         var role = cs.GetById(roleId);
         return(role == null ? null : Entity2DTO(role));
     }
 }
Пример #19
0
 public UserDTO GetbyPhoneNum(string phoneNum)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <UserEntity> cs = new CommonService <UserEntity>(ctx);
         UserEntity user = cs.GetAll().SingleOrDefault(a => a.PhoneNum == phoneNum);
         return(user == null ? null : Entity2DTO(user));
     }
 }
Пример #20
0
 public IdNameDTO[] GetAll(string typeName)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <IdNameEntity> cs = new CommonService <IdNameEntity>(ctx);
         //直接ToList都拿到内存中,免得频繁查数据库
         return(cs.GetAll().Where(a => a.TypeName == typeName).ToList().Select(a => Entity2DTO(a)).ToArray());
     }
 }
Пример #21
0
 public PermissionDTO GetById(long id)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <PermissionEntity> cs = new CommonService <PermissionEntity>(ctx);
         //return Entity2DTO(cs.GetById(id));
         var perm = cs.GetById(id);
         return(perm == null ? null : Entity2DTO(perm));
     }
 }
Пример #22
0
 public long GetTotalCount(long cityId, string status)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <HouseAppointmentEntity> cs = new CommonService <HouseAppointmentEntity>(ctx);
         var count = cs.GetAll().AsNoTracking().LongCount(h =>
                                                          h.Status == status && h.House.Community.Region.CityId == cityId);
         return(count);
     }
 }
Пример #23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cityId">如果cityId为null则查出总部的员工</param>
 /// <returns></returns>
 public AdminUserDTO[] GetAll(long?cityId)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         //不用判断cityId是否为null,为null他就查出总部的,如果cityId不为null但是不存在就应该抛出异常,找到问题
         //TODO 自己单元测试下CityId不存在的情况
         return(commonService.GetAll().Include(a => a.City).AsNoTracking().Where(a => a.CityId == cityId).ToList().Select(a => Entity2DTO(a)).ToArray());
     }
 }
Пример #24
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();
     }
 }
Пример #25
0
 public long GetCount(long cityId, DateTime startDateTime, DateTime endDateTime)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <HouseEntity> cs = new CommonService <HouseEntity>(ctx);
         return(cs.GetAll().LongCount(a => a.Community.Region.CityId == cityId &&
                                      a.CreateDateTime >= startDateTime && a.CreateDateTime <= endDateTime));
         //这里时间居然可以直接用运算符比较。。
     }
 }
Пример #26
0
 public AdminUserDTO[] GetAll()
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <AdminUserEntity> commonService = new CommonService <AdminUserEntity>(ctx);
         //因为转换成DTO一定会用到city导航属性,为了防止延迟加载就直接用include
         return(commonService.GetAll().Include(a => a.City).AsNoTracking().ToList().Select(a => Entity2DTO(a)).ToArray());
         //linq语句翻译成表达式树翻译成sql语句,entity2DTO这种写法不被ef支持,所以先ToList通过ef查到内存中在执行后面的不被支持的写法
     }
 }
Пример #27
0
 public RegionDTO GetById(long id)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <RegionEntity> cs = new CommonService <RegionEntity>(ctx);
         //return Entity2DTO(cs.GetById(id));
         var region = cs.GetById(id);
         return(region == null ? null : Entity2DTO(region));
     }
 }
Пример #28
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();
     }
 }
Пример #29
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);
     }
 }
Пример #30
0
 public HouseDTO[] GetAll()
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         CommonService <HouseEntity> cs = new CommonService <HouseEntity>(ctx);
         //为了避免延迟加载,所以直接include 在读取本表时把指定的外键表信息也读出来
         return(cs.GetAll().Include(a => a.Community).Include(a => a.Community.Region)
                .Include(a => a.Community.Region.City).Include(a => a.Attachments).Include(a => a.HousePics).Include(a => a.DecorateStatus)
                .Include(a => a.Status).Include(a => a.RoomType).Include(a => a.Type).AsNoTracking()
                .ToList().Select(a => Entity2DTO(a)).ToArray());
     }
 }