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
75 changes: 75 additions & 0 deletions Checkpoint3/Program.cs
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
{
Copy link

Choose a reason for hiding this comment

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

extra?


}

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()
{

}
}
}

8 changes: 8 additions & 0 deletions Checkpoint3/checkpoint3.csproj
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>
222 changes: 194 additions & 28 deletions Database/Database.cs
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");
}
}
}
}
1 change: 1 addition & 0 deletions Database/Database.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.0" />
</ItemGroup>

</Project>
Binary file removed Database/database.db
Binary file not shown.
Binary file added Database/todo.db
Binary file not shown.