/// <summary> /// 获取一个房屋的所有照片 /// </summary> /// <param name="houseId"></param> /// <returns></returns> public HousePicDTO[] GetPics(long houseId) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { /* * BaseService<HousePicEntity> bs = new BaseService<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();*/ BaseService <HouseEntity> bs = new BaseService <HouseEntity>(ctx); return(bs.GetById(houseId).HousePics.Select(p => new HousePicDTO { CreateDateTime = p.CreateDateTime, HouseId = p.HouseId, Id = p.Id, ThumbUrl = p.ThumbUrl, Url = p.Url }).ToArray()); } }
/// <summary> /// 分页获取一个城市下某一个类型的房屋信息列表 /// </summary> /// <param name="cityId"></param> /// <param name="typeId"></param> /// <param name="pageSize"></param> /// <param name="currentIndex"></param> /// <returns></returns> public HouseDTO[] GetPagedData(long cityId, long typeId, int pageSize, int currentIndex) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <HouseEntity> houseBS = new BaseService <HouseEntity>(ctx); var houses = houseBS.GetAll() .Include(h => h.Attachments).Include(h => h.Community) /* * .Include(h => nameof(HouseEntity.Community) + "." + nameof(CommunityEntity.Region) + "." + nameof(RegionEntity.City)) + .Include(h => nameof(HouseEntity.Community) + "." + nameof(CommunityEntity.Region))*/ //.Include("Community.Region.City") .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) //注意Where的位置,要放到Skip之前 .Where(h => h.Community.Region.CityId == cityId && h.TypeId == typeId) .OrderByDescending(h => h.CreateDateTime) .Skip(currentIndex).Take(pageSize); //.Where(h => h.Community.Region.CityId == cityId && h.TypeId == typeId); return(houses.ToList().Select(h => ToDTO(h)).ToArray()); } }
/// <summary> /// 更新一个房屋 /// </summary> /// <param name="house"></param> public void Update(HouseDTO house) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { 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(); } }
/// <summary> /// 添加一个后台用户 /// </summary> /// <param name="name"></param> /// <param name="phoneNum"></param> /// <param name="password"></param> /// <param name="email"></param> /// <param name="cityId"></param> /// <returns></returns> public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId) { AdminUserEntity user = new AdminUserEntity(); user.CityId = cityId; user.Email = email; user.Name = name; user.PhoneNum = phoneNum; string salt = CommonHelper.CreateVerifyCode(5);//盐 user.PasswordSalt = salt; //Md5(盐+用户密码) string pwdHash = CommonHelper.CalcMD5(salt + password); user.PasswordHash = pwdHash; using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx); bool exists = bs.GetAll().Any(u => u.PhoneNum == phoneNum); if (exists) { throw new ArgumentException("手机号已经存在" + phoneNum); } ctx.AdminUsers.Add(user); ctx.SaveChanges(); return(user.Id); } }
/// <summary> /// 根据id获取房屋信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public HouseDTO GetById(long id) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <HouseEntity> houseBS = new BaseService <HouseEntity>(ctx); var house = houseBS.GetAll() .Include(h => h.Attachments).Include(h => h.Community) //Include("Community.Region.City"); .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) .SingleOrDefault(h => h.Id == id); //.Where(h => h.Id == id).SingleOrDefault(); if (house == null) { return(null); } return(ToDTO(house)); } }
public SettingDTO[] GetAll() { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx); /* * return bs.GetAll().Select(s => new SettingDTO * { * Id = s.Id, * CreateDateTime = s.CreateDateTime, * Name = s.Name, * Value = s.Value * }).ToArray();*/ List <SettingDTO> list = new List <SettingDTO>(); foreach (var setting in bs.GetAll()) { SettingDTO dto = new SettingDTO(); dto.CreateDateTime = setting.CreateDateTime; dto.Id = setting.Id; dto.Name = setting.Name; dto.Value = setting.Value; list.Add(dto); } return(list.ToArray()); } }
/// <summary> /// 获取所有的角色 /// </summary> /// <returns></returns> public RoleDTO[] GetAll() { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx); return(bs.GetAll().ToList().Select(p => ToDTO(p)).ToArray()); } }
/// <summary> /// 软删除角色 /// </summary> /// <param name="roleId"></param> public void MarkDeleted(long roleId) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx); bs.MarkDeleted(roleId); } }
/// <summary> /// 软删除一个权限 /// </summary> /// <param name="id"></param> public void MarkDeleted(long id) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <PermissionEntity> bs = new BaseService <PermissionEntity>(ctx); bs.MarkDeleted(id); } }
/// <summary> /// 根据角色获取权限 /// </summary> /// <param name="roleId"></param> /// <returns></returns> public PermissionDTO[] GetByRoleId(long roleId) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx); return(bs.GetById(roleId).Permissions.ToList().Select(p => ToDTO(p)).ToArray()); } }
/// <summary> /// 根据name获取权限 /// </summary> /// <param name="name"></param> /// <returns></returns> public PermissionDTO GetByName(string name) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <PermissionEntity> bs = new BaseService <PermissionEntity>(ctx); var pe = bs.GetAll().SingleOrDefault(p => p.Name == name); return(pe == null ? null : ToDTO(pe)); } }
/// <summary> /// 根据name获取角色 /// </summary> /// <param name="name"></param> /// <returns></returns> public RoleDTO GetByName(string name) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx); var role = bs.GetAll().SingleOrDefault(r => r.Name == name); return(role == null ? null : ToDTO(role)); } }
public UserDTO GetById(long id) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx); var user = bs.GetById(id); return(user == null ? null : ToDTO(user)); } }
/// <summary> /// 获取所有城市 /// </summary> /// <returns></returns> public CityDTO[] GetAll() { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <CityEntity> bs = new BaseService <CityEntity>(ctx); return(bs.GetAll().AsNoTracking() .ToList().Select(c => ToDTO(c)).ToArray()); } }
/// <summary> /// 根据id获取权限 /// </summary> /// <param name="id"></param> /// <returns></returns> public PermissionDTO GetById(long id) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <PermissionEntity> bs = new BaseService <PermissionEntity>(ctx); var pe = bs.GetById(id); return(pe == null ? null : ToDTO(pe)); } }
public UserDTO GetByPhoneNum(string phoneNum) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx); var user = bs.GetAll().SingleOrDefault(u => u.PhoneNum == phoneNum); return(user == null ? null : ToDTO(user)); } }
/// <summary> /// 根据id获取角色 /// </summary> /// <param name="id"></param> /// <returns></returns> public RoleDTO GetById(long id) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx); var role = bs.GetById(id); return(role == null ? null : ToDTO(role)); } }
public IdNameDTO GetById(long id) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <IdNameEntity> bs = new BaseService <IdNameEntity>(ctx); return(ToDTO(bs.GetById(id))); } }
/// <summary> /// 获取一个城市下,某一个类型的房屋的数量 /// </summary> /// <param name="cityId"></param> /// <param name="typeId"></param> /// <returns></returns> public long GetTotalCount(long cityId, long typeId) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <HouseEntity> bs = new BaseService <HouseEntity>(ctx); return(bs.GetAll() .LongCount(h => h.Community.Region.CityId == cityId && h.TypeId == typeId)); } }
public IdNameDTO[] GetAll(string typeName) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <IdNameEntity> bs = new BaseService <IdNameEntity>(ctx); return(bs.GetAll().Where(e => e.TypeName == typeName) .ToList().Select(e => ToDTO(e)).ToArray()); } }
/// <summary> /// 获取所有配套设施 /// </summary> /// <returns></returns> public AttachmentDTO[] GetAll() { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <AttachmentEntity> bs = new BaseService <AttachmentEntity>(ctx); var items = bs.GetAll().AsNoTracking(); return(items.ToList().Select(a => ToDTO(a)).ToArray()); } }
/// <summary> /// 获取在一个城市下创建时间在指定时间范围内的房屋的数量 /// </summary> /// <param name="cityId"></param> /// <param name="startDateTime"></param> /// <param name="endDateTime"></param> /// <returns></returns> public long GetCount(long cityId, DateTime startDateTime, DateTime endDateTime) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <HouseEntity> houseBS = new BaseService <HouseEntity>(ctx); return(houseBS.GetAll() .LongCount(h => h.Community.Region.CityId == cityId && h.CreateDateTime >= startDateTime && h.CreateDateTime <= endDateTime)); } }
public RegionDTO GetById(long id) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <RegionEntity> bs = new BaseService <RegionEntity>(ctx); var region = bs.GetAll().Include(r => r.City) .SingleOrDefault(r => r.Id == id); return(region == null ? null : ToDTO(region)); } }
/// <summary> /// 获得所有的管理员 /// </summary> /// <param name="cityId"></param> /// <returns></returns> public AdminUserDTO[] GetAll() { using (PalmRentDbContext ctx = new PalmRentDbContext()) { //using System.Data.Entity;才能在IQueryable中用Include、AsNoTracking BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx); return(bs.GetAll().Include(u => u.City) .AsNoTracking().ToList().Select(u => ToDTO(u)).ToArray()); } }
public RegionDTO[] GetAll(long cityId) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <RegionEntity> bs = new BaseService <RegionEntity>(ctx); return(bs.GetAll().Include(r => r.City) .Where(r => r.CityId == cityId).ToList() .Select(r => ToDTO(r)).ToArray()); } }
/// <summary> /// 获得某一个城市的管理员 /// </summary> /// <param name="cityId"></param> /// <returns></returns> public AdminUserDTO[] GetAll(long?cityId) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx); //CityId is null;CityId=3 var all = bs.GetAll().Include(u => u.City) .AsNoTracking().Where(u => u.CityId == cityId); return(all.ToList().Select(u => ToDTO(u)).ToArray()); } }
/// <summary> /// 预约看房总条数 /// </summary> /// <param name="cityId"></param> /// <param name="status"></param> /// <returns></returns> public long GetTotalCount(long cityId, string status) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <HouseAppointmentEntity> bs = new BaseService <HouseAppointmentEntity>(ctx); var count = bs.GetAll() //Where(a => a.House.Community.Region.CityId == cityId && a.Status == status).LongCount() .LongCount(a => a.House.Community.Region.CityId == cityId && a.Status == status); return(count); } }
/// <summary> /// 根据Id获取城市信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public CityDTO GetById(long id) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { BaseService <CityEntity> bs = new BaseService <CityEntity>(ctx); var city = bs.GetById(id); if (city == null) { return(null); } return(ToDTO(city)); } }
/// <summary> /// 根据用户id获取角色列表 /// </summary> /// <param name="adminUserId"></param> /// <returns></returns> public RoleDTO[] GetByAdminUserId(long adminUserId) { using (PalmRentDbContext ctx = new PalmRentDbContext()) { 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()); } }
/// <summary> /// 为一个房屋添加照片 /// </summary> /// <param name="housePic"></param> /// <returns></returns> public long AddNewHousePic(HousePicDTO housePic) { HousePicEntity entity = new HousePicEntity(); entity.HouseId = housePic.HouseId; entity.ThumbUrl = housePic.ThumbUrl; entity.Url = housePic.Url; using (PalmRentDbContext ctx = new PalmRentDbContext()) { ctx.HousePics.Add(entity); ctx.SaveChanges(); return(entity.Id); } }