AdvertisementService.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using Lottomat.Application.Entity.InformationManage;
  3. using Lottomat.Application.IService.InformationManage;
  4. using Lottomat.Data.Repository;
  5. using Lottomat.Util.WebControl;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Linq.Expressions;
  9. using Lottomat.Util.Extension;
  10. using Newtonsoft.Json.Linq;
  11. namespace Lottomat.Application.Service.InformationManage
  12. {
  13. /// <summary>
  14. /// 版 本 1.0
  15. /// Copyright (c) 2016-2017
  16. /// 创 建:超级管理员
  17. /// 日 期:2018-01-05 14:54
  18. /// 描 述:广告管理
  19. /// </summary>
  20. public class AdvertisementService : RepositoryFactory<AdvertisementEntity>, IAdvertisementService
  21. {
  22. #region 获取数据
  23. /// <summary>
  24. /// 获取列表
  25. /// </summary>
  26. /// <param name="pagination">分页</param>
  27. /// <param name="queryJson">查询参数</param>
  28. /// <returns>返回分页列表</returns>
  29. public IEnumerable<AdvertisementEntity> GetPageList(Pagination pagination, string queryJson)
  30. {
  31. var expression = LinqExtensions.True<AdvertisementEntity>();
  32. JObject queryParam = queryJson.ToJObject();
  33. if (queryParam != null)
  34. {
  35. if (!queryParam["Term"].IsEmpty())
  36. {
  37. string term = queryParam["Term"].ToString();
  38. if (!string.IsNullOrEmpty(term))
  39. {
  40. expression = expression.And(t => t.Title.Contains(term));
  41. }
  42. }
  43. if (!queryParam["Category"].IsEmpty())
  44. {
  45. string category = queryParam["Category"].ToString();
  46. if (!string.IsNullOrEmpty(category))
  47. {
  48. expression = expression.And(t => t.CategoryId == category);
  49. }
  50. }
  51. if (!queryParam["IsEnable"].IsEmpty())
  52. {
  53. string isEnable = queryParam["IsEnable"].ToString();
  54. if (!string.IsNullOrEmpty(isEnable))
  55. {
  56. bool i = isEnable == "true" ? true : false;
  57. expression = expression.And(t => t.IsEnable ==i );
  58. }
  59. }
  60. }
  61. expression = expression.And(t => t.IsDelete == false);
  62. return this.BaseRepository().FindList(expression, pagination);
  63. }
  64. /// <summary>
  65. /// 获取列表
  66. /// </summary>
  67. /// <param name="query">查询参数</param>
  68. /// <returns>返回列表</returns>
  69. public IEnumerable<AdvertisementEntity> GetList(Expression<Func<AdvertisementEntity, bool>> query)
  70. {
  71. return this.BaseRepository().FindList(query);
  72. }
  73. /// <summary>
  74. /// 获取实体
  75. /// </summary>
  76. /// <param name="keyValue">主键值</param>
  77. /// <returns></returns>
  78. public AdvertisementEntity GetEntity(string keyValue)
  79. {
  80. return this.BaseRepository().FindEntity(keyValue);
  81. }
  82. public AdvertisementEntity GetEntity(Expression<Func<AdvertisementEntity, bool>> query)
  83. {
  84. return this.BaseRepository().FindEntity(query);
  85. }
  86. #endregion
  87. #region 提交数据
  88. /// <summary>
  89. /// 删除数据
  90. /// </summary>
  91. /// <param name="keyValue">主键</param>
  92. public void RemoveForm(string keyValue)
  93. {
  94. this.BaseRepository().Delete(keyValue);
  95. }
  96. /// <summary>
  97. /// 保存表单(新增、修改)
  98. /// </summary>
  99. /// <param name="keyValue">主键值</param>
  100. /// <param name="entity">实体对象</param>
  101. /// <returns></returns>
  102. public void SaveForm(string keyValue, AdvertisementEntity entity)
  103. {
  104. if (!string.IsNullOrEmpty(keyValue))
  105. {
  106. entity.Modify(keyValue);
  107. this.BaseRepository().Update(entity);
  108. }
  109. else
  110. {
  111. entity.Create();
  112. this.BaseRepository().Insert(entity);
  113. }
  114. }
  115. #endregion
  116. }
  117. }