Example #1
0
        public long AddNew(HouseAddNewDTO house)
        {
            HouseEntity entity = new HouseEntity();

            entity.Address = house.Address;
            entity.Area    = house.Area;
            using (WarmHomeContext db = new WarmHomeContext())
            {
                BaseService <AttachmentEntity> service = new BaseService <AttachmentEntity>(db);
                var atts = service.GetAll().Where(e => house.AttachmentIds.Contains(e.Id));
                foreach (var att in atts)
                {
                    entity.Attachments.Add(att);
                }
                entity.CheckInDateTime  = house.CheckInDateTime;
                entity.CommunityId      = house.CommunityId;
                entity.DecorateStatusId = house.DecorateStatusId;
                entity.Description      = house.Description;
                entity.Direction        = house.Direction;
                entity.FloorIndex       = house.FloorIndex;
                //houseEntity.HousePics 新增后再单独添加
                entity.LookableDateTime = house.LookableDateTime;
                entity.MonthRent        = house.MonthRent;
                entity.OwnerName        = house.OwnerName;
                entity.OwnerPhoneNum    = house.OwnerPhoneNum;
                entity.RoomTypeId       = house.RoomTypeId;
                entity.StatusId         = house.StatusId;
                entity.TotalFloorCount  = house.TotalFloorCount;
                entity.TypeId           = house.TypeId;
                db.Houses.Add(entity);
                db.SaveChanges();
                return(entity.Id);
            }
        }
Example #2
0
 public HouseDTO GetById(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <HouseEntity> service = new BaseService <HouseEntity>(db);
         var data = service.GetAll().Include(e => e.Community.Region)
                    .Include(e => e.Community)
                    .Include(e => e.Housepics)
                    .Include(e => e.Community.Region.City)
                    .Include(e => e.RoomType)
                    .Include(e => e.Status)
                    .Include(e => e.DecorateStatus)
                    .Include(e => e.Type)
                    .Include(e => e.Attachments)
                    .AsNoTracking()
                    .SingleOrDefault(e => e.Id == id);
         if (data == null)
         {
             return(null);
         }
         else
         {
             return(ToDTO(data));
         }
     }
 }
Example #3
0
 public long AddNew(string phoneNum, string password)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <UserEntity> service = new BaseService <UserEntity>(db);
         bool exists = service.GetAll().Any(s => s.PhoneNum == phoneNum);
         if (exists)
         {
             throw new ArgumentException("手机号已存在");
         }
         else
         {
             string     salt   = CommonHelper.CreateVerifyCode(4);
             string     pwd    = CommonHelper.CalcMD5(password + salt);
             UserEntity entity = new UserEntity()
             {
                 PasswordSalt = salt,
                 PasswordHash = pwd,
                 PhoneNum     = phoneNum,
             };
             db.Users.Add(entity);
             return(entity.Id);
         }
     }
 }
Example #4
0
 public void Update(HouseDTO house)
 {
     using (WarmHomeContext ctx = new WarmHomeContext())
     {
         BaseService <HouseEntity> bs = new BaseService <HouseEntity>(ctx);
         HouseEntity entity           = bs.GetById(house.Id);
         entity.Address = house.Address;
         entity.Area    = house.Area;
         //2,3,4
         entity.Attachments.Clear();//先删再加
         var atts = ctx.Attachments.Where(a => a.IsDeleted == false &&
                                          house.AttachmentIds.Contains(a.Id));
         foreach (AttachmentEntity att in atts)
         {
             entity.Attachments.Add(att);
         }
         //3,4,5
         entity.CheckInDateTime  = house.CheckInDateTime;
         entity.CommunityId      = house.CommunityId;
         entity.DecorateStatusId = house.DecorateStatusId;
         entity.Description      = house.Description;
         entity.Direction        = house.Direction;
         entity.FloorIndex       = house.FloorIndex;
         entity.LookableDateTime = house.LookableDateTime;
         entity.MonthRent        = house.MonthRent;
         entity.OwnerName        = house.OwnerName;
         entity.OwnerPhoneNum    = house.OwnerPhoneNum;
         entity.RoomTypeId       = house.RoomTypeId;
         entity.StatusId         = house.StatusId;
         entity.TotalFloorCount  = house.TotalFloorCount;
         entity.TypeId           = house.TypeId;
         ctx.SaveChanges();
     }
 }
 public long GetTotalCount(long cityId, string status)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <HouseAppointmentEntity> service = new BaseService <HouseAppointmentEntity>(db);
         return(service.GetAll().Include(e => e.House.Community.Region).AsNoTracking().Where(e => e.Status == status).LongCount());
     }
 }
 public void Deleted(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <CommunityEntity> service = new BaseService <CommunityEntity>(db);
         service.MarkDeleted(id);
     }
 }
