private void MakeComment() { Console.Clear(); Comentary comentary = new Comentary(); comentary.UserId = AuthenticationService.LoggedUser.Id; Console.WriteLine("Add new Comment on Task:"); Console.Write("Task ID: "); comentary.TaskId = Convert.ToInt32(Console.ReadLine()); TasksRepository tasksRepository = new TasksRepository("tasks.txt"); TaskData taskData = tasksRepository.GetById(comentary.TaskId); if (taskData.Creator == AuthenticationService.LoggedUser.Id || taskData.ResponsibleUser == AuthenticationService.LoggedUser.Id) { Console.Write("Commentary: "); comentary.ComentaryText = Console.ReadLine(); ComentaryRepository comentaryRepository = new ComentaryRepository("comentaries.txt"); comentaryRepository.Insert(comentary); Console.WriteLine("Comentary made successfully."); } else { Console.WriteLine("You can comment only task you created or you are responsible for."); } Console.ReadKey(true); }
private void ListComments() { Console.Clear(); Console.WriteLine("Get all the commentaries of a task"); Console.Write("Task ID:"); int taskId = Convert.ToInt32(Console.ReadLine()); TasksRepository tasksRespository = new TasksRepository("tasks.txt"); TaskData task = new TaskData(); task = tasksRespository.GetById(taskId); if (task.Creator == AuthenticationService.LoggedUser.Id || task.ResponsibleUser == AuthenticationService.LoggedUser.Id) { ComentaryRepository comentaryRepository = new ComentaryRepository("comentaries.txt"); List <Comentary> comentaries = comentaryRepository.ListAllComments(task.Id); foreach (Comentary comentary in comentaries) { Console.WriteLine("Comentary ID:" + comentary.Id); Console.WriteLine("Task ID: " + comentary.TaskId); Console.WriteLine("Comentator ID: " + comentary.UserId); Console.WriteLine("Comentary: " + comentary.ComentaryText); Console.WriteLine("########################################"); } Console.ReadKey(true); } else { Console.WriteLine("You can see only comments on tasks you created or you are responsible for"); Console.ReadKey(true); } }
private void UpdateState() { Console.Clear(); Console.WriteLine("Update Task State"); Console.Write("Task ID: "); int taskId = Convert.ToInt32(Console.ReadLine()); TasksRepository tasksRepository = new TasksRepository("tasks.txt"); TaskData task = tasksRepository.GetById(taskId); if (task == null) { Console.Clear(); Console.WriteLine("Task not found."); Console.ReadKey(true); return; } if (task.ResponsibleUser == AuthenticationService.LoggedUser.Id || task.Creator == AuthenticationService.LoggedUser.Id) { Console.WriteLine("Editing Task State For (" + task.Title + ": " + task.Description + ")"); Console.WriteLine("ID:" + task.Id); Console.WriteLine("State: " + task.State); Console.Write("New Task State: "); string taskState = Console.ReadLine(); if ((task.ResponsibleUser == AuthenticationService.LoggedUser.Id && taskState.ToLower() == "completed") || (task.Creator == AuthenticationService.LoggedUser.Id && taskState.ToLower() == "waiting")) { task.State = taskState; tasksRepository.Update(task); Console.WriteLine("Task state updated successfully."); Console.WriteLine("Comentary:"); string comentaryText = Console.ReadLine(); Comentary comentary = new Comentary(); comentary.TaskId = task.Id; comentary.UserId = AuthenticationService.LoggedUser.Id; comentary.ComentaryText = comentaryText; ComentaryRepository comentaryRepository = new ComentaryRepository("comentaries.txt"); comentaryRepository.Insert(comentary); Console.WriteLine("Comentary added successfully."); Console.ReadKey(true); } else { Console.WriteLine("You can change the state of a task from \"Completed\" to \"Waiting\" only if you are the creator of the task"); Console.WriteLine("You can change the state of a task from \"Waiting\" to \"Completed\" only if you are the responsible for the task"); Console.ReadKey(true); } } else { Console.WriteLine("You can only change the state of tasks you are responsible for or you have created"); Console.ReadKey(true); } }