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
59 changes: 59 additions & 0 deletions CommandParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace SectTask;

public class CommandParser
{
public void Commands(string?[] args)
{
TaskManager td = new TaskManager();
for (int i = 0; i < args.Length - 1; ++i)
{
if (args[i] is null)
{
return;
}
switch (args[i])
{
case "/add":
td.AddTask(Convert.ToInt32(args[i + 4]), Convert.ToDateTime(args[i + 5]),Convert.ToBoolean(args[i + 6]));
break;
case "/all":
td.ShowTasks();
break;
case "/delete":
td.DeleteTask(Convert.ToInt32(args[i + 1]));
break;
case "/save":
td.toFile(args[i + 1]);
break;
case "/load":
td.fromFile(args[i + 1]);
break;
case "/completed":
td.ChangeTaskStatus(Convert.ToInt32(args[i + 1]), Convert.ToBoolean(args[i + 2]));
break;
case "/create-group":
td.CreateGroup(Convert.ToInt32(args[i + 1]));
break;
case "/delete-group":
td.DeleteGroup(Convert.ToInt32(args[i + 1]));
break;
case "/add-to-group":
td.AddToGroup(Convert.ToInt32(args[i + 1]), Convert.ToInt32(args[i + 2]));
break;
case "/delete-from-group":
td.DeleteTaskFromGroup(Convert.ToInt32(args[i + 1]), Convert.ToInt32(args[i + 2]));
break;
case "/add-subtask":
SubTask sub1 = new SubTask(Convert.ToBoolean(args[i + 1]), Convert.ToInt32(args[i + 2]), args[i + 3], args [i + 4]);
td.AddSubTask(Convert.ToInt32(args[i + 5]),sub1);
break;
case "/change-sub-status":
td.ChangeSubtaskStatus(Convert.ToInt32(args[i + 1]), Convert.ToInt32(args[i + 1]));
break;
case "/today":
td.PrintTodaysDeadline();
break;
}
}
}
}
13 changes: 13 additions & 0 deletions Group.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SectTask;

public class Group
{
public List<Task> Tasks;
public int? GroupId { get; set; }

public Group(int Id)
{
Tasks = new List<Task>();
GroupId = Id;
}
}
189 changes: 189 additions & 0 deletions Methods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
using System.Data;
using System.Numerics;

namespace SectTask;

using System.Text.Json;

public class TaskManager
{
private readonly List<Task> _taskData;
private readonly List<Group> _groupData;

public TaskManager()
{
_groupData = new List<Group>();
_taskData = new List<Task>();
}

public void AddTask(int id, DateTime deadline, bool complete)
{
_taskData.Add(new Task(id, deadline, complete));
Console.WriteLine("Task Created!");
}

public void AddSubTask(int taskId, SubTask subTask)
{

var adder = _taskData
.FirstOrDefault(task => task.TaskId == taskId)
?.SubTasks;
if (adder != null)
{
adder.Add(subTask);
Console.WriteLine("SubTask Created!");
}
else
{
Console.WriteLine("Try another Id");
}

}

public void ChangeSubtaskStatus(int taskId, int subTaskId)
{
_taskData
.FirstOrDefault(task => task.TaskId == taskId)?
.SubTasks
.FirstOrDefault(subtask => subtask.SubTaskId == subTaskId)?
.ChangeStatus();
Console.WriteLine("Status Changed!");
}

public void ShowTasks()
{
foreach (var task in _taskData)
{
Console.WriteLine(task!.TaskId);
Console.WriteLine(task!.TaskStatus);
foreach (var task1 in task.SubTasks)
{
var json = JsonSerializer.Serialize(task1);
Console.WriteLine(json);
}

var json1 = JsonSerializer.Serialize(task.DeadLine);
Console.WriteLine(json1);
}
}

public void DeleteTask(int id)
{
for (var i = 0; i < _taskData.Count; ++i)
{
if (_taskData[i]!.TaskId == id)
{
_taskData.Remove(_taskData[i]);
}
}
}

public void ChangeTaskStatus(int id, bool status)
{
foreach (var t in _taskData)
{
t!.TaskStatus = status;
}

Console.WriteLine("Status Changed!");
}

public void toFile(string? ph)
{
var str = new StreamWriter(ph!);
foreach (var t in _taskData)
{
str.WriteLine(t!.TaskId);
str.WriteLine(t!.TaskStatus);
var json = JsonSerializer.Serialize(t?.SubTasks);
var json1 = JsonSerializer.Serialize(t?.DeadLine);
str.WriteLine(json);
str.WriteLine(json1);
}

str.Close();
}

public void fromFile(string? ph)
{
if (!File.Exists(ph))
{
throw new Exception("File not found");
}

using var reader = new StreamReader(ph);
_taskData.Clear();
for (var i = 0; i < System.IO.File.ReadAllLines(ph).Length; ++i)
{
var json = reader.ReadLine();
if (json != null) _taskData.Add(JsonSerializer.Deserialize<Task>(json)!);
}
}

public void PrintTodaysDeadline()
{
foreach (var task in _taskData)
{
if (task.DeadLine.Day == DateTime.Now.Day)
{
var json = JsonSerializer.Serialize(task);
Console.WriteLine(json);
}
}
}

public void CreateGroup(int Id)
{
_groupData.Add(new Group(Id));
}

public void AddToGroup(int taskId, int groupId)
{
foreach (var t in _taskData)
{
if (t.TaskId == taskId)
{
foreach (var t1 in _groupData)
{
if (t1.GroupId == groupId)
{
t1.Tasks.Add(t);
}
}
}
}
}

public void ShowGroup()
{
foreach (var t in _groupData)
{
var json = JsonSerializer.Serialize(t!.GroupId);
var json1 = JsonSerializer.Serialize(t!.Tasks);
Console.WriteLine(json);
Console.WriteLine(json1);
}
}

public void DeleteGroup(int Id)
{
var group = _groupData.Single(group => group.GroupId == Id);
_groupData.Remove(group);
}

public void DeleteTaskFromGroup(int groupId, int taskId)
{
foreach (var group in _groupData.Where(t => t.GroupId == groupId))
{
for (var j = 0; j < _taskData.Count; ++j)
{
if (_taskData[j].TaskId == taskId)
{
group.Tasks.Remove(group.Tasks[j]);
}
}
}
}


}
42 changes: 42 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace SectTask;

