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
271 changes: 271 additions & 0 deletions SimplifiedTodo/Crud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace SimplifiedTodo
{
internal class Crud
{
private static ToDoDBContext Context;

public Crud(ToDoDBContext c)
{
Context = c;
}

public void Run()
{
while (true)
{
//make a choice and loop while the choice is invalid
Console.Write("c.r.u.d (or e for exit): ");
string request = Console.ReadLine();
if (request == "e")
{
break;
}
switch (request)
{
case "c":
CreateItem();
break;
case "r":
ReadItem();
break;
case "u":
UpdateItem();
break;
case "d":
DeleteItem();
break;

default:
Console.Clear();
Console.WriteLine("Invalid selection.");
Thread.Sleep(500);
Console.Clear();
break;
}
}
}
public static void CreateItem()
{
ToDo entry = new ToDo();
Console.Clear();
Console.Write("Enter a title");
entry.Title = Console.ReadLine();
Console.Write("Enter Reminder");
entry.Content = Console.ReadLine();
entry.CreateDate = DateTime.Now;
Context.ToDos.Add(entry);
Context.SaveChanges();
}
public static void ReadItem()
{
string input = "";
while (input == "")
{
Console.Clear();
Console.WriteLine("Enter an id or a range of id's seperated by a \"-\" (example \"1-7\") or a for all");
Console.Write(": ");
input = Console.ReadLine();

if (input == "")
{
Console.Clear();
Console.WriteLine("Invalid Entry");
Thread.Sleep(500);
}

if (input.Contains("-") || int.TryParse(input, out int num) || input == "a")
{

}
else
{
input = "";
Console.Clear();
Console.WriteLine("Invalid Entry");
Thread.Sleep(500);
}
}
ToDo entry;
if (input.Contains("-"))
{
Console.WriteLine("This functionality is under construction");
}
else if (input == "a")
{
List<ToDo> todosList = Context.ToDos.ToList();
foreach (var item in todosList)
{
Console.WriteLine("*****************************************************************************************************************");
Console.Write("Title: ");
Console.WriteLine(item.Title);
Console.Write("Created: ");
Console.WriteLine(item.CreateDate);
Console.Write("Content: ");
Console.WriteLine(item.Content);
if (item.Completed)
{
if (item.Sucess)
{
Console.WriteLine("Status: Completed Successfully");
}
else
{
Console.WriteLine("Status: Abandoned");
}
}
else
{
Console.WriteLine("Status: In Progress");
}
}
Console.WriteLine("*****************************************************************************************************************");
}
else
{
entry = Context.ToDos.Find(Convert.ToInt32(input));
var find = Context.ToDos.Find(Convert.ToInt32(input));
if (find != null)
{
Console.WriteLine("*****************************************************************************************************************");
Console.Write("Title: ");
Console.WriteLine(entry.Title);
Console.Write("Created: ");
Console.WriteLine(entry.CreateDate);
Console.Write("Content: ");
Console.WriteLine(entry.Content);
if (entry.Completed)
{
if (entry.Sucess)
{
Console.WriteLine("Status: Completed Successfully");
}
else
{
Console.WriteLine("Status: Abandoned");
}
}
else
{
Console.WriteLine("Status: In Progress");
}
Console.WriteLine("*****************************************************************************************************************");
}
else
{
Console.WriteLine("invalid selection");
}
Console.ReadLine();
}

}
public static void UpdateItem()
{
string input = "";
while (input == "")
{
Console.Write("Enter item Id: ");
input = Console.ReadLine();
}
var find = Context.ToDos.Find(Convert.ToInt32(input));
if (find != null)
{
string modifyWhat = "";
while (modifyWhat != "t" && modifyWhat != "c" && modifyWhat != "s" && modifyWhat != "a" && modifyWhat != "e")
{
Console.WriteLine("*****************************************************************************************************************");
Console.Write("Title: ");
Console.WriteLine(find.Title);
Console.Write("Created: ");
Console.WriteLine(find.CreateDate);
Console.Write("Content: ");
Console.WriteLine(find.Content);
if (find.Completed)
{
if (find.Sucess)
{
Console.WriteLine("Status: Completed Successfully");
}
else
{
Console.WriteLine("Status: Abandoned");
}
}
else
{
Console.WriteLine("Status: In Progress");
}
Console.WriteLine("*****************************************************************************************************************");
Console.WriteLine();
Console.Write("Modify Entry");
Console.Write("t = Title c = Content s = successful a = abandon e = Exit: ");
modifyWhat = Console.ReadLine();
}
if (modifyWhat == "t")
{
string userInput = "";
while (userInput == "")
{
Console.Clear();
Console.Write("Enter new Title: ");
userInput = Console.ReadLine();
}
find.Title = userInput;
}
else if (modifyWhat == "c")
{
string userInput = "";
while (userInput != "")
{
Console.Clear();
Console.Write("Enter new Content: ");
userInput = Console.ReadLine();
}

find.Content = userInput;
}
else if (modifyWhat == "s")
{
find.Completed = true;
}
else if (modifyWhat == "a")
{
find.Completed = true;
find.Sucess = false;
}
Context.SaveChanges();
}
}
public static void DeleteItem()
{
string input = "";
while (input == "")
{
Console.Clear();
Console.WriteLine("Enter an id of item to remove");
Console.Write(": ");
input = Console.ReadLine();

if (input == "")
{
Console.Clear();
Console.WriteLine("Invalid Entry");
Thread.Sleep(500);
}
else
{
var find = Context.ToDos.Find(Convert.ToInt32(input));
if (find != null)
{
Context.ToDos.Remove(find);
}
Context.SaveChanges();
}
}
}
}
}
21 changes: 21 additions & 0 deletions SimplifiedTodo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Threading;

