示例#1
0
        public ActionResult AddSingleTextReply(TextReplyInfo model)
        {
            if (ModelState.IsValid)
            {
                var isOK = RunWithCatch(r =>
                {
                    var key = model.Keys.Trim();
                    if (!string.IsNullOrEmpty(model.Keys) && _wxReplyRepository.Query().Any(x => x.Keys == key))
                    {
                        r.AddModelError("Keys", "关键字重复!");
                    }
                    else
                    {
                        WxReply info;
                        info             = new WxReply();
                        info.MessageType = MessageType.Text;
                        info.IsDisabled  = model.IsDisable;
                        if (model.ReplyType == ReplyType.Keys && !string.IsNullOrWhiteSpace(model.Keys))
                        {
                            info.Keys = model.Keys.Trim();
                        }
                        info.Content   = model.Text.Trim();
                        info.MatchType = model.MatchType;
                        if (model.ReplyType == ReplyType.Keys)
                        {
                            info.ReplyType |= ReplyType.Keys;
                        }
                        if (model.ReplyType == ReplyType.Subscribe)
                        {
                            info.ReplyType |= ReplyType.Subscribe;
                        }
                        if (model.ReplyType == ReplyType.NoMatch)
                        {
                            info.ReplyType |= ReplyType.NoMatch;
                        }
                        if (info.ReplyType == ReplyType.None)
                        {
                            r.AddModelError("ReplyType", "请选择回复类型");
                        }
                        else if (_wxReplyRepository.Insert(info))
                        {
                            return(true);
                        }
                        else
                        {
                            r.AddModelError("", new Exception("添加失败"));
                        }
                    }
                    return(false);
                });

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

            return(View(model));
        }
示例#2
0
        public IList <ReplyInfo> GetReplies(ReplyType type)
        {
            var replies = _replyRepo.Query().Where(x => x.ReplyType == type).ToList();

            List <ReplyInfo> list = new List <ReplyInfo>();

            foreach (var p in replies)
            {
                TextReplyInfo info3;
                WxReply       info = p;
                switch (info.MessageType)
                {
                default:
                case MessageType.Text:
                    info3 = new TextReplyInfo()
                    {
                        ActivityId   = p.ActivityId,
                        Id           = p.Id,
                        Text         = p.Content,
                        IsDisable    = p.IsDisabled,
                        Keys         = p.Keys,
                        LastEditDate = p.LastModified,
                        LastEditor   = p.LastModifier,
                        MatchType    = p.MatchType,
                        MessageType  = p.MessageType,
                        ReplyType    = p.ReplyType,
                    };
                    list.Add(info3);
                    break;

                case MessageType.News:
                case MessageType.List:
                {
                    NewsReplyInfo item = new Models.NewsReplyInfo()
                    {
                        ActivityId   = p.ActivityId,
                        Id           = p.Id,
                        IsDisable    = p.IsDisabled,
                        Keys         = p.Keys,
                        LastEditDate = p.LastModified,
                        LastEditor   = p.LastModifier,
                        MatchType    = p.MatchType,
                        MessageType  = p.MessageType,
                        ReplyType    = p.ReplyType,
                    };

                    item.NewsMsg = this.GetNewsReplyInfo(item.Id);
                    list.Add(item);
                    break;
                }
                }
            }

            return(list);
        }
示例#3
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));
        }
示例#4
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));
        }