OrganizeService.cs 4.6 KB

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