Example #7
0
 public long GetTotalCout(long cityId, long typeId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <HouseEntity> service = new BaseService <HouseEntity>(db);
         return(service.GetAll().Where(e => e.Community.Region.CityId == cityId && e.TypeId == typeId).LongCount());
     }
 }
Example #8
0
 public IEnumerable <RoleDTO> GetAll()
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RolesEntity> service = new BaseService <RolesEntity>(db);
         return(service.GetAll().ToList().Select(item => GetDTO(item)));
     }
 }
Example #9
0
 public IEnumerable <RegionDTO> GetAll()
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RegionEntity> service = new BaseService <RegionEntity>(db);
         return(service.GetAll().Include(e => e.City).ToList().Select(item => GetDTO(item)));
     }
 }
Example #10
0
 public int GetCount(long cityId, DateTime startDateTime, DateTime endDateTime)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <HouseEntity> service = new BaseService <HouseEntity>(db);
         return(service.GetAll().Where(e => e.Community.Region.CityId == cityId && e.CreateDateTime >= startDateTime && e.CreateDateTime <= endDateTime).Count());
     }
 }
Example #11
0
 public IEnumerable <PermissionDTO> GetRoleId(long roleId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RolesEntity> service = new BaseService <RolesEntity>(db);
         return(service.GetById(roleId).Permissions.Select(item => GetDTO(item)));
     }
 }
Example #12
0
 public PermissionDTO GetById(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <PermissionEntity> service = new BaseService <PermissionEntity>(db);
         return(GetDTO(service.GetById(id)));
     }
 }
Example #13
0
 public void MarkDelted(long roleId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RolesEntity> service = new BaseService <RolesEntity>(db);
         service.MarkDeleted(roleId);
     }
 }
 public IEnumerable <HouseAppointmentDTO> GetPagedData(long cityId, string status, int pageSize, int currentIndex)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <HouseAppointmentEntity> service = new BaseService <HouseAppointmentEntity>(db);
         var data = service.GetAll().Include(e => e.House.Community).Include(e => e.House.Community.Region).Include(e => e.FollowAdminUser).AsNoTracking().Where(e => e.House.Community.Region.CityId == cityId && e.Status == status).OrderBy(e => e.CreateDateTime).Skip(pageSize).Take(currentIndex);
         return(data.Select(item => DTO(item)).ToList());
     }
 }
Example #15
0
 public RoleDTO GetByName(string name)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RolesEntity> service = new BaseService <RolesEntity>(db);
         var role = service.GetAll().SingleOrDefault(e => e.Name == name);
         return(role == null ? null : GetDTO(role));
     }
 }
Example #16
0
 public RoleDTO GetById(long roleid)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RolesEntity> service = new BaseService <RolesEntity>(db);
         var role = service.GetById(roleid);
         return(role == null ? null : GetDTO(role));
     }
 }
Example #17
0
 public void DeleteHousePic(long housePicId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         HousepicEntity entity = new HousepicEntity();
         entity.Id = housePicId;
         db.Entry(entity).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
Example #18
0
 public UserDTO GetByPhoneNum(string phoneNum)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <UserEntity> service = new BaseService <UserEntity>(db);
         var user = service.GetAll().SingleOrDefault(e => e.PhoneNum == phoneNum);
         if (user == null)
         {
             return(null);
         }
         return(GetDTO(user));
     }
 }
 public HouseAppointmentDTO GetById(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <HouseAppointmentEntity> service = new BaseService <HouseAppointmentEntity>(db);
         var data = service.GetAll().Include(e => e.House.Community.Region).Include(e => e.House.Community).Include(e => e.FollowAdminUser).AsNoTracking().SingleOrDefault(e => e.Id == id);
         if (data == null)
         {
             return(null);
         }
         return(DTO(data));
     }
 }
