MappingLogic.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using CZFW.Framework.Logic;
  2. using CZFW.Framework.Model.Entity;
  3. using CZFW.Framework.Model.ViewModel;
  4. using CZKJ.GBRS2.Entity;
  5. using CZKJ.GBRS2.Interface;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. namespace CZKJ.GBRS2.Logic
  11. {
  12. public class MappingLogic : LogicBase<MappingEntity>, IMapping
  13. {
  14. public ResultModel AddMapping(int module, IList<int> idList)
  15. {
  16. if(idList!=null)
  17. {
  18. IList<MappingEntity> list = new List<MappingEntity>();
  19. foreach(var item in idList)
  20. {
  21. var entity = new MappingEntity { Module = module, RefId = item };
  22. list.Add(entity);
  23. }
  24. return AddEntities(list);
  25. }
  26. return new ResultModel { Success = true };
  27. }
  28. public IList<ProductEntity> GetProductTableList(int module, int pageIndex, int pageSize, out int rowsCount)
  29. {
  30. var queryable = Queryable.Where(x => x.Module == module);
  31. rowsCount = queryable.Count();
  32. queryable = queryable.Skip((pageIndex - 1) * pageSize).Take(pageSize);
  33. var result = from a in queryable
  34. join p in DbContext.Set<ProductEntity>() on a.RefId equals p.Id
  35. join b in DbContext.Set<TypeEntity>() on p.TypeId equals b.Id into temp
  36. from t in temp.DefaultIfEmpty()
  37. select new
  38. {
  39. Id = p.Id,
  40. Title = p.Title,
  41. TypeName = t.Name,
  42. Image = p.Image,
  43. Summary = p.Summary,
  44. PublishTime = p.PublishTime
  45. };
  46. return result.ToList().Select(x => new ProductEntity
  47. {
  48. Id = x.Id,
  49. Title=x.Title,
  50. TypeName=x.TypeName,
  51. Image=x.Image,
  52. Summary=x.Summary,
  53. PublishTime=x.PublishTime
  54. }).ToList();
  55. }
  56. public ResultModel RemoveMapping(int module, int refId)
  57. {
  58. var entity = GetEntity(x=>x.Module==module&&x.RefId==refId);
  59. if(entity ==null)
  60. {
  61. return new ResultModel { Success = false, Message = "未删除任何数据" };
  62. }
  63. return RemoveEntity(entity.Id);
  64. }
  65. public IList<ArticleEntity> GetArticleTableList(int module, int pageIndex, int pageSize, out int rowsCount)
  66. {
  67. var queryable = Queryable.Where(x => x.Module == module);
  68. rowsCount = queryable.Count();
  69. queryable = queryable.Skip((pageIndex - 1) * pageSize).Take(pageSize);
  70. var result = from x in queryable
  71. join ai in DbContext.Set<ArticleEntity>() on x.RefId equals ai.Id
  72. join ty in DbContext.Set<TypeEntity>() on ai.TypeId equals ty.Id
  73. select new
  74. {
  75. Id = ai.Id,
  76. Title = ai.Title,
  77. Image = ai.Image,
  78. Summary = ai.Summary,
  79. Detail = ai.Detail,
  80. PublishTime = ai.PublishTime,
  81. TypeName = ty.Name
  82. };
  83. return result.ToList().Select(x => new ArticleEntity
  84. {
  85. Id = x.Id,
  86. Title = x.Title,
  87. Image = x.Image,
  88. Summary = x.Summary,
  89. Detail = x.Detail,
  90. PublishTime = x.PublishTime,
  91. TypeName = x.TypeName
  92. }).ToList();
  93. }
  94. }
  95. }