NewsService.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using Lottomat.Application.Entity.PublicInfoManage;
  3. using Lottomat.Application.IService.PublicInfoManage;
  4. using Lottomat.Data.Repository;
  5. using Lottomat.Util;
  6. using Lottomat.Util.Extension;
  7. using Lottomat.Util.WebControl;
  8. using System.Collections.Generic;
  9. using System.Linq.Expressions;
  10. using Newtonsoft.Json.Linq;
  11. namespace Lottomat.Application.Service.PublicInfoManage
  12. {
  13. /// <summary>
  14. /// 版 本 1.0
  15. /// Copyright (c) 2016-2017
  16. /// 创建人:赵轶
  17. /// 日 期:2015.12.7 16:40
  18. /// 描 述:新闻中心
  19. /// </summary>
  20. public class NewsService : RepositoryFactory<NewsEntity>, INewsService
  21. {
  22. #region 获取数据
  23. /// <summary>
  24. /// 新闻列表
  25. /// </summary>
  26. /// <param name="pagination">分页</param>
  27. /// <param name="queryJson">查询参数</param>
  28. /// <returns></returns>
  29. public IEnumerable<NewsEntity> GetPageList(Pagination pagination, string queryJson)
  30. {
  31. var expression = LinqExtensions.True<NewsEntity>();
  32. JObject queryParam = queryJson.ToJObject();
  33. if (queryParam != null)
  34. {
  35. if (!queryParam["FullHead"].IsEmpty())
  36. {
  37. string FullHead = queryParam["FullHead"].ToString();
  38. expression = expression.And(t => t.FullHead.Contains(FullHead));
  39. }
  40. if (!queryParam["Category"].IsEmpty())
  41. {
  42. string Category = queryParam["Category"].ToString();
  43. expression = expression.And(t => t.Category == Category);
  44. }
  45. if (!queryParam["CategoryId"].IsEmpty())
  46. {
  47. string CategoryId = queryParam["CategoryId"].ToString();
  48. expression = expression.And(t => t.CategoryId == CategoryId);
  49. }
  50. }
  51. expression = expression.And(t => t.TypeId == 1 && t.IsDelete == false);
  52. return this.BaseRepository().FindList(expression, pagination);
  53. }
  54. /// <summary>
  55. ///
  56. /// </summary>
  57. /// <param name="condition"></param>
  58. /// <param name="pagination"></param>
  59. /// <returns></returns>
  60. public IEnumerable<NewsEntity> GetPageList(Expression<Func<NewsEntity, bool>> condition, Pagination pagination)
  61. {
  62. //var expression = LinqExtensions.True<NewsEntity>();
  63. //expression = expression.And(t => t.TypeId == 1 && t.IsDelete == false);
  64. //expression = expression.And(condition);
  65. return this.BaseRepository().FindList(condition, pagination);
  66. }
  67. /// <summary>
  68. /// 新闻实体
  69. /// </summary>
  70. /// <param name="keyValue">主键值</param>
  71. /// <returns></returns>
  72. public NewsEntity GetEntity(string keyValue)
  73. {
  74. return this.BaseRepository().FindEntity(keyValue);
  75. }
  76. public NewsEntity GetEntity(Expression<Func<NewsEntity, bool>> condition)
  77. {
  78. return this.BaseRepository().FindEntity(condition);
  79. }
  80. /// <summary>
  81. /// 获取所有数据
  82. /// </summary>
  83. /// <param name="condition"></param>
  84. /// <returns></returns>
  85. public IEnumerable<NewsEntity> GetList(Expression<Func<NewsEntity, bool>> condition)
  86. {
  87. return this.BaseRepository().FindList(condition);
  88. }
  89. /// <summary>
  90. /// 批量修改
  91. /// </summary>
  92. /// <param name="modelModifyProps">要修改的列及修改后列的值集合</param>
  93. /// <param name="where">修改的条件</param>
  94. /// <param name="paramModifyStrings">修改列的名称的集合</param>
  95. /// <returns>返回受影响行数</returns>
  96. public int Modify(NewsEntity modelModifyProps, Expression<Func<NewsEntity, bool>> where, params string[] paramModifyStrings)
  97. {
  98. return this.BaseRepository().Modify(modelModifyProps, where, paramModifyStrings);
  99. }
  100. public IEnumerable<T> FindList<T>(Expression<Func<T, bool>> condition, string orderField, bool isAsc, int pageSize, int pageIndex,
  101. out int total) where T : class, new()
  102. {
  103. return this.BaseRepository().FindList(condition, orderField, isAsc, pageSize, pageIndex, out total);
  104. }
  105. #endregion
  106. #region 提交数据
  107. /// <summary>
  108. /// 删除新闻
  109. /// </summary>
  110. /// <param name="keyValue">主键</param>
  111. public void RemoveForm(string keyValue)
  112. {
  113. this.BaseRepository().Delete(keyValue);
  114. }
  115. /// <summary>
  116. /// 保存新闻表单(新增、修改)
  117. /// </summary>
  118. /// <param name="keyValue">主键值</param>
  119. /// <param name="newsEntity">新闻实体</param>
  120. /// <returns></returns>
  121. public void SaveForm(string keyValue, NewsEntity newsEntity)
  122. {
  123. if (!string.IsNullOrEmpty(keyValue))
  124. {
  125. newsEntity.Modify(keyValue);
  126. newsEntity.TypeId = 1;
  127. this.BaseRepository().Update(newsEntity);
  128. }
  129. else
  130. {
  131. newsEntity.Create();
  132. newsEntity.TypeId = 1;
  133. this.BaseRepository().Insert(newsEntity);
  134. }
  135. }
  136. /// <summary>
  137. /// 修改
  138. /// </summary>
  139. /// <param name="newsEntity">新闻实体</param>
  140. /// <returns></returns>
  141. public void UpdateForm(NewsEntity newsEntity)
  142. {
  143. newsEntity.TypeId = 1;
  144. this.BaseRepository().Update(newsEntity);
  145. }
  146. #endregion
  147. }
  148. }