Example #20
0
 public UserDTO GetById(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <UserEntity> service = new BaseService <UserEntity>(db);
         var data = service.GetById(id);
         if (data == null)
         {
             return(null);
         }
         return(GetDTO(data));
     }
 }
Example #21
0
 public bool CheckLogin(string phoneNum, string password)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <UserEntity> service = new BaseService <UserEntity>(db);
         var user = service.GetAll().SingleOrDefault(e => e.PhoneNum == phoneNum);
         if (user == null)
         {
             return(false);
         }
         string pwd = CommonHelper.CalcMD5(password + user.PasswordSalt);
         return(user.PasswordHash == pwd ? true : false);
     }
 }
Example #22
0
 public IEnumerable <RoleDTO> GetAdminRoles(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <AdminUserEntity> service = new BaseService <AdminUserEntity>(db);
         var user = service.GetAll().Include(e => e.Roles).SingleOrDefault(e => e.Id == id);
         if (user == null)
         {
             return(null);
         }
         var roles = user.Roles.Select(item => GetDTO(item));
         return(roles);
     }
 }
Example #23
0
 public void SetUserCityId(long userId, long cityId)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <UserEntity> service = new BaseService <UserEntity>(db);
         var user = service.GetById(userId);
         if (user == null)
         {
             throw new ArgumentException("不存在Id为" + userId + "的用户");
         }
         user.CityId = cityId;
         db.SaveChanges();
     }
 }
Example #24
0
 public long AddNewHousePic(HousePicDTO housePic)
 {
     using (WarmHomeContext db = new  WarmHomeContext())
     {
         HousepicEntity entity = new HousepicEntity()
         {
             ThumbUrl = housePic.ThumbUrl,
             Url      = housePic.Url,
             HouseId  = housePic.HouseId
         };
         db.Housepics.Add(entity);
         db.SaveChanges();
         return(entity.Id);
     }
 }
Example #25
0
 public void UpdatePwd(long userId, string newPassword)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <UserEntity> service = new BaseService <UserEntity>(db);
         var user = service.GetById(userId);
         if (user == null)
         {
             throw new ArgumentException("不存在Id为" + userId + "的用户");
         }
         string pwd = CommonHelper.CalcMD5(newPassword + user.PasswordSalt);
         user.PasswordHash = pwd;
         db.SaveChanges();
     }
 }
Example #26
0
 public void UpdateRegion(long id, long cityId, string name)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RegionEntity> service = new BaseService <RegionEntity>(db);
         var data = service.GetById(id);
         if (data == null)
         {
             throw new ArgumentException("此" + name + "区域不存在");
         }
         data.CityId = cityId;
         data.Name   = name;
         db.SaveChanges();
     }
 }
 public IEnumerable <CommunityDTO> GetAll()
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <CommunityEntity> service = new BaseService <CommunityEntity>(db);
         var data = service.GetAll().Include(e => e.Region).AsNoTracking();
         if (data.Count() > 0)
         {
             return(data.ToList().Select(item => DTO(item)));
         }
         else
         {
             return(null);
         }
     }
 }
Example #28
0
 public RegionDTO GetById(long id)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RegionEntity> service = new BaseService <RegionEntity>(db);
         var data = service.GetAll().Include(e => e.City).SingleOrDefault(e => e.Id == id);
         if (data == null)
         {
             return(null);
         }
         else
         {
             return(GetDTO(data));
         }
     }
 }
 public void AddCommunity(CommunityDTO community)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <CommunityEntity> service = new BaseService <CommunityEntity>(db);
         CommunityEntity entity = new CommunityEntity()
         {
             RegionId  = community.RegionId,
             Name      = community.Name,
             Location  = community.Location,
             BuiltYear = community.BuiltYear,
             Traffic   = community.Traffic
         };
         db.Communities.Add(entity);
         db.SaveChanges();
     }
 }
Example #30
0
 public void UpdataRole(long roleId, string name)
 {
     using (WarmHomeContext db = new WarmHomeContext())
     {
         BaseService <RolesEntity> service = new BaseService <RolesEntity>(db);
         var role = service.GetById(roleId);
         if (role == null)
         {
             throw new ArgumentException("不存在" + roleId + "的角色");
         }
         else
         {
             role.Name = name;
             db.SaveChanges();
         }
     }
 }