forked from AustinCodingAcademy/csharp-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Checkpoint3 #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jamestglh
wants to merge
2
commits into
master
Choose a base branch
from
checkpoint3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Checkpoint3 #17
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| // Use IntelliSense to find out which attributes exist for C# debugging | ||
| // Use hover for the description of the existing attributes | ||
| // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": ".NET Core Launch (console)", | ||
| "type": "coreclr", | ||
| "request": "launch", | ||
| "preLaunchTask": "build", | ||
| // If you have changed target frameworks, make sure to update the program path. | ||
| "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/checkpoint3.dll", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder}", | ||
| // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window | ||
| "console": "internalConsole", | ||
| "stopAtEntry": false, | ||
| "internalConsoleOptions": "openOnSessionStart" | ||
| }, | ||
| { | ||
| "name": ".NET Core Attach", | ||
| "type": "coreclr", | ||
| "request": "attach", | ||
| "processId": "${command:pickProcess}" | ||
| } | ||
| ,] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "version": "2.0.0", | ||
| "tasks": [ | ||
| { | ||
| "label": "build", | ||
| "command": "dotnet", | ||
| "type": "process", | ||
| "args": [ | ||
| "build", | ||
| "${workspaceFolder}/checkpoint3.csproj" | ||
| ], | ||
| "problemMatcher": "$msCompile" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,296 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.Collections.Generic; | ||
| using Microsoft.EntityFrameworkCore; | ||
|
|
||
|
|
||
| namespace checkpoint3 | ||
| { | ||
| class Program | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| TaskContext taskContext = new TaskContext(); | ||
| taskContext.Database.EnsureCreated(); | ||
| Console.WriteLine("Welcome to your task list."); | ||
| MainMenu(); | ||
|
|
||
| void MainMenu() | ||
| { | ||
| System.Console.WriteLine(); | ||
| System.Console.WriteLine("Please choose an option: "); | ||
| System.Console.WriteLine("1. List ALL tasks"); | ||
| System.Console.WriteLine("2. List UNFINISHED tasks"); | ||
| System.Console.WriteLine("3. List FINISHED tasks"); | ||
| System.Console.WriteLine("4. Add a task"); | ||
| System.Console.WriteLine("5. Modify a task"); | ||
| System.Console.WriteLine("6. Mark task as finished / unfinished"); | ||
| System.Console.WriteLine("7. Delete a task"); | ||
| System.Console.WriteLine("8. Quit"); | ||
| string userInput = Console.ReadLine(); | ||
| if (userInput == "1") | ||
| { | ||
| Console.Clear(); | ||
| TaskLister(); | ||
| MainMenu(); | ||
| } | ||
| else if (userInput == "2") | ||
| { | ||
| Console.Clear(); | ||
| TaskListerUnfinished(); | ||
| MainMenu(); | ||
| } | ||
| else if (userInput == "3") | ||
| { | ||
| Console.Clear(); | ||
| TaskListerFinished(); | ||
| MainMenu(); | ||
| } | ||
| else if (userInput == "4") | ||
| { | ||
| Console.Clear(); | ||
| TaskCreator(); | ||
| MainMenu(); | ||
| } | ||
| else if (userInput == "5") | ||
| { | ||
| Console.Clear(); | ||
| TaskModifier_db(); | ||
| MainMenu(); | ||
| } | ||
| else if (userInput == "6") | ||
| { | ||
| Console.Clear(); | ||
| TaskStatusUpdater(); | ||
| MainMenu(); | ||
| } | ||
| else if (userInput == "7") | ||
| { | ||
| Console.Clear(); | ||
| TaskDeleter(); | ||
| MainMenu(); | ||
| } | ||
| else if (userInput == "8") | ||
| { | ||
| Environment.Exit(0); | ||
| } | ||
| else | ||
| { | ||
| System.Console.WriteLine("Sorry bud, invalid input."); | ||
| MainMenu(); | ||
| } | ||
| } | ||
| void TaskLister() | ||
| { | ||
| string status = ""; | ||
| foreach (Task t in taskContext.tasks_db) | ||
| { | ||
| if (t.isComplete) | ||
| { | ||
| status = "complete"; | ||
| } | ||
| else | ||
| { | ||
| status = "incomplete"; | ||
| } | ||
| System.Console.WriteLine("Task " + t.id + ": " + t.description + " is " + status + ". Due on " + t.dueDate.ToString("MM/dd/yyyy") + ". Priority is " + t.priority + "."); | ||
| } | ||
| } | ||
| void TaskListerUnfinished() | ||
| { | ||
| foreach (Task t in taskContext.tasks_db) | ||
| { | ||
| if (!t.isComplete) | ||
| { | ||
| System.Console.WriteLine("Task " + t.id + ": " + t.description + " is unfinshed. Due on " + t.dueDate.ToString("MM/dd/yyyy") + ". Priority is " + t.priority + "."); | ||
| } | ||
| } | ||
| } | ||
| void TaskListerFinished() | ||
| { | ||
| foreach (Task t in taskContext.tasks_db) | ||
| { | ||
| if (t.isComplete) | ||
| { | ||
| System.Console.WriteLine("Task " + t.id + ": " + t.description + " is complete. Due on " + t.dueDate.ToString("MM/dd/yyyy") + ". Priority is " + t.priority + "."); | ||
| } | ||
| } | ||
| } | ||
| void TaskCreator() | ||
| { | ||
| System.Console.WriteLine("Please enter a description of your task"); | ||
| string description = Console.ReadLine(); | ||
| System.Console.WriteLine("Please enter a priority for \"" + description + "\". You can just write \"High\", \"Medium\", or \"Low\", or really write whatever you want."); | ||
| string priority = Console.ReadLine(); | ||
| DateTime dueDate = new DateTime(); | ||
| ParseDateTimeInput(); | ||
| void ParseDateTimeInput() | ||
| { | ||
| System.Console.WriteLine("Please enter a due date. Enter using the format \"Month Day, Year\" or \"MM/DD/YYYY\" (example: January 1, 1979). "); | ||
| string dueDateInput = Console.ReadLine(); | ||
| try | ||
| { | ||
| dueDate = DateTime.Parse(dueDateInput); | ||
| AddTaskToList(); | ||
| } | ||
| catch (FormatException) | ||
| { | ||
| Console.WriteLine("Unable to parse '{0}', please try again.", dueDateInput); | ||
| ParseDateTimeInput(); | ||
| } | ||
| } | ||
| void AddTaskToList() | ||
| { | ||
| int id = taskContext.tasks_db.Max(t => t.id) + 1; | ||
| taskContext.tasks_db.Add(new Task(id, false, description, priority, dueDate)); | ||
| taskContext.SaveChanges(); | ||
| } | ||
| } | ||
| void TaskDeleter() | ||
| { | ||
| System.Console.WriteLine("Which task do you want to delete?"); | ||
| TaskLister(); | ||
| string userInput = Console.ReadLine(); | ||
| int userInputInt = 0; | ||
| try | ||
| { | ||
| userInputInt = int.Parse(userInput); | ||
| } | ||
| catch (FormatException) | ||
| { | ||
| Console.WriteLine("Unable to parse '{0}', please try again", userInput); | ||
| } | ||
| foreach (Task t in taskContext.tasks_db) | ||
| { | ||
| if (userInputInt == t.id) | ||
| { | ||
| taskContext.tasks_db.Remove(t); | ||
| taskContext.SaveChanges(); | ||
| } | ||
| } | ||
| } | ||
| void TaskModifier_db() | ||
| { | ||
| System.Console.WriteLine("Which task do you want to modify? Choose a task number"); | ||
| TaskLister(); | ||
| string userInput = Console.ReadLine(); | ||
| int userInputInt = 0; | ||
| try | ||
| { | ||
| userInputInt = int.Parse(userInput); | ||
| } | ||
| catch (FormatException) | ||
| { | ||
| Console.WriteLine("Unable to parse '{0}', please try again", userInput); | ||
| } | ||
| foreach (Task t in taskContext.tasks_db) | ||
| { | ||
| if (userInputInt == t.id) | ||
| { | ||
| System.Console.WriteLine("Do you want to modify 1. the description, 2. the priority, or 3. due date?"); | ||
| string response = Console.ReadLine(); | ||
| if (response == "1") | ||
| { | ||
| System.Console.WriteLine("Please enter a new description:"); | ||
| t.description = Console.ReadLine(); | ||
| } | ||
| else if (response == "2") | ||
| { | ||
| System.Console.WriteLine("Please enter a new priority:"); | ||
| t.priority = Console.ReadLine(); | ||
| } | ||
| else if (response == "3") | ||
| { | ||
| ParseDateTimeUpdate(); | ||
| } | ||
| t.id = userInputInt; | ||
| System.Console.WriteLine("id for this task is " + t.id); | ||
| } | ||
| void ParseDateTimeUpdate() | ||
| { | ||
| System.Console.WriteLine("Please enter a new due date. Enter using the format \"Month Day, Year\" (example: January 1, 1979) :"); | ||
| string dueDateInput = Console.ReadLine(); | ||
| try | ||
| { | ||
| t.dueDate = DateTime.Parse(dueDateInput); | ||
| Console.WriteLine("Due date changed to " + t.dueDate.ToString("MM/dd/yyyy")); | ||
| } | ||
| catch (FormatException) | ||
| { | ||
| Console.WriteLine("Unable to parse '{0}', please try again", dueDateInput); | ||
| ParseDateTimeUpdate(); | ||
| } | ||
| } | ||
| taskContext.SaveChanges(); | ||
| } | ||
| } | ||
| void TaskStatusUpdater() | ||
| { | ||
| System.Console.WriteLine("Which task do you want to update the status on? Choose a task number"); | ||
| TaskLister(); | ||
| string userInput = Console.ReadLine(); | ||
| int userInputInt = 0; | ||
| try | ||
| { | ||
| userInputInt = int.Parse(userInput); | ||
| } | ||
| catch (FormatException) | ||
| { | ||
| Console.WriteLine("Unable to parse '{0}', please try again", userInput); | ||
| } | ||
| foreach (Task t in taskContext.tasks_db) | ||
| { | ||
| if (userInputInt == t.id) | ||
| { | ||
| if (t.isComplete) | ||
| { | ||
| System.Console.WriteLine("Do you want to mark this task as INCOMPLETE? y/n"); | ||
| userInput = Console.ReadLine(); | ||
| if (userInput.ToLower() == "y") | ||
| { | ||
| t.isComplete = false; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| System.Console.WriteLine("Do you want to mark this task as COMPLETE? y/n"); | ||
| userInput = Console.ReadLine(); | ||
| if (userInput.ToLower() == "y") | ||
| { | ||
| t.isComplete = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| System.Console.WriteLine("Task updated!"); | ||
| taskContext.SaveChanges(); | ||
| } | ||
| } | ||
| } | ||
| public class Task | ||
| { | ||
| public int id { get; set; } | ||
| public bool isComplete = false; | ||
| public string description { get; set; } | ||
| public string priority { get; set; } | ||
| public DateTime dueDate { get; set; } | ||
|
|
||
| public Task(int id, bool isComplete, string description, string priority, DateTime dueDate) | ||
| { | ||
| this.id = id; | ||
| this.isComplete = isComplete; | ||
| this.description = description; | ||
| this.priority = priority; | ||
| this.dueDate = dueDate; | ||
| } | ||
| public Task() { } | ||
| } | ||
| public class TaskContext : DbContext | ||
| { | ||
| public DbSet<Task> tasks_db { get; set; } | ||
| protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
| { | ||
| optionsBuilder.UseSqlite("Filename=./tasks.db"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.3" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.3" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| // Use IntelliSense to find out which attributes exist for C# debugging | ||
| // Use hover for the description of the existing attributes | ||
| // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": ".NET Core Launch (console)", | ||
| "type": "coreclr", | ||
| "request": "launch", | ||
| "preLaunchTask": "build", | ||
| // If you have changed target frameworks, make sure to update the program path. | ||
| "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/checkpoint3.dll", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder}", | ||
| // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window | ||
| "console": "internalConsole", | ||
| "stopAtEntry": false, | ||
| "internalConsoleOptions": "openOnSessionStart" | ||
| }, | ||
| { | ||
| "name": ".NET Core Attach", | ||
| "type": "coreclr", | ||
| "request": "attach", | ||
| "processId": "${command:pickProcess}" | ||
| } | ||
| ,] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how you used exceptions. But you code could use more comments.