示例#1
0
        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);
        }
示例#2
0
        public List <Comentary> ListAllComments(int TaskId)
        {
            List <Comentary> result = new List <Comentary>();

            FileStream   fs = new FileStream(this.filePath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);

            try
            {
                while (!sr.EndOfStream)
                {
                    Comentary comentary = new Comentary();
                    comentary.Id            = Convert.ToInt32(sr.ReadLine());
                    comentary.TaskId        = Convert.ToInt32(sr.ReadLine());
                    comentary.UserId        = Convert.ToInt32(sr.ReadLine());
                    comentary.ComentaryText = sr.ReadLine();

                    if (comentary.TaskId == TaskId)
                    {
                        result.Add(comentary);
                    }
                }
            }
            finally
            {
                sr.Close();
                fs.Close();
            }

            return(result);
        }
示例#3
0
        private int GetNextId()
        {
            FileStream   fs = new FileStream(this.filePath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);

            int id = 1;

            try
            {
                while (!sr.EndOfStream)
                {
                    Comentary comentary = new Comentary();
                    comentary.Id            = Convert.ToInt32(sr.ReadLine());
                    comentary.TaskId        = Convert.ToInt32(sr.ReadLine());
                    comentary.UserId        = Convert.ToInt32(sr.ReadLine());
                    comentary.ComentaryText = sr.ReadLine();



                    if (id <= comentary.Id)
                    {
                        id = comentary.Id + 1;
                    }
                }
            }
            finally
            {
                sr.Close();
                fs.Close();
            }

            return(id);
        }
示例#4
0
    public void Execute(SaveCommentaryCommnad command)
    {
        var user       = userRepository.getBy(userId: command.userId);
        var commentary = new Comentary(
            userId: command.userId,
            userNick: user.nick,
            pictureId: command.pictureId,
            commentary: command.commentary
            );

        commentaryRepository.save(commnetary);
    }
示例#5
0
        public async Task <CommentaryResponse> SaveAsync(Comentary comentary)
        {
            try
            {
                await _comentaryRepository.AddAsync(comentary);

                await _unitOfWork.CompleteAsync();

                return(new CommentaryResponse(comentary));
            }
            catch (Exception e)
            {
                return(new CommentaryResponse($"An error ocurred while saving the Commentary: {e.Message}"));
            }
        }
示例#6
0
        public void Insert(Comentary item)
        {
            item.Id = GetNextId();

            FileStream   fs = new FileStream(filePath, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);

            try
            {
                sw.WriteLine(item.Id);
                sw.WriteLine(item.TaskId);
                sw.WriteLine(item.UserId);
                sw.WriteLine(item.ComentaryText);
            }
            finally
            {
                sw.Close();
                fs.Close();
            }
        }
示例#7
0
        public async Task <CommentaryResponse> UpdateAsync(int id, Comentary comentary)
        {
            var existing = await _comentaryRepository.FindById(id);

            if (existing == null)
            {
                return(new CommentaryResponse("Commentary not found"));
            }
            existing.Opinion = comentary.Opinion;
            try
            {
                _comentaryRepository.Update(existing);
                await _unitOfWork.CompleteAsync();

                return(new CommentaryResponse(existing));
            }
            catch (Exception e)
            {
                return(new CommentaryResponse($"An error ocurred while updating the Commentary: {e.Message}"));
            }
        }
示例#8
0
        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);
            }
        }
 public void Update(Comentary Comentary)
 {
     _context.Comentaries.Update(Comentary);
 }
 public void Remove(Comentary Comentary)
 {
     _context.Comentaries.Remove(Comentary);
 }
 public async Task AddAsync(Comentary comentary)
 {
     await _context.Comentaries.AddAsync(comentary);
 }