/// <summary> /// 删除小区,删除其角色和用户 /// </summary> /// <param name="place">小区实体对象</param> /// <returns></returns> public bool DeletePlace(T_PropertyPlace place) { //使用事务进行数据库操作 using (var tran = this.nContext.Database.BeginTransaction()) { try { //修改用户为删除标识 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); var users = propertyUserBll.GetList(u => u.PropertyPlaceId == place.Id && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT).ToList(); foreach (var user in users) { user.DelFlag = ConstantParam.DEL_FLAG_DELETE; propertyUserBll.Update(user); } //改为删除标识 base.Update(place); //提交事务 tran.Commit(); } catch { tran.Rollback(); return(false); } } return(true); }
public ActionResult EditNews(CompanyNoticeModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyPostBLL postBll = BLLFactory <ICompanyPostBLL> .GetBLL("CompanyPostBLL"); T_CompanyPost newPost = postBll.GetEntity(m => m.Id == model.PostId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (newPost != null) { newPost.Title = model.Title; newPost.Content = model.Content; newPost.PublishStatus = model.PublishedFlag ? 1 : 0; newPost.IsOpen = model.IsOpen ? 1 : 0; } ; if (model.PublishedFlag) { newPost.PublishedTime = DateTime.Now; } // 保存到数据库,如果修改成功 if (postBll.Update(newPost)) { //如果已发布并公开 if (model.PublishedFlag && model.IsOpen) { //推送给物业客户端 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); var PropertyUserIds = userBll.GetList(u => u.PropertyPlace.CompanyId == newPost.CompanyId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT).Select(u => u.Id); if (PropertyUserIds != null) { PropertyUserIds = PropertyUserIds.ToList(); } IPropertyUserPushBLL propertyUserPushBLL = BLLFactory <IPropertyUserPushBLL> .GetBLL("PropertyUserPushBLL"); var propertyRegistrationIds = propertyUserPushBLL.GetList(p => PropertyUserIds.Contains(p.UserId)).Select(p => p.RegistrationId).ToArray(); bool flag = PropertyUtils.SendPush("总公司新闻公告", model.Title, ConstantParam.MOBILE_TYPE_PROPERTY, propertyRegistrationIds); if (!flag) { jm.Msg = "推送发生异常"; } } //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "新闻公告编辑失败"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取本小区物业用户列表 /// </summary> /// <param name="currentPlaceId">物业小区ID</param> /// <returns>物业用户列表</returns> private List <SelectListItem> GetUserList(int currentPlaceId) { var sortModel = this.SettingSorting("Id", false); //调用BLL层获取物业用户列表 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); var pointList = userBll.GetList(c => c.PropertyPlaceId == currentPlaceId && c.DelFlag == ConstantParam.DEL_FLAG_DEFAULT, sortModel.SortName, sortModel.IsAsc).ToList(); //转换为下拉列表并返回 return(pointList.Select(c => new SelectListItem() { Text = string.IsNullOrEmpty(c.TrueName) ? c.UserName : (pointList.Count(p => p.TrueName == c.TrueName) > 1 ? c.TrueName + "(" + c.UserName + ")" : c.TrueName), Value = c.Id.ToString(), Selected = false, }).ToList()); }
public ApiResultModel GetDisposerList([FromUri] TokenModel model) { ApiResultModel resultModel = new ApiResultModel(); try { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //获取物业用户列表 Expression <Func <T_PropertyUser, bool> > where = u => u.PropertyPlaceId == user.PropertyPlaceId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT; var userList = userBll.GetList(where, "Id", false).ToList(); resultModel.result = userList.Select(u => new { UserId = u.Id, Name = string.IsNullOrEmpty(u.TrueName) ? u.UserName : (userList.Count(p => p.TrueName == u.TrueName) > 1 ? u.TrueName + "(" + u.UserName + ")" : u.TrueName) }); } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ActionResult AddNews(NewsNoticeModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { var sessionModel = GetSessionModel(); IPostBLL postBll = BLLFactory <IPostBLL> .GetBLL("PostBLL"); T_Post newPost = new T_Post() { Title = model.Title, Content = model.Content, PropertyPlaceId = sessionModel.PropertyPlaceId.Value, SubmitUserId = sessionModel.UserID, SubmitTime = DateTime.Now.ToLocalTime(), PublishedFlag = model.PublishedFlag ? 1 : 0, PublishedTime = DateTime.Now.ToLocalTime() }; // 保存到数据库 postBll.Save(newPost); // 若选中“发布选项”则即时推送 if (model.PublishedFlag) { // 公告推送 //推送给业主客户端 IPropertyPlaceBLL placeBll = BLLFactory <IPropertyPlaceBLL> .GetBLL("PropertyPlaceBLL"); var userIds = placeBll.GetEntity(p => p.Id == newPost.PropertyPlaceId).UserPlaces.Select(m => m.UserId); if (userIds != null) { userIds = userIds.ToList(); } IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL"); var registrationIds = userPushBLL.GetList(p => userIds.Contains(p.UserId)).Select(p => p.RegistrationId).ToArray(); bool flag = PropertyUtils.SendPush("新闻公告", model.Title, ConstantParam.MOBILE_TYPE_OWNER, registrationIds); //推送给物业客户端 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); var PropertyUserIds = userBll.GetList(u => u.PropertyPlaceId == newPost.PropertyPlaceId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT).Select(u => u.Id); if (PropertyUserIds != null) { PropertyUserIds = PropertyUserIds.ToList(); } IPropertyUserPushBLL propertyUserPushBLL = BLLFactory <IPropertyUserPushBLL> .GetBLL("PropertyUserPushBLL"); var propertyRegistrationIds = propertyUserPushBLL.GetList(p => PropertyUserIds.Contains(p.UserId)).Select(p => p.RegistrationId).ToArray(); bool flag1 = PropertyUtils.SendPush("新闻公告", model.Title, ConstantParam.MOBILE_TYPE_PROPERTY, propertyRegistrationIds); if (!flag || !flag1) { jm.Msg = "推送发生异常"; } } //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }