diff --git a/CommandParser.cs b/CommandParser.cs new file mode 100644 index 0000000..86e5c78 --- /dev/null +++ b/CommandParser.cs @@ -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; + } + } + } +} \ No newline at end of file diff --git a/Group.cs b/Group.cs new file mode 100644 index 0000000..25b3c94 --- /dev/null +++ b/Group.cs @@ -0,0 +1,13 @@ +namespace SectTask; + +public class Group +{ + public List Tasks; + public int? GroupId { get; set; } + + public Group(int Id) + { + Tasks = new List(); + GroupId = Id; + } +} diff --git a/Methods.cs b/Methods.cs new file mode 100644 index 0000000..88b232c --- /dev/null +++ b/Methods.cs @@ -0,0 +1,189 @@ +using System.Data; +using System.Numerics; + +namespace SectTask; + +using System.Text.Json; + +public class TaskManager +{ + private readonly List _taskData; + private readonly List _groupData; + + public TaskManager() + { + _groupData = new List(); + _taskData = new List(); + } + + 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(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]); + } + } + } + } + + +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..be044a0 --- /dev/null +++ b/Program.cs @@ -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(); + */ + } +} \ No newline at end of file diff --git a/SubTask.cs b/SubTask.cs new file mode 100644 index 0000000..a3c1506 --- /dev/null +++ b/SubTask.cs @@ -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; +} \ No newline at end of file diff --git a/Task.cs b/Task.cs new file mode 100644 index 0000000..b474442 --- /dev/null +++ b/Task.cs @@ -0,0 +1,16 @@ +namespace SectTask; +public class Task +{ + public List 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(); + DeadLine = deadline; + TaskStatus = status; + } +} diff --git a/sectreborn.csproj b/sectreborn.csproj new file mode 100644 index 0000000..b9de063 --- /dev/null +++ b/sectreborn.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/sectreborn.sln b/sectreborn.sln new file mode 100644 index 0000000..43293ef --- /dev/null +++ b/sectreborn.sln @@ -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