DepartmentService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using LeaRun.Application.Entity.BaseManage;
  2. using LeaRun.Application.IService.BaseManage;
  3. using LeaRun.Data;
  4. using LeaRun.Data.Repository;
  5. using LeaRun.Util.Extension;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data.Common;
  9. using System.Linq;
  10. using System.Text;
  11. using LeaRun.Application.IService.AuthorizeManage;
  12. using LeaRun.Application.Service.AuthorizeManage;
  13. namespace LeaRun.Application.Service.BaseManage
  14. {
  15. /// <summary>
  16. /// 版 本 6.1
  17. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  18. /// 创建人:佘赐雄
  19. /// 日 期:2015.11.02 14:27
  20. /// 描 述:部门管理
  21. /// </summary>
  22. public class DepartmentService : RepositoryFactory<DepartmentEntity>, IDepartmentService
  23. {
  24. private IAuthorizeService<DepartmentEntity> iauthorizeservice = new AuthorizeService<DepartmentEntity>();
  25. #region 获取数据
  26. /// <summary>
  27. /// 部门列表
  28. /// </summary>
  29. /// <returns></returns>
  30. public IEnumerable<DepartmentEntity> GetList()
  31. {
  32. return this.BaseRepository().IQueryable().OrderByDescending(t => t.CreateDate).ToList();
  33. }
  34. /// <summary>
  35. /// 部门实体
  36. /// </summary>
  37. /// <param name="keyValue">主键值</param>
  38. /// <returns></returns>
  39. public DepartmentEntity GetEntity(string keyValue)
  40. {
  41. return this.BaseRepository().FindEntity(keyValue);
  42. }
  43. #endregion
  44. #region 验证数据
  45. /// <summary>
  46. /// 部门编号不能重复
  47. /// </summary>
  48. /// <param name="enCode">编号</param>
  49. /// <param name="keyValue">主键</param>
  50. /// <returns></returns>
  51. public bool ExistEnCode(string enCode, string keyValue)
  52. {
  53. var expression = LinqExtensions.True<DepartmentEntity>();
  54. expression = expression.And(t => t.EnCode == enCode);
  55. if (!string.IsNullOrEmpty(keyValue))
  56. {
  57. expression = expression.And(t => t.DepartmentId != keyValue);
  58. }
  59. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  60. }
  61. /// <summary>
  62. /// 部门名称不能重复
  63. /// </summary>
  64. /// <param name="fullName">名称</param>
  65. /// <param name="keyValue">主键</param>
  66. /// <returns></returns>
  67. public bool ExistFullName(string fullName, string keyValue)
  68. {
  69. var expression = LinqExtensions.True<DepartmentEntity>();
  70. expression = expression.And(t => t.FullName == fullName);
  71. if (!string.IsNullOrEmpty(keyValue))
  72. {
  73. expression = expression.And(t => t.DepartmentId != keyValue);
  74. }
  75. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  76. }
  77. #endregion
  78. #region 提交数据
  79. /// <summary>
  80. /// 删除部门
  81. /// </summary>
  82. /// <param name="keyValue">主键</param>
  83. public void RemoveForm(string keyValue)
  84. {
  85. int count = this.BaseRepository().IQueryable(t => t.ParentId == keyValue).Count();
  86. if (count > 0)
  87. {
  88. throw new Exception("当前所选数据有子节点数据!");
  89. }
  90. this.BaseRepository().Delete(keyValue);
  91. }
  92. /// <summary>
  93. /// 保存部门表单(新增、修改)
  94. /// </summary>
  95. /// <param name="keyValue">主键值</param>
  96. /// <param name="departmentEntity">机构实体</param>
  97. /// <returns></returns>
  98. public void SaveForm(string keyValue, DepartmentEntity departmentEntity)
  99. {
  100. if (!string.IsNullOrEmpty(keyValue))
  101. {
  102. departmentEntity.Modify(keyValue);
  103. this.BaseRepository().Update(departmentEntity);
  104. }
  105. else
  106. {
  107. departmentEntity.Create();
  108. this.BaseRepository().Insert(departmentEntity);
  109. }
  110. }
  111. #endregion
  112. }
  113. }