Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions checkpoint3/.vscode/launch.json
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}"
}
,]
}
15 changes: 15 additions & 0 deletions checkpoint3/.vscode/tasks.json
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"
}
]
}
296 changes: 296 additions & 0 deletions checkpoint3/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
using System;
Copy link

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.

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");
}
}
}
13 changes: 13 additions & 0 deletions checkpoint3/checkpoint3.csproj
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 added checkpoint3/tasks.db
Binary file not shown.
28 changes: 28 additions & 0 deletions cp3 backup/.vscode/launch.json
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}"
}
,]
}
Loading