Im curious if my approach is correct in this case:
I would like to get two DateTimes from a public property, but one of the dates i want them only if a user has purchase a feature or if he has not activate a switch, otherwise i want to get the same DateTime twice.
More specifically, the way im getting the values now is this:
public class MainApplication : Application
{
public DateTime DateFrom { get; set; } = DateTime.Now;
public DateTime DateTo { get; set; } = DateTime.Now;
}
AnotherClass
{
SearchButton.Click += async (sender, e) =>
{
await SearchFoNumbersAsync(ApplicationState.DateFrom, ApplicationState.DateTo, DailySearchSwitch.Checked, SeperateCheckBox.Checked, ShowListsCheckBox.Checked).ConfigureAwait(false);
};
private async Task SearchFoNumbersAsync(DateTime dateFrom, DateTime dateTo, bool isDailySearchEnabled, bool seperateSearch, bool showDrawTime)
{
((MainActivity)Activity).DisplayLoadingMessage(true, GetString(Resource.String.Common_SearchTitle), GetString(Resource.String.Common_SearchMessage));
if (isDailySearchEnabled || !PurchaseFunctions.HasPurchasedDateRangeSelection())
dateTo = dateFrom;
...
}
}
So i want to get DateTo only
if (isDailySearchEnabled || !PurchaseFunctions.HasPurchasedDateRangeSelection()), otherwise i want to get the DateFrom value in the place of DateTo
Im sure this approach is not correct so im thinking i should get the DateTo this way:
public class MainApplication : Application
{
public DateTime DateFrom { get; set; } = DateTime.Now;
private DateTime DateTo { get; set; } = DateTime.Now;
public DateTime GetDateTo(bool isDailySearchEnabled)
{
if (isDailySearchEnabled || !PurchaseFunctions.HasPurchasedDateRangeSelection())
return DateFrom;
else
return DateTo;
}
public void SetDateTo(DateTime dateTime)
{
DateTo = dateTime;
}
}
Is my new approach a good idea?