/// <summary> /// 新增房源 /// </summary> /// <param name="house"></param> /// <returns></returns> public long AddNew(HouseAddNewDTO house) { HouseEntity houseEntity = new HouseEntity(); houseEntity.Address = house.Address; houseEntity.Area = house.Area; using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <AttachmentEntity> attBs = new Service.BaseService <Entities.AttachmentEntity>(ctx); //获取house.AttachmentIds为主键的房屋配套设施 var atts = attBs.GetAll().Where(a => house.AttachmentIds.Contains(a.Id)); foreach (var att in atts) { houseEntity.Attachments.Add(att); } houseEntity.CheckInDateTime = house.CheckInDateTime; houseEntity.CommunityId = house.CommunityId; houseEntity.DecorateStatusId = house.DecorateStatusId; houseEntity.Description = house.Description; houseEntity.Direction = house.Direction; houseEntity.FloorIndex = house.FloorIndex; //houseEntity.HousePics 新增后再单独添加 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.TotalFloorCount = house.TotalFloorCount; houseEntity.TypeId = house.TypeId; ctx.Houses.Add(houseEntity); ctx.SaveChanges(); return(houseEntity.Id); } }
public long AddAdminUser(string name, string phoneNum, string password, string email, long?cityId) { AdminUserEntity adminAdd = new AdminUserEntity(); adminAdd.Name = name; adminAdd.PhoneNum = phoneNum; adminAdd.Email = email; adminAdd.CityId = cityId; //Passwordhash=md5(salt+用户输入密码) string salt = CommonHelper.GenerateCaptchaCode(4);//盐值 adminAdd.PasswordSalt = salt; adminAdd.PasswordHash = CommonHelper.CalMD5(salt + password); using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx); bool exsits = bs.GetAll().Any(u => u.PhoneNum == phoneNum); if (exsits) { throw new ArgumentException("手机号已存在!"); } ctx.AdminUsers.Add(adminAdd); ctx.SaveChanges(); return(adminAdd.Id); } }
public AttachmentDTO[] GetAll() { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <AttachmentEntity> bs = new Service.BaseService <Entities.AttachmentEntity>(ctx); return(bs.GetAll().ToList().Select(a => ToDTO(a)).ToArray()); } }
public void MarkDeleted(long id) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <PermissionEntity> bs = new Service.BaseService <Entities.PermissionEntity>(ctx); bs.MarkDeleted(id); } }
/// <summary> /// 求CityId这个所在城市下区域信息 /// </summary> /// <param name="cityId"></param> /// <returns></returns> public RegionDTO[] GetAll(long cityId) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <RegionEntity> bs = new Service.BaseService <Entities.RegionEntity>(ctx); return(bs.GetAll().Include(r => r.City).Where(r => r.CityId == cityId).ToList().Select(r => ToDTO(r)).ToArray()); } }
public PermissionDTO[] GetAll() { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <PermissionEntity> perms = new Service.BaseService <Entities.PermissionEntity>(ctx); return(perms.GetAll().ToList().Select(p => ToDTO(p)).ToArray()); } }
public PermissionDTO GetById(long id) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <PermissionEntity> bs = new BaseService <PermissionEntity>(ctx); var perm = bs.GetById(id); if (perm == null) { return(null); } return(ToDTO(perm)); } }
public AttachmentDTO[] GetAttachments(long houseId) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <HouseEntity> bs = new BaseService <HouseEntity>(ctx); var house = bs.GetAll().Include(h => h.Attachments).AsNoTracking().SingleOrDefault(h => h.Id == houseId); if (house == null) { throw new ArgumentException("houseId" + houseId + "不存在"); } return(house.Attachments.ToList().Select(a => ToDTO(a)).ToArray()); } }
public CityDTO GetById(long id) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <CityEntity> bs = new BaseService <CityEntity>(ctx); var city = bs.GetById(id); if (city == null) { return(null); } return(ToDTO(city)); } }
public bool CheckLogin(string phoneNum, string password) { using (ZSZDbContext ctx = new Service.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 hash = CommonHelper.CalMD5(user.PasswordSalt + password); return(hash == dbHash); } }
public HouseAppointmentDTO GetById(long id) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <HouseAppointmentEntity> bs = new Service.BaseService <Entities.HouseAppointmentEntity>(ctx); var houseApp = bs.GetAll().Include(a => a.House).Include(nameof(HouseAppointmentEntity.House) + "." + nameof(HouseEntity.Community)).Include(a => a.FollowAdminUser).Include //Include("House.Community.Region") (nameof(HouseAppointmentEntity.House) + "." + nameof(HouseEntity.Community) + "." + nameof(CommunityEntity.Region)).AsNoTracking().SingleOrDefault(a => a.Id == id); if (houseApp == null) { return(null); } return(ToDTO(houseApp)); } }
public long AddNew(long?userId, string name, string phoneNum, long houseId, DateTime visitDate) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { HouseAppointmentEntity houseApp = new HouseAppointmentEntity(); houseApp.HouseId = houseId; houseApp.VisitDate = visitDate; houseApp.Name = name; houseApp.PhoneNum = phoneNum; houseApp.Status = "未处理"; houseApp.UserId = userId; ctx.HouseAppointments.Add(houseApp); ctx.SaveChanges(); return(houseApp.Id); } }
/// <summary> /// 新增角色 /// </summary> /// <param name="roleName"></param> /// <returns></returns> public long AddNew(string roleName) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <RoleEntity> bs = new BaseService <RoleEntity>(ctx); bool exsits = bs.GetAll().Any(r => r.Name == roleName); if (exsits) { throw new ArgumentException("角色已存在" + roleName); } RoleEntity role = new RoleEntity(); role.Name = roleName; ctx.Roles.Add(role); ctx.SaveChanges(); return(role.Id); } }
/// <summary> /// 查看今天新增的房源数量 /// </summary> /// <param name="cityId"></param> /// <returns></returns> public int GetTodayNewHouseCount(long cityId) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { //房子创建的时间是在当前时间内的24个小时,就认为是“今天的房源” //日期相减结果是TimeSpan类型 /* * return bs.GetAll().Count(h => h.Community.Region.CityId==cityId * && (DateTime.Now - h.CreateDateTime).TotalHours <= 24);*/ /* * DateTime date24HourAgo = DateTime.Now.AddHours(-24);//算出来一个24小时之前的时间 * return bs.GetAll().Count(h => h.Community.Region.CityId == cityId * && h.CreateDateTime<=date24HourAgo);*/ BaseService <HouseEntity> bs = new BaseService <HouseEntity>(ctx); return(bs.GetAll().Count(h => h.Community.Region.CityId == cityId && SqlFunctions.DateDiff("hh", h.CreateDateTime, DateTime.Now) <= 24)); } }
public long AddNew(string typeName, string name) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <IdNameEntity> bs = new BaseService <IdNameEntity>(ctx); var idnames = bs.GetAll().SingleOrDefault(i => i.TypeName == typeName); IdNameEntity idname = new IdNameEntity(); if (idnames == null) { idname.Name = name; idname.TypeName = typeName; } ctx.IdNames.Add(idname); ctx.SaveChanges(); return(idname.Id); } }
/// <summary> /// 为roleId增加权限,新增权限 /// </summary> /// <param name="roleId"></param> /// <param name="permIds"></param> public void AddPermIds(long roleId, long[] permIds) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <RoleEntity> roleBs = new Service.BaseService <Entities.RoleEntity>(ctx); var role = roleBs.GetById(roleId); if (role == null) { throw new ArgumentException("角色不存在" + roleId); } BaseService <PermissionEntity> perm = new Service.BaseService <Entities.PermissionEntity>(ctx); var perms = perm.GetAll().ToList().Where(p => permIds.Contains(p.Id)); foreach (var p in perms) { role.Permissions.Add(p); } ctx.SaveChanges(); } }
/// <summary> /// 新增城市 /// </summary> /// <param name="cityName"></param> /// <returns>新增Id</returns> public long AddNew(string cityName) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <CityEntity> bs = new BaseService <CityEntity>(ctx); bool exsits = bs.GetAll().Any(c => c.Name == cityName); //var exsit=bs.GetAll().Where(c => c.Name == cityName).Count()>0; //如果只是判断是否存在,用Any比用where().Count()的效率高 if (exsits) { throw new ArgumentException("城市已经存在"); } CityEntity city = new Entities.CityEntity(); city.Name = cityName; ctx.Cities.Add(city); ctx.SaveChanges(); return(city.Id); } }
/// <summary> /// 添加用户 /// </summary> /// <param name="phoneNum"></param> /// <param name="password"></param> /// <returns></returns> public long AddNew(string phoneNum, string password) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <UserEntity> bs = new BaseService <UserEntity>(ctx); bool exsits = bs.GetAll().Any(u => u.PhoneNum == phoneNum); if (exsits) { throw new ArgumentException("手机号已存在"); } UserEntity userEntity = new UserEntity(); userEntity.PhoneNum = phoneNum; string salt = Common.CommonHelper.GenerateCaptchaCode(5); userEntity.PasswordSalt = salt; userEntity.PasswordHash = Common.CommonHelper.CalMD5(salt + password); userEntity.LoginErrorTimes = 0; ctx.Users.Add(userEntity); ctx.SaveChanges(); return(userEntity.Id); } }
public CommunityDTO[] GetByRegionId(long RegionId) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <CommunityEntity> bs = new BaseService <CommunityEntity>(ctx); var community = bs.GetAll().Include(c => c.Region).AsNoTracking().Where(c => c.RegionId == RegionId); if (community == null) { return(null); } return(community.Select(c => new CommunityDTO() { CreateDateTime = c.CreateDateTime, Location = c.Location, BuildYear = c.BuildYear, RegionId = c.RegionId, Traffic = c.Traffic, Name = c.Name, Id = c.Id }).ToArray()); } }
/// <summary> /// 抢单 /// </summary> /// <param name="adminUserId"></param> /// <param name="houseAppointmentId"></param> /// <returns></returns> public bool Follow(long adminUserId, long houseAppointmentId) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <HouseAppointmentEntity> bs = new Service.BaseService <HouseAppointmentEntity>(ctx); var app = bs.GetById(houseAppointmentId); if (app == null) { throw new ArgumentException("不存在的订单Id"); } //FollowAdminUserId不为null,要么已经自己抢过,要么早早被别人抢了 if (app.FollowAdminUserId != null) { return(app.FollowAdminUserId == adminUserId); /* if (app.FollowAdminUserId==adminUserId) * { * return true; * } * else * { * return false; * } */ } //如果为null,说明有抢的机会 app.FollowAdminUserId = adminUserId; try { ctx.SaveChanges(); return(true); } //如果抛出DbUpdateConcurrencyException这个异常说明抢单失败 catch (DbUpdateConcurrencyException) { return(false); } } }
public long AddNew(long adminUserId, string message) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { //BaseService<AdminLogEntity> bs = new BaseService<AdminLogEntity>(ctx); /* ctx.AdminUserLogs.Add(new Entities.AdminLogEntity() { * Id = adminUserId, * Message = message * }); * ctx.SaveChanges(); */ AdminLogEntity log = new AdminLogEntity() { AdminUserId = adminUserId, Message = message }; ctx.AdminUserLogs.Add(log); ctx.SaveChanges(); return(log.Id); } }
public void SetValue(string name, string value) { using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <SettingEntity> bs = new Service.BaseService <SettingEntity>(ctx); /* * bool exsits = GetAll().Any(s => s.Name == name); * SettingEntity setting = new Entities.SettingEntity(); * if (exsits) * { * setting.Value = value; * } * else * { * setting.Name = name; * setting.Value = value; * } * ctx.SaveChanges(); */ var setting = bs.GetAll().SingleOrDefault(s => s.Name == name); if (setting != null) { ctx.Settings.Add(new SettingEntity() { Value = value }); } else { ctx.Settings.Add(new SettingEntity { Value = value, Name = name }); } ctx.SaveChanges(); } }
public AdminUserDTO[] GetAll() { /* using (ZSZDbContext ctx=new ZSZDbContext()) * { * BaseService<AdminUserEntity> bs = new BaseService<AdminUserEntity>(ctx); * List<AdminUserDTO> list = new List<AdminUserDTO>(); * AdminUserEntity adminUser = new AdminUserEntity(); * foreach (var admin in bs.GetAll()) * { * AdminUserDTO dto = new AdminUserDTO(); * dto.Email = admin.Email; * dto.Name = admin.Name; * dto.PhoneNum = admin.PhoneNum; * dto.LastLoginErrorDateTime = admin.LastLoginErrorDateTime; * dto.LoginErrorTimes = admin.LoginErrorTimes; * if (admin.City.Name!=null) * { * dto.CityName = admin.City.Name; * } * else * { * dto.CityName = "总部"; * } * dto.Id = admin.Id; * dto.CreateDateTime = admin.CreateDateTime; * list.Add(dto); * } * return list.ToArray(); * } */ using (ZSZDbContext ctx = new Service.ZSZDbContext()) { BaseService <AdminUserEntity> bs = new BaseService <AdminUserEntity>(ctx); return(bs.GetAll().Include(c => c.City).AsNoTracking().ToList().Select(a => ToDTO(a)).ToArray()); } }