コード例 #1
0
        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));
        }
コード例 #2
0
        public ActionResult AddNews()
        {
            CompanyNoticeModel model = new CompanyNoticeModel();

            model.PublishedFlag = false;
            model.IsOpen        = false;
            return(View(model));
        }
コード例 #3
0
        public ActionResult EditNews(int id)
        {
            ICompanyPostBLL postBll = BLLFactory <ICompanyPostBLL> .GetBLL("CompanyPostBLL");

            var post = postBll.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            if (post != null)
            {
                CompanyNoticeModel postModel = new CompanyNoticeModel();
                postModel.PostId        = post.Id;
                postModel.Title         = post.Title;
                postModel.Content       = post.Content;
                postModel.PublishedFlag = post.PublishStatus == 1;
                postModel.IsOpen        = post.IsOpen == 1;
                return(View(postModel));
            }
            else
            {
                return(RedirectToAction("NewsList"));
            }
        }