public void Add_Filter_Data()
        {
            PageInfo pageInfo;

            pageInfo = PageInfoManager.GetPageInfo("Filter", "Index");
            Assert.AreEqual("Index", pageInfo.Action);
            Assert.AreEqual("Filter", pageInfo.Controller);
            Assert.AreEqual(StateButtonIdentifier.None, pageInfo.StateButton);
            Assert.AreEqual(ButtonGroupIdentifier.Filter, pageInfo.ButtonGroup);
        }
        public void CheckIfAllViewActionsAreDefinedInPageInfoManager()
        {
            List <string> missingActionsInPageInfoManager = new List <string>();
            List <Type>   allControllers = GetAllControllers();

            foreach (Type controllerType in allControllers)
            {
                string            controllerName      = controllerType.Name.Replace("Controller", "");
                List <MethodInfo> actionResultMethods = GetMethodsWithSpecificReturnType(controllerType, typeof(ActionResult), true);
                foreach (MethodInfo methodInfo in actionResultMethods)
                {
                    if (IgnoreActionResultType(methodInfo.ReturnType))
                    {
                        continue;
                    }
                    if (methodInfo.GetCustomAttributes(typeof(IgnorePageInfoManagerAttribute), false).Length > 0)
                    {
                        continue;
                    }
                    PageInfo pageInfo = PageInfoManager.GetPageInfo(controllerName, methodInfo.Name);
                    if (pageInfo == null)
                    {
                        missingActionsInPageInfoManager.Add(string.Format("{0}/{1}  ", controllerName, methodInfo.Name));
                    }
                }
            }

            string strMissingMethods = "No missing methods";

            if (missingActionsInPageInfoManager.Count > 0)
            {
                strMissingMethods = "Missing methods in PageInfoManager: ";
                foreach (string str in missingActionsInPageInfoManager)
                {
                    strMissingMethods += string.Format("\n{0}", str);
                }
            }

            Assert.AreEqual(0, missingActionsInPageInfoManager.Count, strMissingMethods);
        }
        public PresentationTableViewModel CreatePresentationTableViewModel()
        {
            var model = new PresentationTableViewModel();

            model.SelectedTableTypes = TableSetting.SelectedTableTypes.Select(tableType => (int)tableType).ToList();
            model.Tables             = new List <PresentationTableTypeViewModel>();

            var speciesObservationTable = new PresentationTableTypeViewModel();

            speciesObservationTable.Title       = Resource.PresentationSpeciesObservationTable;
            speciesObservationTable.Id          = (int)PresentationTableType.SpeciesObservationTable;
            speciesObservationTable.HasSettings = true;
            speciesObservationTable.PageInfo    = PageInfoManager.GetPageInfo("Result", "SpeciesObservationTable");
            speciesObservationTable.IsSelected  = TableSetting.SelectedTableTypes.Any(id => id == PresentationTableType.SpeciesObservationTable);
            model.Tables.Add(speciesObservationTable);

            var gridStatisticsTable = new PresentationTableTypeViewModel();

            gridStatisticsTable.Title       = Resource.PresentationGridStatisticsTable;
            gridStatisticsTable.Id          = (int)PresentationTableType.GridStatisticsTable;
            gridStatisticsTable.HasSettings = false;
            gridStatisticsTable.PageInfo    = null; // no settings in presentation
            bool viewGridStatistics = TableSetting.SelectedTableTypes.Any(id => id == PresentationTableType.GridStatisticsTable);

            gridStatisticsTable.IsSelected = false || viewGridStatistics;
            model.Tables.Add(gridStatisticsTable);
            model.IsSettingsDefault = TableSetting.IsSettingsDefault();

            model.SelectedSpeciesObservationTableName = TableSetting.SpeciesObservationTable.GetSelectedObservationTableName();
            //var gridTaxonStatisticsTable = new PresentationTableTypeViewModel();
            //gridTaxonStatisticsTable.Title = Resource.PresentationGridTaxonStatisticsTable;
            //gridTaxonStatisticsTable.Id = (int)PresentationTableType.GridTaxonStatisticsTable;
            //gridTaxonStatisticsTable.PageInfo = null; // no settings in presentation
            //gridTaxonStatisticsTable.IsSelected = TableSetting.SelectedTableTypes.Any(id => id == PresentationTableType.GridTaxonStatisticsTable);
            //model.Tables.Add(gridTaxonStatisticsTable);

            return(model);
        }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.IsChildAction || Request.IsAjaxRequest() || Session == null)
            {
                return;
            }

            IUserContext user = GetCurrentUser();

            //Response.AppendHeader("Refresh",Convert.ToString((Session.Timeout * 30)) + ";URL=~/Home/Index");

            // set language
            if (Request.QueryString["lang"] != null)
            {
                ILocale locale;

                locale = CoreData.LocaleManager.GetUsedLocales(GetCurrentUser()).Get(Request.QueryString["lang"]);
                if (locale.IsNotNull())
                {
                    SetLanguage(locale.ISOCode);
                    if (user.IsAuthenticated())
                    {
                        user.Locale = locale;
                    }
                }
            }

            // Render image mode.
            // If we render the map as image, we use Google Mercator coordinate system and Google maps.
            if (Request.QueryString["renderImageMode"] != null)
            {
                ViewBag.RenderImageMode = true;
            }

            // Set LogOn information
            ViewBag.IsLoggedIn    = user.IsAuthenticated();
            ViewBag.UserName      = user.User.UserName;
            ViewBag.UserRole      = string.Empty;
            ViewBag.MultipleRoles = false;
            if (user.CurrentRoles.IsNotNull() && user.CurrentRoles.Count > 0)
            {
                ViewBag.UserRole = user.CurrentRole.IsNotNull() ? "(" + user.CurrentRole.Name + ")" : string.Empty;
                if (user.CurrentRoles.Count > 1 && user.CurrentRole.IsNotNull())
                {
                    ViewBag.MultipleRoles = true;
                }
            }

            // User message
            if (SessionHandler.UserMessages != null)
            {
                ViewBag.UserMessages = new List <UserMessage>(SessionHandler.UserMessages);
                SessionHandler.UserMessages.Clear();
            }

            // MySettings message
            if (SessionHandler.MySettingsMessage != null)
            {
                ViewBag.MySettingsMessage        = SessionHandler.MySettingsMessage;
                SessionHandler.MySettingsMessage = null;
            }

