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.
 
 
 
 
 
 

112 lines
3.4 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Learun.Application.AppMagager
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创 建:超级管理员
  12. /// 日 期:2018-06-26 10:32
  13. /// 描 述:我的常用移动应用
  14. /// </summary>
  15. public class MyFunctionService : RepositoryFactory
  16. {
  17. #region 构造函数和属性
  18. private string fieldSql;
  19. public MyFunctionService()
  20. {
  21. fieldSql = @"
  22. t.F_Id,
  23. t.F_UserId,
  24. t.F_FunctionId,
  25. t.F_Sort
  26. ";
  27. }
  28. #endregion
  29. #region 获取数据
  30. /// <summary>
  31. /// 获取列表数据
  32. /// </summary>
  33. /// <param name="userId">用户主键ID</param>
  34. /// <returns></returns>
  35. public IEnumerable<MyFunctionEntity> GetList(string userId)
  36. {
  37. try
  38. {
  39. var strSql = new StringBuilder();
  40. strSql.Append("SELECT ");
  41. strSql.Append(fieldSql);
  42. strSql.Append(" FROM LR_App_MyFunction t where t.F_UserId = @userId Order by t.F_Sort ");
  43. return this.BaseRepository().FindList<MyFunctionEntity>(strSql.ToString(), new { userId });
  44. }
  45. catch (Exception ex)
  46. {
  47. if (ex is ExceptionEx)
  48. {
  49. throw;
  50. }
  51. else
  52. {
  53. throw ExceptionEx.ThrowServiceException(ex);
  54. }
  55. }
  56. }
  57. #endregion
  58. #region 提交数据
  59. /// <summary>
  60. /// 保存实体数据(新增、修改)
  61. /// <param name="keyValue">主键</param>
  62. /// <summary>
  63. /// <returns></returns>
  64. public void SaveEntity(string userId, string strFunctionId)
  65. {
  66. var db = this.BaseRepository().BeginTrans();
  67. try
  68. {
  69. if (!string.IsNullOrEmpty(strFunctionId))
  70. {
  71. string[] functionIds = strFunctionId.Split(',');
  72. db.Delete<MyFunctionEntity>(t => t.F_UserId.Equals(userId));
  73. int num = 0;
  74. foreach (var functionId in functionIds)
  75. {
  76. MyFunctionEntity entity = new MyFunctionEntity();
  77. entity.Create();
  78. entity.F_UserId = userId;
  79. entity.F_FunctionId = functionId;
  80. entity.F_Sort = num;
  81. db.Insert(entity);
  82. num++;
  83. }
  84. }
  85. else
  86. {
  87. db.Delete<MyFunctionEntity>(t => t.F_UserId.Equals(userId));
  88. }
  89. db.Commit();
  90. }
  91. catch (Exception ex)
  92. {
  93. db.Rollback();
  94. if (ex is ExceptionEx)
  95. {
  96. throw;
  97. }
  98. else
  99. {
  100. throw ExceptionEx.ThrowServiceException(ex);
  101. }
  102. }
  103. }
  104. #endregion
  105. }
  106. }