MenuController.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Bowin.Common.WebModels;
  6. using YLShipBuildLandMap.Entity;
  7. using YLShipBuildLandMap.Entity.ViewModel;
  8. using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
  9. using YLShipBuildLandMap.Services.SystemSetting;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.AspNetCore.Mvc;
  13. namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
  14. {
  15. [Route("api/systemsetting/[controller]/[action]")]
  16. [ApiController]
  17. [Authorize]
  18. public class MenuController : ControllerBase
  19. {
  20. private IMenuService MenuService { get; set; }
  21. public MenuController(IMenuService menuService)
  22. {
  23. MenuService = menuService;
  24. }
  25. [HttpPost]
  26. public ResultMessage GetMenu()
  27. {
  28. try
  29. {
  30. var aa=HttpContext.User;
  31. var userID = LoginUser.Current.UserID;
  32. var menuList = MenuService.GetMenuByUserID(userID);
  33. var menuModelList = GetMenuModelsByMenuList(menuList);
  34. return ResultMessage.Success(menuModelList);
  35. }
  36. catch (Exception ex)
  37. {
  38. return ResultMessage.GetError(ex.Message);
  39. }
  40. }
  41. private List<MenuView> GetMenuModelsByMenuList(List<SysMenu> menuList, string parentID = null)
  42. {
  43. var result = menuList.Where(menu => menu.ParentMenuNo == parentID).Select(menu => new MenuView
  44. {
  45. MenuId = menu.MenuNo,
  46. Title = menu.MenuName,
  47. Url = menu.Url,
  48. //Url = ((menu.Url ?? "") != "") ?
  49. // ((menu.Url.StartsWith("http://") ? "" : "/") + menu.Url + (menu.Url.Contains("?") ? "&" : "?") + "MNU=" + menu.MenuNo)
  50. // : null,
  51. Icon = menu.Icon,
  52. IsVisible = menu.IsVisible ? 1 : 0
  53. }).ToList();
  54. result.ForEach(menu =>
  55. {
  56. menu.Childrens = GetMenuModelsByMenuList(menuList, menu.MenuId);
  57. });
  58. return result;
  59. }
  60. }
  61. }