namespace SimplifiedTodo
{
class Program
{
static void Main(string[] args)
{
DbContextOptionsBuilder<ToDoDBContext> builder = new DbContextOptionsBuilder<ToDoDBContext>();
builder.UseSqlServer("Server=(localdb)\\MSSQLLocalDb;Database=ToDoDB;Trusted_Connection=true");
DbContextOptions<ToDoDBContext> opts = builder.Options;
ToDoDBContext context = new ToDoDBContext(opts);
context.Database.EnsureCreated();

Crud crud = new Crud(context);
crud.Run();
}
}
}
13 changes: 13 additions & 0 deletions SimplifiedTodo/SimplifiedTodo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

</Project>
16 changes: 16 additions & 0 deletions SimplifiedTodo/ToDo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace SimplifiedTodo
{
public class ToDo
{
public string Content { get; set; }
public DateTime CreateDate { get; set; }
public string Title { get; set; }
public bool Completed { get; set; }
public bool Sucess { get; set; } = true;
public int Id { get; set; }
}
}
17 changes: 17 additions & 0 deletions SimplifiedTodo/ToDoDBContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace SimplifiedTodo
{
public class ToDoDBContext : DbContext
{
public ToDoDBContext(DbContextOptions<ToDoDBContext> options) : base(options)
{

}
public DbSet<ToDo> ToDos { get; set; }
}
}

Binary file added ToDo/.vs/ToDoApp/v15/.suo
Binary file not shown.
Empty file.
Binary file added ToDo/.vs/ToDoApp/v15/Server/sqlite3/storage.ide
Binary file not shown.
25 changes: 25 additions & 0 deletions ToDo/ToDoApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToDoApp", "ToDoApp\ToDoApp.csproj", "{8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5A43835A-1011-4684-8549-3E48B102432F}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions ToDo/ToDoApp/Database/AddEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ToDoApp
{
internal class AddEntry
{
public void NewTask()
{
//take in a list of values varify them and put them in the DB
}
}
}
11 changes: 11 additions & 0 deletions ToDo/ToDoApp/Database/DeleteEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace ToDoApp
{
internal class DeleteEntry
{

public void RemoveTask()
{
//take in a task# and move it to completed in the database under IsCompleted
}
}
}
Loading