static class Program
{
static void Main(string?[] args)
{
CommandParser input = new CommandParser();
input.Commands(args);

/* TaskManager td = new TaskManager();
SubTask subTask = new SubTask(false, 1,"sport", "beerpong") ;
SubTask subTask1 = new SubTask(false, 2,"sprt", "beerpong") ;
SubTask subTask2 = new SubTask(false, 3,"port", "beerpong") ;

td.AddTask(1,DateTime.Now, true);
td.AddTask(2,DateTime.Now, true);
td.AddTask(3,DateTime.Now, true);

td.ShowTasks();
Console.WriteLine();
td.ChangeTaskStatus(1, false);
td.ShowTasks();
Console.WriteLine();
td.ChangeSubtaskStatus(1, 1);
td.ShowTasks();
td.AddSubTask(1,subTask);
td.AddSubTask(1,subTask1);
td.AddSubTask(5,subTask2);
td.CreateGroup(1);
td.AddToGroup(1,1);
td.AddToGroup(2,1);
Console.WriteLine();
//td.ShowTasks();

td.ShowGroup();
td.DeleteTaskFromGroup(1,2);
td.ShowGroup();
td.DeleteGroup(1);
td.ShowGroup();
*/
}
}
22 changes: 22 additions & 0 deletions SubTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace SectTask;

public class SubTask
{
public bool Status { get; set; }

public string? Name { get; set; }

public string? Description { get; set; }

public int SubTaskId { get; set; }

public SubTask(bool complete, int id, string? name, string? description)
{
Status = complete;
Name = name;
Description = description;
SubTaskId = id;
}

public void ChangeStatus() => Status = !Status;
}
16 changes: 16 additions & 0 deletions Task.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace SectTask;
public class Task
{
public List<SubTask> SubTasks;
public int TaskId { get; set; }
public bool TaskStatus { get; set; }
public DateTime DeadLine { get; set; } // 01.01.0001 0:00:00

public Task(int id, DateTime deadline, bool status)
{
TaskId = id;
SubTasks = new List<SubTask>();
DeadLine = deadline;
TaskStatus = status;
}
}
10 changes: 10 additions & 0 deletions sectreborn.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
16 changes: 16 additions & 0 deletions sectreborn.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sectreborn", "sectreborn\sectreborn.csproj", "{68D18D10-A682-4D7E-BB67-3815EA1336E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{68D18D10-A682-4D7E-BB67-3815EA1336E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68D18D10-A682-4D7E-BB67-3815EA1336E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68D18D10-A682-4D7E-BB67-3815EA1336E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68D18D10-A682-4D7E-BB67-3815EA1336E7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal