112 lines
3.6 KiB
C#
112 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using COMCMS.Web.Models;
|
|
using COMCMS.Common;
|
|
using COMCMS.Core;
|
|
using XCode;
|
|
using System.Text;
|
|
using System.IO;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration.Json;
|
|
using Microsoft.AspNetCore.Http;
|
|
using System.Collections.Concurrent;
|
|
using Newtonsoft.Json;
|
|
using COMCMS.Web.Common;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
namespace COMCMS.Web.Controllers
|
|
{
|
|
public class HomeController : HomeBaseController
|
|
{
|
|
private IWebHostEnvironment _env;
|
|
|
|
public HomeController(IWebHostEnvironment env)
|
|
{
|
|
_env = env;
|
|
}
|
|
#region 首页
|
|
public IActionResult Index()
|
|
{
|
|
ViewBag.cfg = cfg;
|
|
ViewBag.about = Article.FindById(1);//关于我们
|
|
return View("~/Views/Home/Index.cshtml");
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 显示默认错误页面
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
#endregion
|
|
|
|
#region 初始化安装
|
|
[HttpGet]
|
|
public IActionResult Install()
|
|
{
|
|
string lockPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}install.lock";
|
|
if (System.IO.File.Exists(lockPath))
|
|
{
|
|
return EchoTip("COMCMS系统已经安装过,如果需要重新安装,请删除程序wwwroot目录下的install.lock文件!", false, "/");
|
|
}
|
|
bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;
|
|
ViewBag.hasData = hasData;
|
|
return View();
|
|
}
|
|
#endregion
|
|
|
|
#region 测试
|
|
//[Route("c/{*path}/index2.html")]
|
|
//public IActionResult Test(string path = "")
|
|
//{
|
|
// string tel = "13332835377";
|
|
// return Content(tel.Substring(tel.Length - 5) + ";path:" + path);
|
|
//}
|
|
//[Route("{path1:regex([[a-zA-Z0-9-]])}/{path2:regex([[a-zA-Z0-9-]])}/index.html")]
|
|
//public IActionResult Test2(string path1 = "", string path2 = "")
|
|
//{
|
|
// ArticleController ac = new ArticleController();
|
|
// return ac.Index(1);
|
|
// //return Content(";ath1:" + path1+";path2:"+path2);
|
|
//}
|
|
#endregion
|
|
|
|
|
|
#region 系统文章栏目、商品栏目路由
|
|
/// <summary>
|
|
/// 一级路径栏目
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
/// <returns></returns>
|
|
[Route("{path:regex([[a-zA-Z0-9-]])}/index.html")]
|
|
[Route("{path:regex([[a-zA-Z0-9-]])}/index-{page:int}.html")]
|
|
[Route("{path:regex([[a-zA-Z0-9-]])}/")]
|
|
public IActionResult ShowCategory(string path,int page=1)
|
|
{
|
|
//先判断文章栏目
|
|
ArticleCategory articleCategory = ArticleCategory.FindByFilePath("/" + path);
|
|
if(articleCategory != null)
|
|
{
|
|
//return Content(articleCategory.Id.ToString());
|
|
ArticleController ac = new ArticleController();
|
|
return ac.Index(articleCategory.Id);
|
|
}
|
|
//再判断商品
|
|
Category category = Category.FindByFilePath("/" + path);
|
|
if(category != null)
|
|
{
|
|
ProductController pc = new ProductController();
|
|
return pc.Index(category.Id,page);
|
|
}
|
|
return EchoTip("系统找不到本栏目!"+"/"+path);
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|