HomeController.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using GreenTree.Nachtragsmanagement.Services.Configuration;
  7. using GreenTree.Nachtragsmanagement.Services.Test;
  8. using GreenTree.Nachtragsmanagement.Services.User;
  9. using GreenTree.Nachtragsmanagement.Web.Framework;
  10. using GreenTree.Nachtragsmanagement.Web.Models.Test;
  11. using Newtonsoft.Json;
  12. using GreenTree.Nachtragsmanagement.Core.Plugins;
  13. using GreenTree.Nachtragsmanagement.Core;
  14. using GreenTree.Nachtragsmanagement.Web.Framework.Authorization;
  15. using GreenTree.Nachtragsmanagement.Core.Authentication;
  16. using GreenTree.Nachtragsmanagement.Web.Models.Home;
  17. using GreenTree.Nachtragsmanagement.Core.Domain.User;
  18. namespace GreenTree.Nachtragsmanagement.Web.Controllers
  19. {
  20. [RoleAuthorize(false)]
  21. public class HomeController : Controller
  22. {
  23. private readonly IDbRelationService _dbRelationService;
  24. private readonly IConfigurationService _configurationService;
  25. private readonly IUserService _userService;
  26. private readonly IUserHelper _userHelper;
  27. private readonly IWebHelper _webHelper;
  28. public HomeController(
  29. IDbRelationService dbRelationService,
  30. IConfigurationService configurationService,
  31. IUserService userService,
  32. IUserHelper userHelper,
  33. IWebHelper webHelper)
  34. {
  35. _dbRelationService = dbRelationService;
  36. _configurationService = configurationService;
  37. _userService = userService;
  38. _userHelper = userHelper;
  39. _webHelper = webHelper;
  40. }
  41. // GET: Home
  42. public ActionResult Index()
  43. {
  44. var user = _userHelper.FromCookies();
  45. var userFunctions = user.Roles
  46. .SelectMany(s => s.Functions)
  47. .Where(f => f.IsMenuMember.HasValue && f.IsMenuMember.Value)
  48. .Distinct();
  49. var groups = userFunctions
  50. .GroupBy(g => g.GroupName)
  51. .Select(g => g.Key);
  52. var dict = new Dictionary<Function, List<Function>>();
  53. foreach (var group in groups)
  54. {
  55. var keyFunction = userFunctions
  56. .FirstOrDefault(f => f.Name == group);
  57. if (keyFunction == null)
  58. continue;
  59. var subFunctions = userFunctions
  60. .Where(f => f.GroupName == group)
  61. .ToList();
  62. dict.Add(keyFunction, subFunctions);
  63. }
  64. var model = new HomeModel
  65. {
  66. AvailableFunctions = dict
  67. };
  68. return View("~/Views/Home/Index.cshtml", model);
  69. }
  70. }
  71. }