public JsonResult Reg(string hotelName, string userName, string pwd, string CfmPwd, string handler, string tel, string code)
        {
            var apiResult = new APIResult();

            try
            {
                if (Session[vCode.SessionName] == null)
                {
                    throw new OperationExceptionFacade("验证码已过期");
                }
                else if (code.ToLower() != Session[vCode.SessionName].ToString().ToLower())
                {
                    throw new OperationExceptionFacade("验证码错误");
                }

                if (string.IsNullOrWhiteSpace(hotelName))
                {
                    throw new OperationExceptionFacade("酒店名称不可为空");
                }
                if (string.IsNullOrWhiteSpace(userName))
                {
                    throw new OperationExceptionFacade("用户名不可为空");
                }
                if (string.IsNullOrWhiteSpace(pwd))
                {
                    throw new OperationExceptionFacade("密码不可为空");
                }
                if (CfmPwd != pwd)
                {
                    throw new OperationExceptionFacade("两次输入的密码不相同");
                }
                if (string.IsNullOrWhiteSpace(handler))
                {
                    throw new OperationExceptionFacade("联系人不可为空");
                }
                if (string.IsNullOrWhiteSpace(tel))
                {
                    throw new OperationExceptionFacade("联系电话不可为空");
                }

                var hotelId = IdBuilder.NextLongID();

                var user = new Hotel.Model.User()
                {
                    Id       = IdBuilder.NextLongID(),
                    UserName = userName,
                    Pwd      = pwd,
                    HotelId  = hotelId,
                    UserType = 2,
                    GId      = 2,//总店管理员
                    CDate    = TypeConvert.DateTimeToInt(DateTime.Now)
                };
                if (UserBll.Reg(user))
                {
                    var hotel = new HotelModel()
                    {
                        Id      = hotelId,
                        Name    = hotelName,
                        Handler = handler,
                        Tel     = tel,
                        CDate   = TypeConvert.DateTimeToInt(DateTime.Now)
                    };
                    bool flag = HotelBll.RegHotel(hotel);
                    if (!flag)
                    {
                        throw new OperationExceptionFacade("酒店注册失败");
                    }
                }
            }
            catch (Exception ex)
            {
                apiResult.Ret = -1;
                apiResult.Msg = ex.Message;
                if (!(ex is OperationExceptionFacade))
                {
                    LogFactory.GetLogger().Log(LogLevel.Error, ex);
                }
            }
            return(Json(apiResult));
        }
        public JsonResult Log(string userName, string pwd, string code)
        {
            var apiResult = new APIResult();

            try {
                if (Session[vCode.SessionName] == null)
                {
                    throw new OperationExceptionFacade("验证码已过期");
                }
                else if (code.ToLower() != Session[vCode.SessionName].ToString().ToLower())
                {
                    throw new OperationExceptionFacade("验证码错误");
                }
                if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(pwd))
                {
                    throw new OperationExceptionFacade("用户名或密码不可为空");
                }

                UAParserUserAgent userAgent = new UAParserUserAgent(HttpContext);
                int deviceType = 1;
                if (userAgent.IsMobileDevice)
                {
                    deviceType = (int)DeviceTypeEnum.手机;
                }
                else if (userAgent.IsTablet)
                {
                    deviceType = (int)DeviceTypeEnum.平板;
                }
                else
                {
                    deviceType = (int)DeviceTypeEnum.电脑;
                }
                var user = UserBll.Login(userName, pwd);
                if (user == null)
                {
                    throw new OperationExceptionFacade("用户名或密码错误");
                }

                string token = string.Empty;
                if (user != null)
                {
                    token = UserTokenBL.GetNewTokenAndToCache(UserTokenType.WebToken, user.Id.ToString(), "", 00001, "", 600);
                    SetTokenToCookies(token);
                    //更新权限
                    ContainerHelper.ResolvePerHttpRequest <IPermissionBL>().UpdateCache(user.GId);
                }

                LoginLog log = new LoginLog
                {
                    Id       = IdBuilder.NextLongID(),
                    UserId   = user.Id,
                    UserName = userName,
                    GroupId  = user.Group.Id,
                    Phone    = user.Tel,
                    Ip       = GetClientIP.GetClientIPAddress(),
                    Address  = string.Empty,

                    Device    = deviceType,
                    OS        = userAgent.OS.ToString(),
                    Agent     = userAgent.UserAgent.ToString(),
                    IsSuccess = user == null ? false : true,
                    Token     = token,
                    CDate     = TypeConvert.DateTimeToInt(DateTime.Now)
                                //SysType = 2,
                                //LogType = 1,
                };
                LoginLogBL.Add(log, false);
            }
            catch (Exception ex) {
                apiResult.Ret = -1;
                apiResult.Msg = ex.Message;
                if (!(ex is OperationExceptionFacade))
                {
                    LogFactory.GetLogger().Log(LogLevel.Error, ex);
                }
            }
            return(Json(apiResult));
        }
        public JsonResult Edit(Menu model)
        {
            if (model.Id == 0)
            {
                model.CDate    = TypeConvert.DateTimeToInt(DateTime.Now);
                model.HasChild = false;
            }
            var apiResult = new APIResult();

            try
            {
                if (model.Id == 0)
                {
                    model.Id = IdBuilder.NextLongID();
                    MenuBll.Insert(model);
                    //保存菜单按钮
                    if (!string.IsNullOrWhiteSpace(model.BtnNames))
                    {
                        string[] btnIdArr = model.BtnNames.Split(',');
                        if (btnIdArr.Length > 0)
                        {
                            foreach (var btnIdStr in btnIdArr)
                            {
                                long btnId = 0;
                                if (long.TryParse(btnIdStr, out btnId))
                                {
                                    var menuFuncBtn = new MenuFuncBtn()
                                    {
                                        Id        = IdBuilder.NextLongID(),
                                        MenuId    = model.Id,
                                        FuncBtnId = btnId,
                                        CDate     = TypeConvert.DateTimeToInt(DateTime.Now)
                                    };
                                    MenuFuncBtnBll.AddOrUpdate(menuFuncBtn);
                                }
                            }
                        }
                    }
                }

                else
                {
                    MenuBll.Update(model);
                    //删除菜单按钮
                    MenuFuncBtnBll.Delete(model.Id);
                    //保存菜单按钮
                    if (!string.IsNullOrWhiteSpace(model.BtnNames))
                    {
                        string[] btnIdArr = model.BtnNames.Split(',');
                        if (btnIdArr.Length > 0)
                        {
                            foreach (var btnIdStr in btnIdArr)
                            {
                                long btnId = 0;
                                if (long.TryParse(btnIdStr, out btnId))
                                {
                                    var menuFuncBtn = new MenuFuncBtn()
                                    {
                                        Id        = IdBuilder.NextLongID(),
                                        MenuId    = model.Id,
                                        FuncBtnId = btnId,
                                        CDate     = TypeConvert.DateTimeToInt(DateTime.Now)
                                    };
                                    MenuFuncBtnBll.AddOrUpdate(menuFuncBtn);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                apiResult.Ret = -1;
                apiResult.Msg = ex.Message;
                if (!(ex is OperationExceptionFacade))
                {
                    LogFactory.GetLogger().Log(LogLevel.Error, ex);
                }
            }

            return(Json(apiResult));
        }
        /// <summary>
        /// Action执行后
        /// </summary>
        void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext)
        {
            var         resultFlag = false;
            OprtLogType LogType    = LogWay;

            if (!IsRecordLog)
            {
                return;
            }
            try
            {
                var     result = ((System.Web.Mvc.JsonResult)filterContext.Result).Data;
                dynamic d      = result;
                if (result.ToString().Contains("Ret"))
                {
                    if (d.Ret == 0)
                    {
                        resultFlag = true;
                    }
                }
                else if (result.ToString().Contains("type"))
                {
                    if (d.type == 0)
                    {
                        resultFlag = true;
                    }
                }
                //object obj= JsonConvert.DeserializeObject(result);
                string controller = filterContext.Controller.ToString();
                string action     = filterContext.ActionDescriptor.ActionName;

                Type            type      = Type.GetType(controller);
                ParameterInfo[] parasInfo = null;
                if (IsFormPost)
                {
                    parasInfo = type.GetMethod(action, Entitys).GetParameters();
                }
                else
                {
                    parasInfo = type.GetMethod(action).GetParameters();
                }

                if (parasInfo == null || parasInfo.Length == 0)
                {
                    return;
                }

                StringBuilder content = new StringBuilder();
                if (!IsFormPost)
                {
                    foreach (var item in parasInfo)
                    {
                        //判断是新增还是修改
                        if (LogWay == OprtLogType.新增和修改)
                        {
                            if (item.Name.ToLower().ToString() == "id")
                            {
                                string id = filterContext.HttpContext.Request[item.Name].ToString();
                                if (id == "0" || id == "")
                                {
                                    LogType = OprtLogType.新增;
                                    Method  = OprtLogType.新增.ToString();
                                }
                                else
                                {
                                    LogType = OprtLogType.修改;
                                    Method  = OprtLogType.修改.ToString();
                                }
                            }
                        }

                        if (LogWay == OprtLogType.除 && IsFromCache)
                        {
                            content.Append(DelLogCache.Get());
                            continue;
                        }

                        //获取内容
                        if (string.IsNullOrEmpty(filterContext.HttpContext.Request[item.Name]))
                        {
                            continue;
                        }
                        content.Append(item.Name);
                        content.Append(":");
                        content.Append(filterContext.HttpContext.Request[item.Name].ToString());
                        content.Append(";");
                    }
                }
                else
                {
                    foreach (var item in parasInfo)
                    {
                        PropertyInfo[] fileds = Entitys[0].GetProperties();
                        foreach (var f in fileds)
                        {
                            //判断是新增还是修改
                            if (LogWay == OprtLogType.新增和修改)
                            {
                                if (f.Name.ToLower().ToString() == "id")
                                {
                                    string id = filterContext.HttpContext.Request[f.Name].ToString();
                                    if (id == "0" || id == "")
                                    {
                                        LogType = OprtLogType.新增;
                                        Method  = OprtLogType.新增.ToString();
                                    }
                                    else
                                    {
                                        LogType = OprtLogType.修改;
                                        Method  = OprtLogType.修改.ToString();
                                    }
                                }
                            }

                            if (LogWay == OprtLogType.除 && IsFromCache)
                            {
                                content.Append(DelLogCache.Get());
                                continue;
                            }

                            if (string.IsNullOrEmpty(filterContext.HttpContext.Request[f.Name]))
                            {
                                continue;
                            }
                            content.Append(f.Name);
                            content.Append(":");
                            content.Append(filterContext.HttpContext.Request[f.Name].ToString());
                            content.Append(";");
                        }
                    }
                }

                //根据controler获取菜单的配置,找出控制器对应的中文名
                string page           = string.Empty;
                var    menuList       = MenuBll.GetAllList().Where(m => m.MenuController != null);
                string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                var    menu           = menuList.FirstOrDefault(m => m.MenuController.ToLower() == controllerName.ToLower());
                if (menu != null)
                {
                    page = menu.Name;
                }

                var user = UserContext.CurrentUser;
                if (string.IsNullOrWhiteSpace(Method))
                {
                    Method = LogType.ToString();
                }

                var model = new OprtLog
                {
                    Id         = IdBuilder.NextLongID(),
                    AppKey     = string.Empty,
                    HotelId    = user == null ? 0 : user.HotelId,
                    UserId     = user == null ? 0 : user.Id,
                    UserName   = user == null ? string.Empty : user.UserName,
                    Controller = controllerName,
                    Action     = action,
                    Page       = page,
                    Method     = Method,
                    Content    = content.ToString().Length > 2000 ? content.ToString().Substring(0, 2000) : content.ToString(),
                    Result     = resultFlag,
                    LogType    = (int)LogType,
                    CDate      = TypeConvert.DateTimeToInt(DateTime.Now),
                };

                logService.AddOrUpdate(model);
            }
            catch (Exception ex)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, ex);
            }
        }