public void Given_a_valid_request_When_Mark_As_Deleted_Then_should_call_appropriate_methods()
        {
            // Given
            var target = CreateTaskService();

            var request = new MarkTaskAsDeletedRequest()
                              {
                                  CompanyId = 1,
                                  TaskId = 2,
                                  UserId = Guid.NewGuid()
                              };


            _userRepository
                .Setup(x => x.GetByIdAndCompanyId(request.UserId, request.CompanyId))
                .Returns(_user);

            var mockFurtherControlMeasureTask = new Mock<MultiHazardRiskAssessmentFurtherControlMeasureTask>();

            _tasksRepository
                .Setup(x => x.GetByIdAndCompanyId(request.TaskId, request.CompanyId))
                .Returns(mockFurtherControlMeasureTask.Object);

            // When
            target.MarkTaskAsDeleted(request);

            // Then
            _userRepository.VerifyAll();
            _tasksRepository.VerifyAll();
            mockFurtherControlMeasureTask.Verify(x => x.MarkForDelete(_user));
        }
        public JsonResult MarkTaskAsDeleted(MarkTaskAsDeletedViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new ArgumentException("Invalid Arguments To Mark Task As Deleted");
            }

            var request = new MarkTaskAsDeletedRequest()
                              {
                                  TaskId = viewModel.FurtherControlMeasureTaskId,
                                  CompanyId = viewModel.CompanyId,
                                  UserId = CurrentUser.UserId
                              };

            if (_taskService.HasCompletedTasks(request))
            {
                return Json(new MarkTaskForDeleteResultViewModel()
                {
                    Success = false,
                    Message = "This reoccurring task has previous tasks which have been completed, and can therefore not be deleted."
                });
            }

            _taskService.MarkTaskAsDeleted(request);

            return Json(new MarkTaskForDeleteResultViewModel()
            {
                Success = true
            });
        }
Ejemplo n.º 3
0
        public void MarkTaskAsDeleted(MarkTaskAsDeletedRequest request)
        {
            _log.Add(request);

            try
            {
                var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
                var task = _taskRepository.GetByIdAndCompanyId(request.TaskId, request.CompanyId);

                task.MarkForDelete(user);

                _taskRepository.SaveOrUpdate(task);
            }
            catch (Exception ex)
            {
                _log.Add(ex);
                throw;
            }
        }
Ejemplo n.º 4
0
 public bool HasCompletedTasks(MarkTaskAsDeletedRequest request)
 {
     try
     {
         var task = _taskRepository.GetById(request.TaskId);
         return task.HasCompletedTasks();
     }
     catch (Exception ex)
     {
         _log.Add(ex);
         throw;
     }
 }