HomeController.cs 2.34 KB
using Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using WebApp;
using WebRepository;

namespace WebMvc
{
    public class HomeController : BaseController
    {
        private readonly string _appKey = "hhweb";
        private IUnitWork _unitWork;

        private IAuth _myauthUtil;
        public HomeController(IUnitWork unitWork, IAuth authUtil) : base(authUtil)
        {
            _unitWork = unitWork;
            _myauthUtil = authUtil;
        }

        public ActionResult Index()
        {
            SysInfo sysInfo = _unitWork.FindSingle<SysInfo>(u => u.AppKey.Equals(_appKey));
            ViewBag.CopyRight = sysInfo.Copyright;
            ViewBag.SystemNameCn = sysInfo.Title;
            ViewBag.SystemNameUs = sysInfo.TitleUs;
            ViewBag.IndexLogo = sysInfo.IndexLogo;

            AuthStrategyContext authStrategyContext = _myauthUtil.GetCurrentUser();
            if (authStrategyContext != null)
            {
                ViewBag.Account = authStrategyContext.User.Account;
                ViewBag.Name = authStrategyContext.User.Name;
            }

            return View();
        }

        public ActionResult Main()
        {
            return View();
        }

        [HttpPost]
        public string GetQuickFunc()
        {
            var result = new TableData();
            try
            {
                List<SysModule> sysModules = new List<SysModule>();
                AuthStrategyContext authStrategyContext = _myauthUtil.GetCurrentUser();
                if (authStrategyContext != null)
                {
                    foreach (var item in authStrategyContext.Modules)
                    {
                        if (item.Status)
                        {
                            sysModules.Add(item);
                        }
                    }
                }

                var data = sysModules.Select(u => new { u.Name, u.NameUs, u.IconName, u.Url });
                result.code = 200;
                result.data = data;
                result.count = data.Count();
            }
            catch (Exception ex)
            {
                result.code = 500;
                result.msg = ex.Message;
            }

            return JsonHelper.Instance.Serialize(result);
        }
    }
}