PositionLogic.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using CZFW.Framework.Logic;
  2. using CZFW.Framework.Model.ViewModel;
  3. using CZKJ.GBRS2.Entity;
  4. using CZKJ.GBRS2.Interface;
  5. using System.Linq;
  6. using CZFW.Framework.Model.Entity;
  7. using System.Collections.Generic;
  8. namespace CZKJ.GBRS2.Logic
  9. {
  10. public class PositionLogic : LogicBase<PositionEntity>, IPosition
  11. {
  12. public PositionEntity GetItem(int id)
  13. {
  14. var result = Queryable.Where(x => x.Id == id).Join(DbContext.Set<TypeEntity>(), x => x.TypeId, y => y.Id, (x, y) => new { x, TypeName = y.Name }).Join(DbContext.Set<DictItemEntity>(), x => x.x.DepartmentId, y => y.Id, (x, y) => new { x, Department = y.Name }).Join(DbContext.Set<DictItemEntity>(), x => x.x.x.AddressId, y => y.Id, (x, y) => new { x, Address = y.Name }).FirstOrDefault();
  15. return new PositionEntity
  16. {
  17. Id = result.x.x.x.Id,
  18. AddressId = result.x.x.x.AddressId,
  19. DepartmentId = result.x.x.x.DepartmentId,
  20. Name = result.x.x.x.Name,
  21. Number = result.x.x.x.Number,
  22. Respons = result.x.x.x.Respons,
  23. Requirement = result.x.x.x.Requirement,
  24. SeoTitle = result.x.x.x.SeoTitle,
  25. SeoDescription = result.x.x.x.SeoDescription,
  26. SeoKeywords = result.x.x.x.SeoKeywords,
  27. ShareDescription = result.x.x.x.ShareDescription,
  28. ShareImage = result.x.x.x.ShareImage,
  29. ShareTitle = result.x.x.x.ShareTitle,
  30. ShareUrl = result.x.x.x.ShareUrl,
  31. TypeId = result.x.x.x.TypeId,
  32. Address = result.Address,
  33. Department = result.x.Department,
  34. TypeName = result.x.x.TypeName
  35. };
  36. }
  37. public IList<PositionEntity> GetPositionList(string name, int typeId, int? addressId, int? deptId, int pageIndex, int pageSize, out int rowsCount)
  38. {
  39. var queryable = Queryable.Where(x => x.TypeId == typeId);
  40. if (!string.IsNullOrWhiteSpace(name))
  41. {
  42. queryable = queryable.Where(x => x.Name.Contains(name.Trim()));
  43. }
  44. if (addressId.HasValue)
  45. {
  46. queryable = queryable.Where(x => x.AddressId == addressId);
  47. }
  48. if (deptId.HasValue)
  49. {
  50. queryable = queryable.Where(x => x.DepartmentId == deptId);
  51. }
  52. rowsCount = queryable.Count();
  53. var result = queryable.OrderByDescending(x => x.SortOrder).Skip((pageIndex - 1) * pageSize).Take(pageSize);
  54. var data = (from x in result
  55. join ty in DbContext.Set<TypeEntity>() on x.TypeId equals ty.Id
  56. join de in DbContext.Set<DictItemEntity>() on x.DepartmentId equals de.Id
  57. join ci in DbContext.Set<DictItemEntity>() on x.AddressId equals ci.Id
  58. select new PositionEntity
  59. {
  60. Id = x.Id,
  61. TypeId = x.TypeId,
  62. TypeName = ty.Name,
  63. Name = x.Name,
  64. Number = x.Number,
  65. AddressId = x.AddressId,
  66. Address = ci.Name,
  67. DepartmentId = x.DepartmentId,
  68. Department = de.Name,
  69. Respons = x.Respons,
  70. Requirement = x.Requirement,
  71. SortOrder = x.SortOrder
  72. }).ToList();
  73. return data;
  74. }
  75. public IList<PositionEntity> GetPositionList(int id, int typeId, int deptId)
  76. {
  77. var queryable = Queryable.Where(x => x.Id != id && x.TypeId == typeId && x.DepartmentId == deptId);
  78. var data = (from x in queryable
  79. join ty in DbContext.Set<TypeEntity>() on x.TypeId equals ty.Id
  80. join de in DbContext.Set<DictItemEntity>() on x.DepartmentId equals de.Id
  81. join ci in DbContext.Set<DictItemEntity>() on x.AddressId equals ci.Id
  82. select new PositionEntity
  83. {
  84. Id = x.Id,
  85. TypeId = x.TypeId,
  86. TypeName = ty.Name,
  87. Name = x.Name,
  88. Number = x.Number,
  89. AddressId = x.AddressId,
  90. Address = ci.Name,
  91. DepartmentId = x.DepartmentId,
  92. Department = de.Name,
  93. Respons = x.Respons,
  94. Requirement = x.Requirement
  95. }).ToList();
  96. return data;
  97. }
  98. }
  99. }