纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.6 KiB

3 years ago
  1. using NFine.Code;
  2. using NFine.Domain.Entity.SystemManage;
  3. using NFine.Domain.IRepository.SystemManage;
  4. using NFine.Repository.SystemManage;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace NFine.Application.SystemManage
  8. {
  9. public class RoleApp
  10. {
  11. private IRoleRepository service = new RoleRepository();
  12. private ModuleApp moduleApp = new ModuleApp();
  13. private ModuleButtonApp moduleButtonApp = new ModuleButtonApp();
  14. public List<RoleEntity> GetList(string keyword = "")
  15. {
  16. var expression = ExtLinq.True<RoleEntity>();
  17. if (!string.IsNullOrEmpty(keyword))
  18. {
  19. expression = expression.And(t => t.F_FullName.Contains(keyword));
  20. expression = expression.Or(t => t.F_EnCode.Contains(keyword));
  21. }
  22. expression = expression.And(t => t.F_Category == 1);
  23. return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList();
  24. }
  25. public RoleEntity GetForm(string keyValue)
  26. {
  27. return service.FindEntity(keyValue);
  28. }
  29. public void DeleteForm(string keyValue)
  30. {
  31. service.DeleteForm(keyValue);
  32. }
  33. public void SubmitForm(RoleEntity roleEntity, string[] permissionIds, string keyValue)
  34. {
  35. if (!string.IsNullOrEmpty(keyValue))
  36. {
  37. roleEntity.F_Id = keyValue;
  38. }
  39. else
  40. {
  41. roleEntity.F_Id = Common.GuId();
  42. }
  43. var moduledata = moduleApp.GetList();
  44. var buttondata = moduleButtonApp.GetList();
  45. List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
  46. foreach (var itemId in permissionIds)
  47. {
  48. RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
  49. roleAuthorizeEntity.F_Id = Common.GuId();
  50. roleAuthorizeEntity.F_ObjectType = 1;
  51. roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
  52. roleAuthorizeEntity.F_ItemId = itemId;
  53. if (moduledata.Find(t => t.F_Id == itemId) != null)
  54. {
  55. roleAuthorizeEntity.F_ItemType = 1;
  56. }
  57. if (buttondata.Find(t => t.F_Id == itemId) != null)
  58. {
  59. roleAuthorizeEntity.F_ItemType = 2;
  60. }
  61. roleAuthorizeEntitys.Add(roleAuthorizeEntity);
  62. }
  63. service.SubmitForm(roleEntity, roleAuthorizeEntitys, keyValue);
  64. }
  65. }
  66. }