/// <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); } } }
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(); } }
public IdNameDTO GetById(long id) { using (RhDbContext ctx = new RhDbContext()) { CommonService <IdNameEntity> cs = new CommonService <IdNameEntity>(ctx); return(Entity2DTO(cs.GetById(id))); } }
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)); } }
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)); } }
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(); } }
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)); } }
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)); } }
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(); } }
public CityDTO GetById(long id) { using (RhDbContext ctx = new RhDbContext()) { CommonService <CityEntity> commonService = new CommonService <CityEntity>(ctx); var cityEntity = commonService.GetById(id); if (cityEntity == null) { return(null); } return(Entity2DTO(cityEntity)); } }
public RoleDTO[] GetByAdminUserId(long adminUserId) { using (RhDbContext ctx = new RhDbContext()) { CommonService <AdminUserEntity> cs = new CommonService <AdminUserEntity>(ctx); var adminUser = cs.GetById(adminUserId); if (adminUser == null) { throw new ArgumentException("此用户不存在"); } return(adminUser.Roles.ToList().Select(a => Entity2DTO(a)).ToArray()); } }
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(); } }
public PermissionDTO[] GetByRoleId(long roleId) { using (RhDbContext ctx = new RhDbContext()) { CommonService <RoleEntity> roleCs = new CommonService <RoleEntity>(ctx); var role = roleCs.GetById(roleId); if (role == null) { throw new ArgumentException("该角色不存在"); } return(role.Permissions.ToList().Select(a => Entity2DTO(a)).ToArray()); } }
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(); } }
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(); } }
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(); } }
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(); } }
public HousePicDTO[] GetPics(long houseId) { using (RhDbContext ctx = new RhDbContext()) { CommonService <HouseEntity> cs = new CommonService <HouseEntity>(ctx); HouseEntity house = cs.GetById(houseId); //妈的这里忘了判断pic是否deleted的情况 return(house.HousePics.Where(p => p.IsDeleted == false).Select(p => new HousePicDTO { HouseId = p.HouseId, Url = p.Url, ThumbUrl = p.ThumbUrl, Id = p.Id, CreateDateTime = p.CreateDateTime }).ToArray()); } }
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(); } }
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(); } }
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(); } }