/// <summary> /// Returns the WQX timezone code based on the supplied time zone and date /// </summary> /// <param name="dt">Sample Date</param> /// <param name="TimeZoneName"></param> /// <param name="TimeZoneStandardCode">WQX Standard Code</param> /// <param name="TimeZoneDaylightCode">WQX Daylight Savings Code</param> /// <returns></returns> //TODO: Handle session in core public static string GetWQXTimeZoneByDate(DateTime dt, IHttpContextAccessor httpcontextaccessor) { try { //string OrgID = (HttpContext.Current.Session["OrgID"] ?? "").ToString(); string OrgID = httpcontextaccessor.HttpContext.Session.GetString("OrgID"); //see if session has any timezone value //if ((HttpContext.Current.Session[OrgID + "_TZ"] ?? "") == "") if ((httpcontextaccessor.HttpContext.Session.GetString("OrgID" + "_TZ") ?? "") == "") { //no default time zone found in session, need to retrieve from database string TimeZoneID = ""; TWqxOrganization org = db_WQX.GetWQX_ORGANIZATION_ByID(OrgID); if (org != null) { if ((org.DefaultTimezone ?? "") != "") { TimeZoneID = org.DefaultTimezone; } else { TimeZoneID = db_Ref.GetT_OE_APP_SETTING("Default Timezone"); } } TWqxRefDefaultTimeZone tz = db_Ref.GetT_WQX_REF_DEFAULT_TIME_ZONE_ByName(TimeZoneID); if (tz != null) { //HttpContext.Current.Session[OrgID + "_TZ"] = tz.OfficialTimeZoneName; httpcontextaccessor.HttpContext.Session.SetString("OrgID" + "_TZ", tz.OfficialTimeZoneName); //HttpContext.Current.Session[OrgID + "_TZ_S"] = tz.WqxCodeStandard; httpcontextaccessor.HttpContext.Session.SetString("OrgID" + "_TZ_S", tz.WqxCodeStandard); //HttpContext.Current.Session[OrgID + "_TZ_D"] = tz.WqxCodeDaylight; httpcontextaccessor.HttpContext.Session.SetString("OrgID" + "_TZ_D", tz.WqxCodeDaylight); } } //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(HttpContext.Current.Session[OrgID + "_TZ"].ToString()); TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(httpcontextaccessor.HttpContext.Session.GetString("OrgID" + "_TZ")); if (tzi.IsDaylightSavingTime(dt)) { //return HttpContext.Current.Session[OrgID + "_TZ_S"].ToString(); return(httpcontextaccessor.HttpContext.Session.GetString("OrgID" + "_TZ_S")); } else { //return HttpContext.Current.Session[OrgID + "_TZ_D"].ToString(); return(httpcontextaccessor.HttpContext.Session.GetString("OrgID" + "_TZ_D")); } } catch { return(""); } }
public static TWqxOrganization[] getOrganizations() { var orgs = new TWqxOrganization[] { new TWqxOrganization { OrgFormalName = "abc", OrgId = "123" } }; return(orgs); }