public async Task <IActionResult> Edit(long?id, long?AccountId) { if (id.HasValue) { //编辑 var model = await service.GetByIdAsync(id.Value); if (model == null) { throw new VinoDataNotFoundException("无法取得数据!"); } model.Account = await accountService.GetByIdAsync(model.AccountId); if (model.Account == null) { throw new VinoDataNotFoundException("数据出错!"); } //取得用户标签 ViewBag.UserTags = await wxUserTagService.GetListAsync(new WxUserTagSearch() { AccountId = model.AccountId }, "TagId asc"); ViewData["Mode"] = "Edit"; return(View(model)); } else { //新增 WxMenuDto dto = new WxMenuDto(); if (AccountId.HasValue) { dto.AccountId = AccountId.Value; dto.Account = await accountService.GetByIdAsync(AccountId.Value); if (dto.Account == null) { throw new VinoDataNotFoundException("参数出错!"); } } else { throw new VinoDataNotFoundException("参数出错!"); } //取得用户标签 ViewBag.UserTags = await wxUserTagService.GetListAsync(new WxUserTagSearch() { AccountId = dto.AccountId }, "TagId asc"); ViewData["Mode"] = "Add"; return(View(dto)); } }
/// <summary> /// 获取菜单树 /// </summary> /// <returns></returns> public async Task <List <WxMenuDto> > GetTreesAsync() { var dbmenus = await databaseFixture.Db.WxMenu.FindAllAsync(m => m.IsDel == 0); var dblist = dbmenus.OrderBy(m => m.Sort); List <WxMenuDto> list = new List <WxMenuDto>(); foreach (var item in dblist.Where(m => m.ParentId == 0)) { WxMenuDto tree = mapper.Map <WxMenu, WxMenuDto>(item); tree.Children = mapper.Map <List <WxMenu>, List <WxMenuDto> >(dblist.Where(m => m.ParentId == item.Id).ToList()); list.Add(tree); } return(list); }
public async Task OnGetAsync(long?id, long?AccountId) { if (id.HasValue) { Dto = await _service.GetByIdAsync(id.Value); if (Dto == null) { throw new KuDataNotFoundException(); } Dto.Account = await _accountService.GetByIdAsync(Dto.AccountId); if (Dto.Account == null) { throw new KuDataNotFoundException("数据出错!"); } ViewData["Mode"] = "Edit"; } else { Dto = new WxMenuDto(); if (AccountId.HasValue) { Dto.AccountId = AccountId.Value; Dto.Account = await _accountService.GetByIdAsync(AccountId.Value); if (Dto.Account == null) { throw new KuDataNotFoundException("参数出错!"); } } else { throw new KuDataNotFoundException("参数出错!"); } ViewData["Mode"] = "Add"; } //取得用户标签 UserTags = await _userTagService.GetListAsync(new WxUserTagSearch() { AccountId = Dto.AccountId }, new { TagId = "asc" }); }
private SingleButton BuildMenu(WxMenuDto menu) { switch (menu.BindType) { case BindType.Key: return(new SingleClickButton { name = menu.Name, key = menu.Id.ToString() }); case BindType.Topic: case BindType.HomePage: case BindType.Url: return(new SingleViewButton { name = menu.Name, url = menu.Url }); } return(new SingleClickButton { name = menu.Name, key = "None" }); }
public async Task <IActionResult> Save(WxMenuDto model) { await service.SaveAsync(model); return(JsonData(true)); }