using System; using System.Web.Mvc; using Service; using Domain; namespace WebSite.Controllers { [HandleError] public class BaseController : Controller { public static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(BaseController)); public ISysSystemLogsManager SysSystemLogsManager { get; set; } protected override void HandleUnknownAction(string actionName) { this.View(actionName).ExecuteResult(this.ControllerContext); } protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); } protected Language Language { get { //语言判断 int? isCN = Session["isCN"] as int?; if (!isCN.HasValue) { isCN = 0; Session["isCN"] = isCN; } switch (isCN) { case 1: return Language.EN; case 2: return Language.ZH_TW; default: return Language.CN; } } } /// /// 当前酒店ID /// protected int CurrentHotelID { get { if (Session["CurrentHotelID"] == null) { return 0; } return (int)Session["CurrentHotelID"]; } set { Session["CurrentHotelID"] = value; } } protected string CurrentHotelCode { get { if (Session["CurrentHotelCode"] == null) { return ""; } return Session["CurrentHotelCode"].ToString(); } set { Session["CurrentHotelCode"] = value; } } /// /// 当前酒店名称 /// protected string CurrentHotelName { get { if (Session["CurrentHotelName"] == null) { return ""; } return (string)Session["CurrentHotelName"]; } set { Session["CurrentHotelName"] = value; } } /// /// 当前酒店logo路径 /// protected string CurrentLogoPath { get { if (Session["CurrentLogoPath"] == null) { return "../Uploads/logo/1001.png"; } return (string)Session["CurrentLogoPath"]; } set { Session["CurrentLogoPath"] = value; } } /// /// 当前酒店是否到期提醒 /// protected bool CurrentHotelIsExpire { get { if (Session["CurrentHotelIsExpire"] == null) { return true; } return Convert.ToBoolean(Session["CurrentHotelIsExpire"]); } set { Session["CurrentHotelIsExpire"] = value; } } /// /// 记录操作日志 /// /// 权限ID /// 动作 /// 详细 /// 操作结果 /// 帐号 /// 所属酒店ID protected void SaveSystemLog(int authorityID, string action, string detail, bool result = true, string account = "", int hotelID = 1) { try { Domain.SysSystemLogs entity = new Domain.SysSystemLogs(); entity.ID = 0; entity.AuthorityID = authorityID; entity.Action = action; entity.Detail = detail; entity.Result = result ? HttpContext.InnerLanguage("OperationSuccess") : HttpContext.InnerLanguage("OperationFailed"); entity.Account = string.IsNullOrEmpty(this.User.Identity.Name) ? account : this.User.Identity.Name; entity.IP = GetClientIP(); entity.Time = DateTime.Now; entity.HotelID = CurrentHotelID == 0 ? hotelID : CurrentHotelID; SysSystemLogsManager.Save(entity); } catch (Exception) { } } protected string GetClientIP() { return Common.Tools.GetClientIP(Request); } /// /// 根据语言返回对应名称 /// /// /// /// /// protected string ReturnNameByLanguage(string name, string ename, string twname) { //语言判断 int? isCN = Session["isCN"] as int?; if (!isCN.HasValue) { isCN = 0; Session["isCN"] = isCN; } switch ((int)Session["isCN"]) { case 1: return ename; case 2: return twname; default: return name; } } } }