using CZFW.Framework.Interface; using CZKJ.GBRS2.Enum; using CZKJ.GBRS2.Interface; using CZKJ.GBRS2.WebMVC.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Linq; namespace CZKJ.GBRS2.WebMVC.Controllers { /// /// 产品展示 /// public class ProductController : Controller { IProduct _productLogic; IType _typeLogic; IGallery _galleryLogic; public ProductController(IProduct productLogic, IType typeLogic, IGallery galleryLogic) { _productLogic = productLogic; _typeLogic = typeLogic; _galleryLogic = galleryLogic; } public IActionResult Index() { //100:个险 95: 团险 var typeList = _typeLogic.GetEntities(x => x.ParentId == 100 || x.ParentId == 95); var productList = _productLogic.GetCountList(typeList.Select(x => x.Id).ToList(), 2); var idList = new List { 145, 146, 147 }; var galleryList = _galleryLogic.GetGalleryList(idList); var model = new ProductIndexModel(); model.GalleryEntity = galleryList.First(x => x.TypeId == 145); model.TypeGalleryList = galleryList.Where(x => x.TypeId == 146).ToList(); model.CenterGallery = galleryList.First(x => x.TypeId == 147); model.PersonTypeList = typeList.Where(x => x.ParentId == 100).ToList(); model.GroupTypeList = typeList.Where(x => x.ParentId == 95).ToList(); var personIdList = model.PersonTypeList.Select(x => x.Id).ToList(); var groupIdList = model.GroupTypeList.Select(x => x.Id).ToList(); model.PersonList = productList.Where(x => personIdList.Contains(x.TypeId)).ToList(); model.GroupList = productList.Where(x => groupIdList.Contains(x.TypeId)).ToList(); return View(model); } public IActionResult List(int? typeId, int parentId = 100, int pageIndex = 1, int pageSize = 10) { int rowsCount; var model = new ProductListModel(); model.TypeList = _typeLogic.GetEntities(x => x.ParentId == parentId); typeId = typeId.HasValue ? typeId : model.TypeList.FirstOrDefault().Id; model.ParentTypeName = _typeLogic.GetEntity(x => x.Id == parentId).Name; model.ProductList = _productLogic.GetEntities(out rowsCount, x => x.TypeId == typeId && x.Status == (int)ProductStatusEnum.上线, pageIndex, pageSize, x => x.SortOrder, System.ComponentModel.ListSortDirection.Descending); model.RowsCount = rowsCount; model.PageIndex = pageIndex; model.TypeId = typeId.Value; model.ParentId = parentId; return View(model); } public IActionResult Detail(int id) { return View(_productLogic.GetEntity(id)); } public IActionResult Preview(int id) { return View(_productLogic.GetEntity(id)); } } }