#if DEBUG
            ViewBag.Debug = true;
#else
            ViewBag.Debug = false;
#endif

            ActionDescriptor actionDescriptor = filterContext.ActionDescriptor;
            string           actionName       = actionDescriptor.ActionName;
            string           controllerName   = actionDescriptor.ControllerDescriptor.ControllerName;
            ViewBag.CookieName = string.Format("{0}{1}", controllerName, actionName);

            PageInfo currentPage = PageInfoManager.GetPageInfo(controllerName, actionName);
            if (currentPage.IsNotNull())
            {
                SessionHandler.CurrentPage = currentPage;
            }

            // Log history event
            var logEventHistoryItem = new LogEventHistoryItem();
            logEventHistoryItem.Action     = actionName;
            logEventHistoryItem.Controller = controllerName;
            logEventHistoryItem.Form       = Request.Form != null?Request.Form.PrettyPrint() : "-";

            logEventHistoryItem.HttpAction = Request.HttpMethod;
            logEventHistoryItem.Url        = Request.RawUrl;
            logEventHistoryItem.Date       = DateTime.Now;
            logEventHistoryItem.UserName   = user.User != null ? user.User.UserName : "******";
            logEventHistoryItem.UserRole   = user.CurrentRole != null ? user.CurrentRole.Identifier : "-";
            logEventHistoryItem.Referrer   = Request.UrlReferrer != null ? Request.UrlReferrer.OriginalString : "-";
            var logEventHistory = SessionHandler.LogEventHistory;
            if (logEventHistory == null)
            {
                logEventHistory = new LogEventHistory();
                SessionHandler.LogEventHistory = logEventHistory;
            }
            logEventHistory.HistoryItems.Add(logEventHistoryItem);
            if (logEventHistory.HistoryItems.Count > 10)
            {
                logEventHistory.HistoryItems.RemoveAt(0);
            }

            base.OnActionExecuting(filterContext);
        }