Advertisement
BSO90

Untitled

Aug 5th, 2021
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using TaskManegementSystemOperations.Commands;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using TaskManegementSystemCore;
  5. using TaskManegementSystemModels.Interfaces;
  6. using TaskManegementSystemModels;
  7.  
  8. namespace TaskManegementSystemOperations
  9. {
  10.     public class Add_Comment_To_Task : ICommand
  11.     {
  12.         private readonly Factory factory;
  13.         private readonly Repository repository;
  14.         public Add_Comment_To_Task(Factory factory, Repository repository)
  15.         {
  16.             this.factory = factory;
  17.             this.repository = repository;
  18.         }
  19.         public string Execute(IList<string> parameters)
  20.         {
  21.             string comment = parameters[0];
  22.             string author = parameters[1];
  23.             string taskName = parameters[2];
  24.             ITask task = repository.AllTasks.FirstOrDefault(x => x.Title == taskName);
  25.             return AddCommentToTask(comment, author, task);
  26.            
  27.         }
  28.  
  29.         public string AddCommentToTask(string content, string author, ITask task)
  30.         {
  31.             IMember commentAuthor = repository.People.FirstOrDefault(x => x.Name == author);
  32.  
  33.             commentAuthor.ActivityHistory.Add(new History($"Added comment to Task {task.Title}"));
  34.  
  35.             IComment comment = factory.CreateComment(content, author);
  36.             task.Comments.Add(comment);
  37.             return $"{author} added comment successfully to Task.";
  38.         }
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement