using learun.iapplication; using learun.website.Models; using learun.util; using Microsoft.AspNetCore.Mvc; using System; using System.Diagnostics; using System.Threading.Tasks; namespace learun.website.Controllers { public class HomeController : MvcControllerBase { private readonly HomeConfigIBLL _homeConfigIBLL; private readonly ArticleIBLL _articleIBLL; private readonly PageIBLL _pageIBLL; private readonly ImgIBLL _imgIBLL; public HomeController(HomeConfigIBLL homeConfigIBLL, ArticleIBLL articleIBLL, PageIBLL pageIBLL, ImgIBLL imgIBLL) { _homeConfigIBLL = homeConfigIBLL; _articleIBLL = articleIBLL; _pageIBLL = pageIBLL; _imgIBLL = imgIBLL; } #region 视图功能 /// /// 首页面 /// /// [HttpGet] public ActionResult Index() { return View(); } /// /// 子页面 /// /// [HttpGet] public ActionResult ChildIndex() { return View(); } /// /// 列表页面 /// /// [HttpGet] public ActionResult ListIndex() { return View(); } /// /// 图表页面 /// /// [HttpGet] public ActionResult ImgListIndex() { return View(); } /// /// 详情页面 /// /// [HttpGet] public ActionResult DetailIndex() { return View(); } #endregion #region 获取数据 /// /// 获取全部数据 /// /// [HttpGet] public async Task GetAllList() { var data =await _homeConfigIBLL.GetALLList(); return Success(data); } /// /// 获取数据 /// /// [HttpGet] public async Task GetList(string type) { var data =await _homeConfigIBLL.GetList(type); return Success(data); } /// /// 获取表单数据 /// 主键 /// /// [HttpGet] public async Task GetPageData(string keyValue) { var data = await _pageIBLL.GetEntity(keyValue); return Success(data); } #endregion #region 扩展功能 /// /// 获取图片文件 /// /// 主键 /// [HttpGet] public async Task GetImg(string type) { var entity = await _homeConfigIBLL.GetEntityByType(type); if (entity != null && !string.IsNullOrEmpty(entity.F_Img)) { ImgEntity imgEntity = await _imgIBLL.GetEntity(entity.F_Img); if (imgEntity != null && !string.IsNullOrEmpty(imgEntity.F_Content)) { string imgContent = imgEntity.F_Content.Replace("data:image/" + imgEntity.F_ExName.Replace(".", "") + ";base64,", ""); byte[] arr = Convert.FromBase64String(imgContent); return File(arr, "application/octet-stream"); } else { byte[] arr2 = FileHelper.ReadRoot("/img/plhome/addImg.png"); return File(arr2, "application/octet-stream"); } } else { byte[] arr3 = FileHelper.ReadRoot("/img/plhome/addImg.png"); return File(arr3, "application/octet-stream"); } } /// /// 获取图片文件 /// /// 主键 /// [HttpGet] public async Task GetImg2(string keyValue) { var entity = await _homeConfigIBLL.GetEntity(keyValue); if (entity != null && !string.IsNullOrEmpty(entity.F_Img)) { ImgEntity imgEntity = await _imgIBLL.GetEntity(entity.F_Img); if (imgEntity != null && !string.IsNullOrEmpty(imgEntity.F_Content)) { string imgContent = imgEntity.F_Content.Replace("data:image/" + imgEntity.F_ExName.Replace(".", "") + ";base64,", ""); byte[] arr = Convert.FromBase64String(imgContent); return File(arr, "application/octet-stream"); } else { byte[] arr2 = FileHelper.ReadRoot("/img/plhome/addImg.png"); return File(arr2, "application/octet-stream"); } } else { byte[] arr3 = FileHelper.ReadRoot("/img/plhome/addImg.png"); return File(arr3, "application/octet-stream"); } } /// /// 获取设置图片 /// /// 主键 /// [HttpGet] public async Task GetArticleImg(string keyValue) { var stampEntity = await _articleIBLL.GetEntity(keyValue); if (stampEntity != null && !string.IsNullOrEmpty(stampEntity.F_Img)) { ImgEntity imgEntity = await _imgIBLL.GetEntity(stampEntity.F_Img); if (imgEntity != null && !string.IsNullOrEmpty(imgEntity.F_Content)) { string imgContent = imgEntity.F_Content.Replace("data:image/" + imgEntity.F_ExName.Replace(".", "") + ";base64,", ""); byte[] arr = Convert.FromBase64String(imgContent); return File(arr, "application/octet-stream"); } else { byte[] arr2 = FileHelper.ReadRoot("/img/plhome/banner_df.jpg"); return File(arr2, "application/octet-stream"); } } else { byte[] arr3 = FileHelper.ReadRoot("/img/plhome/banner_df.jpg"); return File(arr3, "application/octet-stream"); } } /// /// 获取表单数据 /// 主键 /// /// [HttpGet] public async Task GetArticle(string keyValue) { var data =await _articleIBLL.GetEntity(keyValue); return Success(data); } /// /// 获取列表分页数据 /// 分页参数 /// /// [HttpGet] public async Task GetArticlePageList(string pagination, string queryJson) { Pagination paginationobj = pagination.ToObject(); var data =await _articleIBLL.GetPageList(paginationobj, queryJson); var jsonData = new { rows = data, total = paginationobj.total, page = paginationobj.page, records = paginationobj.records }; return Success(jsonData); } /// /// 获取设置图片 /// /// 主键 /// [HttpGet] public async Task GetPageImg(string keyValue) { var entity = await _pageIBLL.GetEntity(keyValue); if (entity != null && !string.IsNullOrEmpty(entity.F_Img)) { ImgEntity imgEntity = await _imgIBLL.GetEntity(entity.F_Img); if (imgEntity != null && !string.IsNullOrEmpty(imgEntity.F_Content)) { string imgContent = imgEntity.F_Content.Replace("data:image/" + imgEntity.F_ExName.Replace(".", "") + ";base64,", ""); byte[] arr = Convert.FromBase64String(imgContent); return File(arr, "application/octet-stream"); } else { byte[] arr2 = FileHelper.ReadRoot("/img/plhome/添加图片.jpg"); return File(arr2, "application/octet-stream"); } } else { byte[] arr3 = FileHelper.ReadRoot("/img/plhome/添加图片.jpg"); return File(arr3, "application/octet-stream"); } } /// /// 获取设置图片 /// /// 主键 /// [HttpGet] public IActionResult GetUeditorImg(string id) { string path = ConfigHelper.GetConfig().UeditorImg + "/ueditor/upload/image" + id; path = System.Text.RegularExpressions.Regex.Replace(path, @"\s", ""); byte[] arr3 = System.IO.File.ReadAllBytes(path); return File(arr3, "application/octet-stream"); } #endregion [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }