Пример #1
0
        public ActionResult Edit(string id)
        {
            var menu = _repository.Get(p => p.Id == id);

            var model = new WxMenuModel();

            model.Id             = menu.Id;
            model.Bind           = menu.Bind;
            model.BindTopic      = menu.Content;
            model.BindValue      = menu.ReplyId;
            model.Name           = menu.Name;
            model.CreateDateTime = menu.CreateDateTime;
            model.Url            = menu.Content;
            model.Sequence       = menu.Sequence;

            model.ParentMenu = _repository.Get(x => x.Id == menu.ParentId);

            model.BindTypes = SelectListItems.FromEnum(menu.Bind).ToArray();

            model.Keywords = _wxReplyRepository.Query()
                             .Select(x => new { x.Sequence, x.Id, x.Content })
                             .OrderByDescending(x => x.Sequence)
                             .ToList()
                             .Select(x => new SelectListItem
            {
                Value    = x.Id,
                Text     = x.Content,
                Selected = x.Id == menu.Content
            }).ToArray();

            model.Topics = new SelectListItem[] { };

            return(View(model));
        }
Пример #2
0
        public ActionResult Add(BindType?bind, string parentId)
        {
            var model = new WxMenuModel()
            {
                Bind     = bind.GetValueOrDefault(),
                ParentId = parentId
            };

            model.BindTypes = SelectListItems.FromEnum(bind.GetValueOrDefault()).ToArray();

            model.Keywords = _wxReplyRepository.Query()
                             .Select(x => new { x.Sequence, x.Id, x.Content })
                             .OrderByDescending(x => x.Sequence)
                             .ToList()
                             .Select(x => new SelectListItem {
                Value = x.Id, Text = x.Content
            }).ToArray();

            model.Topics = new SelectListItem[] { };

            return(View(model));
        }
Пример #3
0
        public ActionResult Add(WxMenuModel model)
        {
            if (ModelState.IsValid)
            {
                var isOk = RunWithCatch((ms) =>
                {
                    var entity      = new WxMenu();
                    entity.Name     = model.Name;
                    entity.Content  = model.BindValue;
                    entity.Bind     = model.Bind;
                    entity.Type     = model.BindType;
                    entity.ParentId = model.ParentId;
                    entity.Sequence = model.Sequence;

                    BindType bindType = model.Bind;
                    switch (bindType)
                    {
                    case BindType.Key:
                        entity.ReplyId = model.BindValue;
                        break;

                    case BindType.Topic:
                        entity.Content = model.BindTopic;
                        break;

                    default:
                        if (bindType == BindType.Url)
                        {
                            entity.Content = model.Url;
                        }
                        break;
                    }
                    entity.Client = MenuClient.Weixin;
                    entity.Type   = "click";
                    if (entity.ParentId.IsBlank())
                    {
                        entity.Type = "view";
                    }
                    else if (entity.Bind == BindType.None)
                    {
                        ms.AddModelError("Bind", "二级菜单必须绑定一个对象");
                        return(false);
                    }

                    _repository.Insert(entity);
                    return(true);
                });

                if (isOk)
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                model.BindTypes = SelectListItems.FromEnum(model.Bind).ToArray();

                model.Keywords = _wxReplyRepository.Query()
                                 .Select(x => new { x.Sequence, x.Id, x.Content })
                                 .OrderByDescending(x => x.Sequence)
                                 .ToList()
                                 .Select(x => new SelectListItem
                {
                    Value    = x.Id,
                    Text     = x.Content,
                    Selected = model.BindValue == x.Id
                }).ToArray();

                model.Topics = new SelectListItem[] { };
            }
            return(View(model));
        }