Esempio n. 1
0
 public static DateTime CurrentTimeForUser(UserInfo userInfo)
 {
     if (userInfo == null || userInfo.UserID == -1)
     {
         //Obtain PortalSettings from Current Context
         PortalSettings objSettings = PortalController.GetCurrentPortalSettings();
         return(TimeZoneInfo.ConvertTime(SystemDateTime.GetCurrentTimeUtc(), TimeZoneInfo.Utc, objSettings.TimeZone));
     }
     else
     {
         return(TimeZoneInfo.ConvertTime(SystemDateTime.GetCurrentTimeUtc(), TimeZoneInfo.Utc, userInfo.Profile.PreferredTimeZone));
     }
 }
Esempio n. 2
0
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Gets current time in User's timezone
 /// </summary>
 /// <history>
 ///     [aprasad]	07/19/2011	Added
 /// </history>
 /// -----------------------------------------------------------------------------
 public DateTime LocalTime()
 {
     return(LocalTime(SystemDateTime.GetCurrentTimeUtc()));
 }
Esempio n. 3
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   Provides a list of context variables for XML output
        /// </summary>
        /// <returns>DataTable with all context variables</returns>
        /// -----------------------------------------------------------------------------
        public DataTable Context(ModuleInfo moduleInfo, UserInfo userInfo, string searchInput, string orderBy,
                                 string orderDirection, string paging)
        {
            var request = HttpContext.Current.Request;

            orderBy        = orderBy.AsString("UserDefinedRowId");
            orderDirection = orderDirection.AsString("ascending");

            var contextTable = new DataTable("Context");

            contextTable.Columns.Add("ModuleId", typeof(int));
            contextTable.Columns.Add("TabId", typeof(int));
            contextTable.Columns.Add("TabName", typeof(string));
            contextTable.Columns.Add("PortalId", typeof(int));
            contextTable.Columns.Add("UserName", typeof(string));
            contextTable.Columns.Add("BestUserName", typeof(string));
            //obsolete, please use DisplayName
            contextTable.Columns.Add("DisplayName", typeof(string));
            contextTable.Columns.Add("ApplicationPath", typeof(string));
            contextTable.Columns.Add("HomePath", typeof(string));
            contextTable.Columns.Add("UserRoles", typeof(string));
            contextTable.Columns.Add("IsAdministratorRole", typeof(bool));
            contextTable.Columns.Add("Parameter", typeof(string));
            contextTable.Columns.Add("OrderBy", typeof(string));
            contextTable.Columns.Add("OrderDirection", typeof(string));
            contextTable.Columns.Add("CurrentCulture", typeof(string));
            contextTable.Columns.Add("LocalizedString_Search", typeof(string));
            contextTable.Columns.Add("LocalizedString_Page", typeof(string));
            contextTable.Columns.Add("LocalizedString_Of", typeof(string));
            contextTable.Columns.Add("LocalizedString_First", typeof(string));
            contextTable.Columns.Add("LocalizedString_Previous", typeof(string));
            contextTable.Columns.Add("LocalizedString_Next", typeof(string));
            contextTable.Columns.Add("LocalizedString_Last", typeof(string));
            contextTable.Columns.Add("NowInTicks", typeof(long));
            contextTable.Columns.Add("TodayInTicks", typeof(long));
            contextTable.Columns.Add("TicksPerDay", typeof(long));
            contextTable.Columns.Add("LocalizedDate", typeof(string));
            contextTable.Columns.Add("Now", typeof(DateTime));

            if (paging != string.Empty)
            {
                contextTable.Columns.Add("Paging", typeof(int));
            }
            var row = contextTable.NewRow();

            row["ModuleId"] = moduleInfo.ModuleID;
            row["TabId"]    = moduleInfo.TabID;
            row["TabName"]  = moduleInfo.ParentTab.TabName;
            row["PortalId"] = moduleInfo.PortalID;

            // null username handled by extension method
            row["DisplayName"] = userInfo.GetSafeDisplayname();
            row["UserName"]    = userInfo.GetSafeUsername();

            row["BestUserName"] = row["DisplayName"];
            var portalSettings = Globals.GetPortalSettings();

            row["HomePath"]        = portalSettings.HomeDirectory;
            row["ApplicationPath"] = request.ApplicationPath == "/" ? "" : request.ApplicationPath;
            row["UserRoles"]       = ModuleSecurity.RoleNames(userInfo);
            if (ModuleSecurity.IsAdministrator())
            {
                row["IsAdministratorRole"] = true;
            }
            row["Parameter"]      = searchInput;
            row["OrderBy"]        = orderBy;
            row["OrderDirection"] = orderDirection == "DESC" ? "descending" : "ascending";
            row["CurrentCulture"] = new Localization().CurrentCulture;
            if (paging != string.Empty)
            {
                row["Paging"] = int.Parse(paging);
            }
            row["LocalizedString_Search"]   = Localization.GetString("Search.Text", Definition.SharedRessources);
            row["LocalizedString_Page"]     = Localization.GetString("PagingPage.Text", Definition.SharedRessources);
            row["LocalizedString_of"]       = Localization.GetString("PagingOf.Text", Definition.SharedRessources);
            row["LocalizedString_First"]    = Localization.GetString("PagingFirst.Text", Definition.SharedRessources);
            row["LocalizedString_Previous"] = Localization.GetString("PagingPrevious.Text", Definition.SharedRessources);
            row["LocalizedString_Next"]     = Localization.GetString("PagingNext.Text", Definition.SharedRessources);
            row["LocalizedString_Last"]     = Localization.GetString("PagingLast.Text", Definition.SharedRessources);
            var d        = SystemDateTime.GetCurrentTimeUtc();
            var timeZone = userInfo.Username != null
                                  ? userInfo.Profile.PreferredTimeZone
                                  : portalSettings.TimeZone;

            d                    = TimeZoneInfo.ConvertTimeFromUtc(d, timeZone);
            row["Now"]           = d;
            row["LocalizedDate"] = d.ToString("g", Thread.CurrentThread.CurrentCulture);
            row["NowInTicks"]    = d.Ticks;
            row["TodayInTicks"]  = d.Date.Ticks;
            row["TicksPerDay"]   = TimeSpan.TicksPerDay;
            contextTable.Rows.Add(row);

            return(contextTable);
        }