51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
namespace Activities
|
|
{
|
|
public class Invitation
|
|
{
|
|
public static string GetValue(string prompt)
|
|
{
|
|
Console.Write(prompt);
|
|
string? value = Console.ReadLine();
|
|
if (value == null)
|
|
{
|
|
Console.WriteLine("No input provided.");
|
|
value = GetValue(prompt);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public static DateOnly GetDate(string prompt)
|
|
{
|
|
string value = GetValue(prompt);
|
|
DateOnly date;
|
|
try
|
|
{
|
|
date = DateOnly.Parse(value);
|
|
}
|
|
catch
|
|
{
|
|
Console.WriteLine("Invalid date provided.");
|
|
date = GetDate(prompt);
|
|
}
|
|
return date;
|
|
}
|
|
|
|
public static bool GetResponse(string prompt)
|
|
{
|
|
string value = GetValue(prompt);
|
|
if (value.Equals("y", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
else if (value.Equals("n", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Invalid response provided.");
|
|
return GetResponse(prompt);
|
|
}
|
|
}
|
|
}
|
|
} |