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
3 changes: 3 additions & 0 deletions checkpoint3/.vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file added checkpoint3/.vs/checkpoint3/v15/.suo
Binary file not shown.
Binary file added checkpoint3/.vs/slnx.sqlite
Binary file not shown.
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.2/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"
}
]
}
106 changes: 106 additions & 0 deletions checkpoint3/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;



namespace checkpoint3
{
class Program
{
static void Main(string[] args)
{
DbContextOptionsBuilder<Utils> builder = new DbContextOptionsBuilder<Utils>();
builder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=BlogDb;Trusted_Connection=true");
DbContextOptions<Utils> opts = builder.Options;
Utils context = new Utils(opts);

context.Database.EnsureCreated();

ToDo todo1 = new ToDo();
ToDo todo2 = new ToDo();
ToDo todo3 = new ToDo();
ToDo todo4 = new ToDo();

context.CreateToDo(todo1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on Create, Edit and List All, but you are missing Delete, List by ID and not using EF to save your ToDos between application runs.

System.Console.WriteLine("What task do you want to complete?");
todo1.Description = Console.ReadLine();
context.PrintToDos(context.ToDos);
context.CreateToDo(todo2);
Console.WriteLine("Enter additional tasks if needed:");
todo2.Description = Console.ReadLine();
context.PrintToDos(context.ToDos);
context.CreateToDo(todo3);
Console.WriteLine("Enter additional tasks if needed:");
todo3.Description = Console.ReadLine();
context.PrintToDos(context.ToDos);
context.CreateToDo(todo4);
Console.WriteLine("Enter additional tasks if needed:");
todo4.Description = Console.ReadLine();
context.PrintToDos(context.ToDos);

System.Console.WriteLine("Id of task you want to update: ");
int id = Convert.ToInt32(Console.ReadLine());
System.Console.WriteLine("What would you like to change it to?");
string newdesc = Console.ReadLine();
context.UpdateToDo(id, newdesc);
context.PrintToDos(context.ToDos);

//Console.WriteLine("Would you like to Add,Edit, or Delete any tasks>");
//string answer = Console.ReadLine();
//string[] commands = { "Edit", "Add", "Delete" };





//List<String> commands { "Edit", "Add", "Delete" };
//while (answer == )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were heading down the right path here...

// if (answer == "Edit")
// {
// System.Console.WriteLine("Id of task you want to update: ");
// int id = Convert.ToInt32(Console.ReadLine());
// System.Console.WriteLine("What would you like to change it to?");
// string newdesc = Console.ReadLine();
// context.UpdateToDo(id, newdesc);
// context.PrintToDos(context.ToDos);

// }
// else if (answer == "Add")
// {
// context.CreateToDo(todo1);
// System.Console.WriteLine("What task do you want to complete?");
// todo1.Description = Console.ReadLine();
// context.PrintToDos(context.ToDos);
// context.CreateToDo(todo2);
// Console.WriteLine("Enter additional tasks if needed:");
// todo2.Description = Console.ReadLine();
// context.PrintToDos(context.ToDos);
// context.CreateToDo(todo3);
// Console.WriteLine("Enter additional tasks if needed:");
// todo3.Description = Console.ReadLine();
// context.PrintToDos(context.ToDos);
// context.CreateToDo(todo4);
// Console.WriteLine("Enter additional tasks if needed:");
// todo4.Description = Console.ReadLine();
// context.PrintToDos(context.ToDos);
// }
// else if (answer == "Delete")
// {
// context.DeleteToDo();
// }





System.Console.ReadLine();


}

}

}
9 changes: 9 additions & 0 deletions checkpoint3/SQLQuery1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Create Table checkpoint3 (
TaskID int,
Description varchar(255),
);

CREATE TABLE todo_list (id INTEGER PRIMARY KEY, item TEXT);
INSERT INTO todo_list VALUES (1, "Wash the dishes");
INSERT INTO todo_list VALUES (2, "vacuuming");
INSERT INTO todo_list VALUES (3, "Learn some stuff on KA");
16 changes: 16 additions & 0 deletions checkpoint3/ToDo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace checkpoint3
{
class ToDo
{
public int Id { get; set; }

public string Description { get; set; }

public string TastTitle { get; set; }
}
}
12 changes: 12 additions & 0 deletions checkpoint3/checkpoint3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
</ItemGroup>

</Project>
56 changes: 56 additions & 0 deletions checkpoint3/utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;


namespace checkpoint3
{
class Utils : DbContext
{
public Utils(DbContextOptions<Utils> options) : base(options)
{

}
public List<ToDo> ToDos = new List<ToDo>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost right. You have to declare your ToDos property as a type of DbSet and it needs to be a property not a field.

public int count;

public ToDo GetToDoByID(int id)
{
return ToDos.FirstOrDefault(x => x.Id == id);
}


public void UpdateToDo(int Id, string newdesc)
{
ToDo todo = GetToDoByID(Id);
todo.Description = newdesc;
}


public void DeleteToDo()
{

}


public void CreateToDo(ToDo todo)
{
count++;
todo.Id = count;
ToDos.Add(todo);


}


public void PrintToDos(List<ToDo> toDos)
{
foreach (var item in toDos)
{
System.Console.WriteLine("Task ID: " + item.Id + ", and the description: " + item.Description);
}
}
}
}