/// <summary> /// The update user profile. /// </summary> /// <param name="userName"> /// The user name. /// </param> private void UpdateUserProfile([NotNull] string userName) { var userProfile = YafUserProfile.GetProfile(userName); userProfile.Country = this.Country.SelectedItem != null ? this.Country.SelectedItem.Value.Trim() : string.Empty; userProfile.Region = this.Region.SelectedItem != null && this.Country.SelectedItem != null && this.Country.SelectedItem.Value.Trim().IsSet() ? this.Region.SelectedItem.Value.Trim() : string.Empty; userProfile.City = this.City.Text.Trim(); userProfile.Location = this.Location.Text.Trim(); userProfile.Homepage = this.HomePage.Text.Trim(); userProfile.ICQ = this.ICQ.Text.Trim(); userProfile.Facebook = this.Facebook.Text.Trim(); userProfile.Twitter = this.Twitter.Text.Trim(); userProfile.XMPP = this.Xmpp.Text.Trim(); userProfile.Skype = this.Skype.Text.Trim(); userProfile.RealName = this.Realname.Text.Trim(); userProfile.Occupation = this.Occupation.Text.Trim(); userProfile.Interests = this.Interests.Text.Trim(); userProfile.Gender = this.Gender.SelectedIndex; userProfile.Blog = this.Weblog.Text.Trim(); DateTime userBirthdate; if (this.Get <BoardSettings>().UseFarsiCalender&& this.CurrentCultureInfo.IsFarsiCulture()) { try { var persianDate = new PersianDate(this.Birthday.Text); userBirthdate = PersianDateConverter.ToGregorianDateTime(persianDate); } catch (Exception) { userBirthdate = DateTimeHelper.SqlDbMinTime().Date; } if (userBirthdate >= DateTimeHelper.SqlDbMinTime().Date) { userProfile.Birthday = userBirthdate.Date; } } else { DateTime.TryParse(this.Birthday.Text, this.CurrentCultureInfo, DateTimeStyles.None, out userBirthdate); if (userBirthdate >= DateTimeHelper.SqlDbMinTime().Date) { // Attention! This is stored in profile in the user timezone date userProfile.Birthday = userBirthdate.Date; } } userProfile.Save(); }
public void Can_Convert_Strings_ToDateTime() { PersianDate pd = new PersianDate(1380, 1, 1); DateTime converted = pd.ToDateTime(); DateTime dt = PersianDateConverter.ToGregorianDateTime(pd.ToString()); Assert.AreEqual(dt, converted); }
public void Can_Convert_Directly_To_Gregorian_Date_From_String() { var dt = PersianDateConverter.ToGregorianDateTime("1387/07/29 02:31:30"); //2008/10/20 Assert.That(dt.Year, Is.EqualTo(2008)); Assert.That(dt.Month, Is.EqualTo(10)); Assert.That(dt.Day, Is.EqualTo(20)); Assert.That(dt.Hour, Is.EqualTo(2)); Assert.That(dt.Minute, Is.EqualTo(31)); Assert.That(dt.Second, Is.EqualTo(30)); }
public static DateTime ToDateTime(this string persianDateStr) { if (persianDateStr.Length == 6) { var strDate = string.Format("13{0}/{1}/{2}", persianDateStr.Substring(0, 2), persianDateStr.Substring(2, 2), persianDateStr.Substring(4, 2)); DateTime dateTime = PersianDateConverter.ToGregorianDateTime(strDate); return(dateTime); } else { var strDate = string.Format("{0}/{1}/{2}", persianDateStr.Substring(0, 4), persianDateStr.Substring(4, 2), persianDateStr.Substring(6, 2)); DateTime dateTime = PersianDateConverter.ToGregorianDateTime(strDate); return(dateTime); } }
private static CompositeFilterDescriptor getDateRangeCompositeFilterConditionForInEquality(FilterDescriptor fItem, string filterVal) { var dateTimeValue = PersianDateConverter.ToGregorianDateTime(filterVal.Split(Convert.ToChar(_filterSeperator))[0] + " 00:00 Þ.Ù"); fItem.Operator = FilterOperator.IsLessThan; fItem.Value = dateTimeValue; var compositeFilter = new CompositeFilterDescriptor(); var secondFilterRule = new FilterDescriptor(); secondFilterRule.Operator = FilterOperator.IsGreaterThan; secondFilterRule.Value = ((DateTime)PersianDateConverter.ToGregorianDateTime(filterVal.Split(Convert.ToChar(_filterSeperator))[0] + " 00:00 Þ.Ù")).Add(new TimeSpan(23, 59, 59)); secondFilterRule.Member = fItem.Member; compositeFilter.LogicalOperator = FilterCompositionLogicalOperator.Or; compositeFilter.FilterDescriptors.Add(fItem); compositeFilter.FilterDescriptors.Add(secondFilterRule); return(compositeFilter); }
void UserBS_PositionChanged(object sender, EventArgs e) { EmptyFields(); CurrentUser = new UserEntity(); if (UserBS.Count == 0) { return; } CurrentUser = (UserEntity)UserBS.Current; txtUserName.Text = CurrentUser.UserName; txtFullName.Text = CurrentUser.UserFulName; CmbBDate.SelectedDateTime = PersianDateConverter.ToGregorianDateTime(new PersianDate(CurrentUser.UserbDate)); CmbUserType.SelectedIndex = CurrentUser.Active ? 1 : 0; txtUserName.Tag = CurrentUser.UserId; }
public ActionResult SaveComments(string sdate, string edate) { //string sdate = "1397/03/06"; //string edate = "1397/04/06"; PersianDate ssdate = PersianDate.Parse(Convert.ToDateTime(sdate).ToString("yyyy/MM/dd HH:mm:ss")); DateTime Sdate = PersianDateConverter.ToGregorianDateTime(ssdate); PersianDate eedate = PersianDate.Parse(Convert.ToDateTime(edate).ToString("yyyy/MM/dd HH:mm:ss")); DateTime Edate = PersianDateConverter.ToGregorianDateTime(eedate); //PersianDate pd= PersianDateConverter.ToPersianDate(dt); var select = db.users.Where(q => q.birth >= Sdate && q.birth <= Edate).ToList(); //foreach(var item in select) //{ // //dt.Add(Convert.ToDateTime(item)); //} return(Content("")); }
/// <summary> /// Populates data source and binds data to controls. /// </summary> private void BindData() { var baseSize = this.Get <BoardSettings>().MemberListPageSize; var currentPageIndex = this.PagerTop.CurrentPageIndex; this.PagerTop.PageSize = baseSize; var sinceDate = DateTime.UtcNow.AddDays(-this.Get <BoardSettings>().EventLogMaxDays); var toDate = DateTime.UtcNow; var ci = this.Get <ILocalization>().Culture; if (this.SinceDate.Text.IsSet()) { if (this.Get <BoardSettings>().UseFarsiCalender&& ci.IsFarsiCulture()) { var persianDate = new PersianDate(this.SinceDate.Text); sinceDate = PersianDateConverter.ToGregorianDateTime(persianDate); } else { DateTime.TryParse(this.SinceDate.Text, ci, DateTimeStyles.None, out sinceDate); } } if (this.ToDate.Text.IsSet()) { if (this.Get <BoardSettings>().UseFarsiCalender&& ci.IsFarsiCulture()) { var persianDate = new PersianDate(this.ToDate.Text); toDate = PersianDateConverter.ToGregorianDateTime(persianDate); } else { DateTime.TryParse(this.ToDate.Text, ci, DateTimeStyles.None, out toDate); } } // list event for this board var dt = this.GetRepository <Types.Models.EventLog>() .List( this.PageContext.PageUserID, this.Get <BoardSettings>().EventLogMaxMessages, this.Get <BoardSettings>().EventLogMaxDays, currentPageIndex, baseSize, sinceDate, toDate.AddDays(1).AddMinutes(-1), "1003,1004,1005,2000,2001,2002,2003"); this.List.DataSource = dt; this.PagerTop.Count = dt != null && dt.HasRows() ? dt.AsEnumerable().First().Field <int>("TotalRows") : 0; // bind data to controls this.DataBind(); if (this.List.Items.Count == 0) { this.NoInfo.Visible = true; } }
/// <summary> /// Update user Profile Info. /// </summary> private void UpdateUserProfile() { var userProfile = new ProfileInfo { Country = this.Country.SelectedItem != null?this.Country.SelectedItem.Value.Trim() : string.Empty, Region = this.Region.SelectedItem != null && this.Country.SelectedItem != null && this.Country.SelectedItem.Value.Trim().IsSet() ? this.Region.SelectedItem.Value.Trim() : string.Empty, City = this.City.Text.Trim(), Location = this.Location.Text.Trim(), Homepage = this.HomePage.Text.Trim(), ICQ = this.ICQ.Text.Trim(), Facebook = this.Facebook.Text.Trim(), Twitter = this.Twitter.Text.Trim(), XMPP = this.Xmpp.Text.Trim(), Skype = this.Skype.Text.Trim(), RealName = this.Realname.Text.Trim(), Occupation = this.Occupation.Text.Trim(), Interests = this.Interests.Text.Trim(), Gender = this.Gender.SelectedIndex, Blog = this.Weblog.Text.Trim() }; DateTime userBirthdate; if (this.Get <BoardSettings>().UseFarsiCalender&& this.CurrentCultureInfo.IsFarsiCulture()) { try { var persianDate = new PersianDate(this.Birthday.Text); userBirthdate = PersianDateConverter.ToGregorianDateTime(persianDate); } catch (Exception) { userBirthdate = DateTimeHelper.SqlDbMinTime().Date; } if (userBirthdate >= DateTimeHelper.SqlDbMinTime().Date) { userProfile.Birthday = userBirthdate.Date; } } else { DateTime.TryParse(this.Birthday.Text, this.CurrentCultureInfo, DateTimeStyles.None, out userBirthdate); if (userBirthdate >= DateTimeHelper.SqlDbMinTime().Date) { // Attention! This is stored in profile in the user timezone date userProfile.Birthday = userBirthdate.Date; } } this.User.Item2.Profile_Birthday = userProfile.Birthday; this.User.Item2.Profile_Blog = userProfile.Blog; this.User.Item2.Profile_Gender = userProfile.Gender; this.User.Item2.Profile_GoogleId = userProfile.GoogleId; this.User.Item2.Profile_GitHubId = userProfile.GitHubId; this.User.Item2.Profile_Homepage = userProfile.Homepage; this.User.Item2.Profile_ICQ = userProfile.ICQ; this.User.Item2.Profile_Facebook = userProfile.Facebook; this.User.Item2.Profile_FacebookId = userProfile.FacebookId; this.User.Item2.Profile_Twitter = userProfile.Twitter; this.User.Item2.Profile_TwitterId = userProfile.TwitterId; this.User.Item2.Profile_Interests = userProfile.Interests; this.User.Item2.Profile_Location = userProfile.Location; this.User.Item2.Profile_Country = userProfile.Country; this.User.Item2.Profile_Region = userProfile.Region; this.User.Item2.Profile_City = userProfile.City; this.User.Item2.Profile_Occupation = userProfile.Occupation; this.User.Item2.Profile_RealName = userProfile.RealName; this.User.Item2.Profile_Skype = userProfile.Skype; this.User.Item2.Profile_XMPP = userProfile.XMPP; this.User.Item2.Profile_LastSyncedWithDNN = userProfile.LastSyncedWithDNN; this.Get <IAspNetUsersHelper>().Update(this.User.Item2); }
/// <summary> /// The update user profile. /// </summary> /// <param name="userName"> /// The user name. /// </param> private void UpdateUserProfile([NotNull] string userName) { YafUserProfile userProfile = YafUserProfile.GetProfile(userName); userProfile.Country = this.Country.SelectedItem != null ? this.Country.SelectedItem.Value.Trim() : string.Empty; userProfile.Region = this.Region.SelectedItem != null && this.Country.SelectedItem != null && this.Country.SelectedItem.Value.Trim().IsSet() ? this.Region.SelectedItem.Value.Trim() : string.Empty; userProfile.City = this.City.Text.Trim(); userProfile.Location = this.Location.Text.Trim(); userProfile.Homepage = this.HomePage.Text.Trim(); userProfile.MSN = this.MSN.Text.Trim(); userProfile.YIM = this.YIM.Text.Trim(); userProfile.AIM = this.AIM.Text.Trim(); userProfile.ICQ = this.ICQ.Text.Trim(); userProfile.Facebook = this.Facebook.Text.Trim(); userProfile.Twitter = this.Twitter.Text.Trim(); userProfile.Google = this.Google.Text.Trim(); userProfile.XMPP = this.Xmpp.Text.Trim(); userProfile.Skype = this.Skype.Text.Trim(); userProfile.RealName = this.Realname.Text.Trim(); userProfile.Occupation = this.Occupation.Text.Trim(); userProfile.Interests = this.Interests.Text.Trim(); userProfile.Gender = this.Gender.SelectedIndex; userProfile.Blog = this.Weblog.Text.Trim(); DateTime userBirthdate; if (this.Get <YafBoardSettings>().UseFarsiCalender&& this.CurrentCultureInfo.IsFarsiCulture()) { var persianDate = new PersianDate(this.Birthday.Text); userBirthdate = PersianDateConverter.ToGregorianDateTime(persianDate); if (userBirthdate > DateTime.MinValue.Date) { userProfile.Birthday = userBirthdate.Date; } } else { DateTime.TryParse(this.Birthday.Text, this.CurrentCultureInfo, DateTimeStyles.None, out userBirthdate); if (userBirthdate > DateTime.MinValue.Date) { // Attention! This is stored in profile in the user timezone date userProfile.Birthday = userBirthdate.Date; } } userProfile.BlogServiceUrl = this.WeblogUrl.Text.Trim(); userProfile.BlogServiceUsername = this.WeblogUsername.Text.Trim(); userProfile.BlogServicePassword = this.WeblogID.Text.Trim(); try { // Sync to User Profile Mirror table while it's dirty SettingsPropertyValueCollection settingsPropertyValueCollection = userProfile.PropertyValues; LegacyDb.SetPropertyValues( PageContext.PageBoardID, UserMembershipHelper.ApplicationName(), this.currentUserID, settingsPropertyValueCollection); } catch (Exception ex) { this.Logger.Log( "Error while syncinng the User Profile", EventLogTypes.Error, this.PageContext.PageUserName, "Edit User Profile page", ex); } userProfile.Save(); }
/// <summary> /// Populates data source and binds data to controls. /// </summary> private void BindData() { var baseSize = this.PageSize.SelectedValue.ToType <int>(); var currentPageIndex = this.PagerTop.CurrentPageIndex; this.PagerTop.PageSize = baseSize; var sinceDate = DateTime.UtcNow.AddDays(-this.PageContext.BoardSettings.EventLogMaxDays); var toDate = DateTime.UtcNow; var ci = this.Get <ILocalization>().Culture; if (this.SinceDate.Text.IsSet()) { if (this.PageContext.BoardSettings.UseFarsiCalender && ci.IsFarsiCulture()) { var persianDate = new PersianDate(this.SinceDate.Text.PersianNumberToEnglish()); sinceDate = PersianDateConverter.ToGregorianDateTime(persianDate); } else { DateTime.TryParse(this.SinceDate.Text, ci, DateTimeStyles.None, out sinceDate); } } if (this.ToDate.Text.IsSet()) { if (this.PageContext.BoardSettings.UseFarsiCalender && ci.IsFarsiCulture()) { var persianDate = new PersianDate(this.ToDate.Text.PersianNumberToEnglish()); toDate = PersianDateConverter.ToGregorianDateTime(persianDate); } else { DateTime.TryParse(this.ToDate.Text, ci, DateTimeStyles.None, out toDate); } } // list event for this board var list = this.GetRepository <Types.Models.EventLog>() .ListPaged( this.PageContext.PageBoardID, this.PageContext.BoardSettings.EventLogMaxMessages, this.PageContext.BoardSettings.EventLogMaxDays, currentPageIndex, baseSize, sinceDate, toDate.AddDays(1).AddMinutes(-1), null, true); this.List.DataSource = list; this.PagerTop.Count = list != null && list.Any() ? list.FirstOrDefault().TotalRows : 0; // bind data to controls this.DataBind(); if (this.List.Items.Count == 0) { this.NoInfo.Visible = true; } }
public static DateTime ToGeorgianDate(this PersianDate value) { return(PersianDateConverter.ToGregorianDateTime(value)); }
/// <summary> /// Populates data source and binds data to controls. /// </summary> private void BindData() { int baseSize = this.Get <YafBoardSettings>().MemberListPageSize; int nCurrentPageIndex = this.PagerTop.CurrentPageIndex; this.PagerTop.PageSize = baseSize; var sinceDate = DateTime.UtcNow.AddDays(-this.Get <YafBoardSettings>().EventLogMaxDays); var toDate = DateTime.UtcNow; var ci = this.Get <ILocalization>().Culture; if (this.SinceDate.Text.IsSet()) { if (this.Get <YafBoardSettings>().UseFarsiCalender&& ci.IsFarsiCulture()) { var persianDate = new PersianDate(this.SinceDate.Text); sinceDate = PersianDateConverter.ToGregorianDateTime(persianDate); } else { DateTime.TryParse(this.SinceDate.Text, ci, DateTimeStyles.None, out sinceDate); } } if (this.ToDate.Text.IsSet()) { if (this.Get <YafBoardSettings>().UseFarsiCalender&& ci.IsFarsiCulture()) { var persianDate = new PersianDate(this.ToDate.Text); toDate = PersianDateConverter.ToGregorianDateTime(persianDate); } else { DateTime.TryParse(this.ToDate.Text, ci, DateTimeStyles.None, out toDate); } } // list event for this board DataTable dt = this.GetRepository <EventLog>() .List( this.PageContext.PageUserID, this.Get <YafBoardSettings>().EventLogMaxMessages, this.Get <YafBoardSettings>().EventLogMaxDays, nCurrentPageIndex, baseSize, sinceDate, toDate.AddDays(1).AddMinutes(-1), this.Types.SelectedValue.Equals("-1") ? null : this.Types.SelectedValue); this.List.DataSource = dt; this.PagerTop.Count = dt != null && dt.HasRows() ? dt.AsEnumerable().First().Field <int>("TotalRows") : 0; // bind data to controls this.DataBind(); }
private static void getDateRangeCompositeFilterConditionForGreaterThanOrEqual(FilterDescriptor fItem, string filterVal) { var dateTimeValue = PersianDateConverter.ToGregorianDateTime(filterVal.Split(Convert.ToChar(_filterSeperator))[0] + " 00:00 Þ.Ù"); fItem.Value = dateTimeValue; }
/// <summary> /// Converts the PersianDate to a DateTime equivalant. /// </summary> /// <param name="persianDate"></param> /// <returns></returns> public static DateTime ToDateTime(this PersianDate persianDate) { return(PersianDateConverter.ToGregorianDateTime(persianDate)); }