forked from AustinCodingAcademy/csharp-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
It works! #11
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
Forrest-Flowers
wants to merge
3
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
It works! #11
Changes from all commits
Commits
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,75 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace checkpoint3 | ||
| { | ||
| class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| Console.WriteLine("Welcome"); | ||
| } | ||
| } | ||
|
|
||
| public class UserSays | ||
| { | ||
| public UserSays() | ||
| { | ||
| Console.WriteLine(""); | ||
| Console.WriteLine(""); | ||
| Console.WriteLine(""); | ||
| Console.WriteLine(""); | ||
| Console.WriteLine(""); | ||
| } | ||
| } | ||
|
|
||
| public class Todo | ||
| { | ||
| public static int id; | ||
| public string task { get; set; } | ||
| public bool isComplete { get; set; } | ||
| public List<string> tags { get; set; } | ||
|
|
||
| public Todo(int id, string task) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| //Controller | ||
| public interface ITodo | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public class ToDoDAO | ||
| { | ||
| //Creates a new Todo object. | ||
| public static void Add() | ||
| { | ||
|
|
||
| } | ||
| //Takes an existing Todo object and allows you to edit it. | ||
| public static void Update() | ||
| { | ||
|
|
||
| } | ||
| //Lists all Todo objects. | ||
| public static void GetAll() | ||
| { | ||
|
|
||
| } | ||
| //Removes on Todo object by id | ||
| public static void Remove() | ||
| { | ||
|
|
||
| } | ||
| //Fetches one Todo object from database. | ||
| public static GetTodo() | ||
| { | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
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,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
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 |
|---|---|---|
| @@ -1,49 +1,215 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.Data.Sqlite; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using System.Linq; | ||
| using System.Threading; | ||
|
|
||
| namespace Database{ | ||
| namespace Database | ||
| { | ||
| class Program | ||
| { | ||
| static SqliteConnectionStringBuilder connectionStringBuilder = new SqliteConnectionStringBuilder(); | ||
| static List<Dictionary<string, string>> results = new List<Dictionary<string, string>>(); | ||
|
|
||
| static void Main(string[] args) | ||
| { | ||
| connectionStringBuilder.DataSource = "./database.db"; | ||
| SqliteDataReader reader = RunQuery(@" | ||
| SELECT * FROM items; | ||
| "); | ||
| PrintResults(reader); | ||
| DAO theDao = new DAO(); | ||
| List<Todo> theList = theDao.list(); | ||
| string userInput = " "; | ||
| string id; | ||
| string yesNo; | ||
|
|
||
| Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| Console.WriteLine("-------TO DO APP-------"); | ||
| Console.WriteLine("--By: Forrest Flowers--"); | ||
| Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| Thread.Sleep(1500); | ||
|
|
||
| while (userInput != "exit") | ||
| { | ||
| Console.WriteLine("Please enter 'add', 'remove', 'list','update' 'list done' or 'exit'"); | ||
| userInput = Console.ReadLine().ToLower(); | ||
| if (userInput == "add") | ||
| { | ||
| Console.WriteLine("Do you want to add a task?"); | ||
| yesNo = Console.ReadLine(); | ||
|
|
||
| if (yesNo == "yes" || yesNo == "y") | ||
| { | ||
| Console.WriteLine("Enter a task:"); | ||
| string task = Console.ReadLine(); | ||
| theDao.add(task); | ||
| theDao.save(); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("Returning to menu..."); | ||
| } | ||
| } | ||
| else if (userInput == "list") | ||
| { | ||
| foreach (Todo item in theDao.list()) | ||
| { | ||
| Console.WriteLine(item); | ||
| } | ||
| } | ||
| /* -Make sure you actually want to add something. | ||
| -Enter the Id to lookup. | ||
| -Calls the GetTodo method | ||
| -Use it to grab the Todo with that Id | ||
| -Put the Todo in remove method. | ||
| */ | ||
| else if (userInput == "remove") | ||
| { | ||
| Console.WriteLine("Do you want to delete an entry?(Y/N)"); | ||
| yesNo = Console.ReadLine().ToLower(); | ||
| if (yesNo == "yes" || yesNo == "y") | ||
| { | ||
| Console.WriteLine("Enter the id of the task you want to remove."); | ||
| id = Console.ReadLine(); | ||
| Todo removeItem = theDao.GetTodo(id); | ||
| theDao.remove(removeItem); | ||
| theDao.save(); | ||
|
|
||
| Console.WriteLine("Deleted!"); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("Gotcha, returning to menu..."); | ||
| } | ||
| } | ||
| else if (userInput == "update") | ||
| { | ||
| Console.WriteLine("Do you want to mark a task as complete? (Y/N)"); | ||
| yesNo = Console.ReadLine().ToLower(); | ||
| if (yesNo == "yes" || yesNo == "y") | ||
| { | ||
| Console.WriteLine("Enter the id of a task to mark as complete"); | ||
| id = Console.ReadLine(); | ||
| Todo markAsDone = theDao.GetTodo(id); | ||
| markAsDone.Status = true; | ||
| theDao.save(); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("Gotcha, returning to menu..."); | ||
| } | ||
| } | ||
| else if (userInput == "list done") | ||
| { | ||
| foreach (Todo item in theDao.listDone()) | ||
| { | ||
| Console.WriteLine(item); | ||
| } | ||
| } | ||
| else if (userInput == "exit") | ||
| { | ||
| break; | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("Invalid Input."); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
| // Cookie Cutter Todo Class | ||
| public class Todo | ||
| { | ||
| public int Id { get; set; } | ||
| public string Task { get; set; } | ||
| public bool Status { get; set; } | ||
|
|
||
| public Todo(int Id, string Task) | ||
| { | ||
| this.Id = Id; | ||
| this.Task = Task; | ||
| } | ||
|
|
||
| public Todo(string Task) | ||
| { | ||
| this.Task = Task; | ||
| } | ||
|
|
||
| override | ||
| public string ToString() | ||
| { | ||
| return Id + ": " + Task + " | " + (Status ? "Complete" : "Incomplete"); | ||
| } | ||
| } | ||
|
|
||
| public class DAO | ||
| { | ||
| public Context context; | ||
| public DAO() | ||
| { | ||
| context = new Context(); | ||
| context.Database.EnsureCreated(); | ||
| } | ||
|
|
||
| static SqliteDataReader RunQuery(string query) | ||
| public List<Todo> list() | ||
| { | ||
| using (var connection = new SqliteConnection(connectionStringBuilder.ConnectionString)) | ||
| List<Todo> allItems = new List<Todo>(); | ||
| foreach (Todo item in context.myList) | ||
| { | ||
| connection.Open(); | ||
| var selectCmd = connection.CreateCommand(); | ||
| selectCmd.CommandText = query; | ||
| return selectCmd.ExecuteReader(); | ||
| allItems.Add(item); | ||
| } | ||
| return allItems; | ||
| } | ||
|
|
||
| //Add an items to the database. | ||
| public void add(string task) | ||
| { | ||
| context.myList.Add(new Todo(task)); | ||
| } | ||
|
|
||
| static void PrintResults(SqliteDataReader reader) | ||
| //Search a single item in the database by Id. | ||
| public Todo GetTodo(string findId) | ||
| { | ||
| foreach (Todo item in context.myList) | ||
| { | ||
| if (item.Id.ToString() == findId) | ||
| { | ||
| return item; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| public List<Todo> listDone() | ||
| { | ||
| results.Clear(); | ||
| var row = 0; | ||
| while (reader.Read()){ | ||
| results.Add(new Dictionary<string, string>()); | ||
| for (var column = 0; column < reader.FieldCount; column++) | ||
| List<Todo> doneList = new List<Todo>(); | ||
|
|
||
| foreach (Todo item in context.myList) | ||
| { | ||
| if (item.Status == true) | ||
| { | ||
| results[row].Add(reader.GetName(column), reader.GetString(column)); | ||
| doneList.Add(item); | ||
| } | ||
| var lines = results[row].Select(kvp => kvp.Key + ": " + kvp.Value.ToString()); | ||
| Console.WriteLine(String.Join(Environment.NewLine, lines)); | ||
| Console.WriteLine(""); | ||
| row++; | ||
| } | ||
| return doneList; | ||
| } | ||
|
|
||
| public void remove(Todo removeItem) | ||
| { | ||
| context.myList.Remove(removeItem); | ||
| } | ||
|
|
||
| public void save() | ||
| { | ||
| context.SaveChanges(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| //Sets up the database. | ||
| public class Context : DbContext | ||
| { | ||
| public DbSet<Todo> myList { get; set; } | ||
| override | ||
| protected void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
| { | ||
| optionsBuilder.UseSqlite("Filename =./todo.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
Binary file not shown.
Binary file not shown.
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.
extra?