PublicInfoController.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using CZFW.Framework.Interface;
  2. using CZKJ.GBRS2.Interface;
  3. using CZKJ.GBRS2.WebMVC.Models;
  4. using Microsoft.AspNetCore.Mvc;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. namespace CZKJ.GBRS2.WebMVC.Controllers
  8. {
  9. public class PublicInfoController : Controller
  10. {
  11. IPublicInfo _publicInfologic;
  12. IPublicType _publicTypeLogic;
  13. IGallery _galleryLogic;
  14. public PublicInfoController(IPublicInfo publicinfologic, IPublicType publicTypeLogic, IGallery galleryLogic)
  15. {
  16. _publicInfologic = publicinfologic;
  17. _publicTypeLogic = publicTypeLogic;
  18. _galleryLogic = galleryLogic;
  19. }
  20. public IActionResult Index(int? typeId, int? id, int pageIndex = 1, int pageSize = 10)
  21. {
  22. int rowsCount;
  23. var model = new PublicInfoIndexModel();
  24. var entity = id.HasValue ? _publicInfologic.GetEntity(id.Value) : new Entity.PublicInfoEntity();
  25. model.PublicInfoEntity = entity;
  26. model.GalleryEntity = _galleryLogic.GetEntity(x => x.TypeId == 132);
  27. typeId = typeId.HasValue ? typeId : entity.TypeId == 0 ? _publicTypeLogic.GetChildList(null)[0].Id : entity.TypeId;
  28. model.TypeId = typeId.Value;
  29. model.ArticleList = _publicInfologic.GetEntities(out rowsCount, x => x.TypeId == typeId, pageIndex, pageSize, x => x.SortOrder, ListSortDirection.Descending);
  30. var typeList = _publicTypeLogic.GetEntities();
  31. model.TypeList = typeList;
  32. model.TypeName = typeList.FirstOrDefault(x => x.Id == typeId.Value).Name;
  33. model.RowsCount = rowsCount;
  34. model.PageIndex = pageIndex;
  35. model.Id = id;
  36. if (id.HasValue)
  37. {
  38. model.SeoTitle = entity.SeoTitle;
  39. model.SeoKeywords = entity.SeoKeywords;
  40. model.SeoDescription = entity.SeoDescription;
  41. model.ShareTitle = entity.ShareTitle;
  42. model.ShareUrl = entity.ShareUrl;
  43. model.ShareImage = entity.ShareImage;
  44. model.ShareDescription = entity.ShareDescription;
  45. }
  46. return View(model);
  47. }
  48. }
  49. }