123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Bowin.Common.WebModels;
- using YLShipBuildLandMap.Entity;
- using YLShipBuildLandMap.Entity.ViewModel;
- using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
- using YLShipBuildLandMap.Services.SystemSetting;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
- {
- [Route("api/systemsetting/[controller]/[action]")]
- [ApiController]
- [Authorize]
- public class MenuController : ControllerBase
- {
- private IMenuService MenuService { get; set; }
- public MenuController(IMenuService menuService)
- {
- MenuService = menuService;
- }
- [HttpPost]
- public ResultMessage GetMenu()
- {
- try
- {
- var aa=HttpContext.User;
- var userID = LoginUser.Current.UserID;
- var menuList = MenuService.GetMenuByUserID(userID);
- var menuModelList = GetMenuModelsByMenuList(menuList);
- return ResultMessage.Success(menuModelList);
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- private List<MenuView> GetMenuModelsByMenuList(List<SysMenu> menuList, string parentID = null)
- {
- var result = menuList.Where(menu => menu.ParentMenuNo == parentID).Select(menu => new MenuView
- {
- MenuId = menu.MenuNo,
- Title = menu.MenuName,
- Url = menu.Url,
- //Url = ((menu.Url ?? "") != "") ?
- // ((menu.Url.StartsWith("http://") ? "" : "/") + menu.Url + (menu.Url.Contains("?") ? "&" : "?") + "MNU=" + menu.MenuNo)
- // : null,
- Icon = menu.Icon,
- IsVisible = menu.IsVisible ? 1 : 0
- }).ToList();
- result.ForEach(menu =>
- {
- menu.Childrens = GetMenuModelsByMenuList(menuList, menu.MenuId);
- });
- return result;
- }
- }
- }
|