From 7fcde4401f6ebf0023e61ddabaa4a6c5b7cf6553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A4seToatz?= Date: Wed, 25 Sep 2024 19:55:58 +0200 Subject: [PATCH] Initial commit --- .gitignore | 3 +++ Activities.csproj | 10 ++++++++++ Activities.sln | 25 +++++++++++++++++++++++ Activity.cs | 24 ++++++++++++++++++++++ Invitation.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++ Person.cs | 18 +++++++++++++++++ Program.cs | 39 ++++++++++++++++++++++++++++++++++++ 7 files changed, 170 insertions(+) create mode 100644 .gitignore create mode 100644 Activities.csproj create mode 100644 Activities.sln create mode 100644 Activity.cs create mode 100644 Invitation.cs create mode 100644 Person.cs create mode 100644 Program.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5df6da6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.vs +/bin +/obj \ No newline at end of file diff --git a/Activities.csproj b/Activities.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/Activities.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Activities.sln b/Activities.sln new file mode 100644 index 0000000..731441c --- /dev/null +++ b/Activities.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34701.34 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Activities", "Activities.csproj", "{D81F6378-2184-4380-AF69-D03738C63DA6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D81F6378-2184-4380-AF69-D03738C63DA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D81F6378-2184-4380-AF69-D03738C63DA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D81F6378-2184-4380-AF69-D03738C63DA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D81F6378-2184-4380-AF69-D03738C63DA6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0D40D0B7-0470-4089-948E-E14CE210C76F} + EndGlobalSection +EndGlobal diff --git a/Activity.cs b/Activity.cs new file mode 100644 index 0000000..c7b7df4 --- /dev/null +++ b/Activity.cs @@ -0,0 +1,24 @@ +namespace Activities +{ + public class Activity(string title, DateOnly date, string description) + { + private readonly string title = title; + private readonly DateOnly date = date; + private readonly string description = description; + + public string GetTitle() + { + return this.title; + } + + public DateOnly GetDate() + { + return this.date; + } + + public string GetDescription() + { + return this.description; + } + } +} \ No newline at end of file diff --git a/Invitation.cs b/Invitation.cs new file mode 100644 index 0000000..c0cdc1e --- /dev/null +++ b/Invitation.cs @@ -0,0 +1,51 @@ +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); + } + } + } +} \ No newline at end of file diff --git a/Person.cs b/Person.cs new file mode 100644 index 0000000..280a3c1 --- /dev/null +++ b/Person.cs @@ -0,0 +1,18 @@ +namespace Activities +{ + public class Person(string name, string email) + { + private readonly string name = name; + private readonly string email = email; + + public string GetName() + { + return this.name; + } + + public string GetEmail() + { + return this.email; + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..63c1f8e --- /dev/null +++ b/Program.cs @@ -0,0 +1,39 @@ +using System.Diagnostics; +using System; + +namespace Activities +{ + public class Program + { + static void Main() + { + Console.WriteLine("Creating a new invitation. Please enter your details."); + string organisorName = Invitation.GetValue("Your name: "); + string organisorEmail = Invitation.GetValue("Your email: "); + Person organisor = new(organisorName, organisorEmail); + Console.Clear(); + Console.WriteLine("Enter activity details."); + string activityTitle = Invitation.GetValue("Activity title: "); + DateOnly activityDate = Invitation.GetDate("Activity date (DD/MM/YYYY): "); + string activityDescription = Invitation.GetValue("Activity description: "); + Activity activity = new(activityTitle, activityDate, activityDescription); + Console.Clear(); + List invitees = []; + bool addInvitee = true; + while (addInvitee) + { + Console.WriteLine("Enter invitee details."); + string inviteeName = Invitation.GetValue("Invitee name: "); + string inviteeEmail = Invitation.GetValue("Invitee email: "); + Person invitee = new(inviteeName, inviteeEmail); + invitees.Add(invitee); + addInvitee = Invitation.GetResponse("Do you wish to add another invitee? (Y/N): "); + } + Console.Clear(); + foreach (Person invitee in invitees) + { + Console.WriteLine($"Dear {invitee.GetName()}, you have been invited for \"{activity.GetTitle()}\" on {activity.GetDate()}. Description: {activity.GetDescription()}\n\nKind regards,\n{organisor.GetName()}"); + } + } + } +} \ No newline at end of file