Esempio n. 1
0
        public ActionResult EditSingleTextImageReply(string id)
        {
            var reply     = _svc.GetReply(id);
            var firstNews = _svc.GetNewsReplyInfo(reply.Id).FirstOrDefault();

            if (firstNews == null)
            {
                firstNews = new NewsMsgInfo();
            }

            AddNewsMsgInfo model = new AddNewsMsgInfo();

            model.Reply = _mapper.Map <NewsReplyInfo>(reply);

            model.Content     = firstNews.Content;
            model.Description = firstNews.Description;
            model.Id          = firstNews.Id;
            model.Title       = firstNews.Title;
            model.Url         = firstNews.Url;
            model.PicUrl      = firstNews.PicUrl;

            // allow login reply
            model.AllowSubscribeReply = getCanChangeSubscribeReply();
            model.AllowNoMatchReply   = getCanChangeNoMatchReply();

            model.Setup();

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult EditSingleTextImageReply(AddNewsMsgInfo model)
        {
            if (ModelState.IsValid)
            {
                var isOk = RunWithCatch((r) =>
                {
                    var keys = model.Reply?.Keys;
                    if ((!string.IsNullOrEmpty(keys) && !string.IsNullOrEmpty(model.Description)) && !string.IsNullOrEmpty(model.PicUrl))
                    {
                        if (!string.IsNullOrEmpty(keys) && _wxReplyRepository.Query().Any(x => x.Id != model.Id && x.Keys == keys))
                        {
                            r.AddModelError("Keys", "关键字重复!");
                        }
                        else
                        {
                            WxReply reply = _wxReplyRepository.Get(x => x.Id == model.Id);

                            if (model.KeyReply && !string.IsNullOrWhiteSpace(keys))
                            {
                                reply.Keys = keys.Trim();
                            }
                            if (model.KeyReply && string.IsNullOrWhiteSpace(keys))
                            {
                                r.AddModelError("Reply.Keys", "你选择了关键字回复,必须填写关键字!");
                            }
                            else
                            {
                                reply.MatchType   = model.Reply.MatchType;
                                reply.MessageType = MessageType.News;
                                if (model.KeyReply)
                                {
                                    reply.ReplyType |= ReplyType.Keys;
                                }
                                if (model.SubscribeReply)
                                {
                                    reply.ReplyType |= ReplyType.Subscribe;
                                }
                                if (model.NoMatchReply)
                                {
                                    reply.ReplyType |= ReplyType.NoMatch;
                                }

                                if (!model.SubscribeReply &&
                                    !model.NoMatchReply &&
                                    !model.KeyReply)
                                {
                                    reply.ReplyType = ReplyType.None;
                                }

                                if (reply.ReplyType == ReplyType.None)
                                {
                                    r.AddModelError("Reply.ReplyType", "请选择回复类型");
                                }
                                else if (string.IsNullOrEmpty(model.Title))
                                {
                                    r.AddModelError("Title", "请输入标题");
                                }
                                else if (string.IsNullOrEmpty(model.PicUrl))
                                {
                                    r.AddModelError("PicUrl", "请上传封面图");
                                }
                                else if (string.IsNullOrEmpty(model.Content) && string.IsNullOrEmpty(model.Url))
                                {
                                    r.AddModelError("Url", "请输入内容或自定义链接");
                                }
                                else
                                {
                                    if (_wxReplyRepository.Update(reply, (b) => new object[] { reply.Id }))
                                    {
                                        WxMessage item   = _wxMsgRepository.Get(x => x.ReplyId == reply.Id);
                                        item.Title       = model.Title;
                                        item.Url         = model.Url;
                                        item.ImageUrl    = model.PicUrl;
                                        item.Content     = model.Content;
                                        item.Description = model.Description;

                                        // insert messags
                                        return(_wxMsgRepository.Update(item, e => new object[] { item.Id }));
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }

                    return(false);
                });

                if (isOk)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View(model));
        }
Esempio n. 3
0
        public ActionResult AddSingleTextImageReply(AddNewsMsgInfo model)
        {
            if (ModelState.IsValid)
            {
                var isOk = RunWithCatch((r) =>
                {
                    var keys = model.Reply?.Keys;
                    if ((!string.IsNullOrEmpty(keys) && !string.IsNullOrEmpty(model.Description)) && !string.IsNullOrEmpty(model.PicUrl))
                    {
                        if (!string.IsNullOrEmpty(keys) && _wxReplyRepository.Query().Any(x => x.Keys == keys))
                        {
                            r.AddModelError("Keys", "关键字重复!");
                        }
                        else
                        {
                            WxReply reply = new WxReply()
                            {
                                IsDisabled = !model.Reply.IsDisable,
                            };

                            if (model.KeyReply && !string.IsNullOrWhiteSpace(keys))
                            {
                                reply.Keys = keys.Trim();
                            }
                            if (model.KeyReply && string.IsNullOrWhiteSpace(keys))
                            {
                                r.AddModelError("Reply.Keys", "你选择了关键字回复,必须填写关键字!");
                            }
                            else
                            {
                                reply.MatchType   = model.Reply.MatchType;
                                reply.MessageType = MessageType.News;
                                if (model.KeyReply)
                                {
                                    reply.ReplyType |= ReplyType.Keys;
                                }
                                if (model.SubscribeReply)
                                {
                                    reply.ReplyType |= ReplyType.Subscribe;
                                }
                                if (model.NoMatchReply)
                                {
                                    reply.ReplyType |= ReplyType.NoMatch;
                                }
                                if (reply.ReplyType == ReplyType.None)
                                {
                                    r.AddModelError("Reply.ReplyType", "请选择回复类型");
                                }
                                else if (string.IsNullOrEmpty(model.Title))
                                {
                                    r.AddModelError("Title", "请输入标题");
                                }
                                else if (string.IsNullOrEmpty(model.PicUrl))
                                {
                                    r.AddModelError("PicUrl", "请上传封面图");
                                }
                                else if (string.IsNullOrEmpty(model.Content) && string.IsNullOrEmpty(model.Url))
                                {
                                    r.AddModelError("Url", "请输入内容或自定义链接");
                                }
                                else
                                {
                                    if (_wxReplyRepository.Insert(reply))
                                    {
                                        if (model.Reply == null)
                                        {
                                            model.Reply = new NewsReplyInfo()
                                            {
                                                Id = reply.Id
                                            };
                                        }

                                        model.Reply.Id = reply.Id;
                                        WxMessage item = _mapper.Map <WxMessage>(model);
                                        // insert messags
                                        return(_wxMsgRepository.Insert(item));
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }

                    return(true);
                });

                if (isOk)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View(model));
        }