-
Notifications
You must be signed in to change notification settings - Fork 0
Checkpoint3 #16
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
base: master
Are you sure you want to change the base?
Checkpoint3 #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "CurrentProjectSetting": null | ||
| } |
| 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}" | ||
| } | ||
| ,] | ||
| } |
| 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" | ||
| } | ||
| ] | ||
| } |
| 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); | ||
| 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 == ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| 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"); |
| 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; } | ||
| } | ||
| } |
| 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> |
| 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>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
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.