diff --git a/Checkpoint3/Program.cs b/Checkpoint3/Program.cs new file mode 100644 index 00000000..ed31f03b --- /dev/null +++ b/Checkpoint3/Program.cs @@ -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 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() + { + + } + } +} + diff --git a/Checkpoint3/checkpoint3.csproj b/Checkpoint3/checkpoint3.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/Checkpoint3/checkpoint3.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/Database/Database.cs b/Database/Database.cs index 588082e7..62c4e298 100644 --- a/Database/Database.cs +++ b/Database/Database.cs @@ -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> results = new List>(); - static void Main(string[] args) { - connectionStringBuilder.DataSource = "./database.db"; - SqliteDataReader reader = RunQuery(@" - SELECT * FROM items; - "); - PrintResults(reader); + DAO theDao = new DAO(); + List 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 list() { - using (var connection = new SqliteConnection(connectionStringBuilder.ConnectionString)) + List allItems = new List(); + 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 listDone() { - results.Clear(); - var row = 0; - while (reader.Read()){ - results.Add(new Dictionary()); - for (var column = 0; column < reader.FieldCount; column++) + List doneList = new List(); + + 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 myList { get; set; } + override + protected void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite("Filename =./todo.db"); } } -} +} \ No newline at end of file diff --git a/Database/Database.csproj b/Database/Database.csproj index 264c27d5..859c4da9 100644 --- a/Database/Database.csproj +++ b/Database/Database.csproj @@ -7,6 +7,7 @@ + diff --git a/Database/database.db b/Database/database.db deleted file mode 100644 index e4e11295..00000000 Binary files a/Database/database.db and /dev/null differ diff --git a/Database/todo.db b/Database/todo.db new file mode 100644 index 00000000..591f34de Binary files /dev/null and b/Database/todo.db differ