public JsonResult UpdateFurtherControlMeasureTask(AddEditFurtherControlMeasureTaskViewModel viewmodel, DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            if (!ModelState.IsValid)
                return Json(new { Success = false, Errors = ModelState.GetErrorMessages() });

            var existingTask = _furtherControlMeasureTaskService.GetByIdAndCompanyId(viewmodel.FurtherControlMeasureTaskId,
                CurrentUser.CompanyId);

            var saveTaskRequest = UpdateFurtherControlMeasureTaskRequest.Create(
                viewmodel.Title,
                viewmodel.Description,
                viewmodel.Reference,
                viewmodel.TaskCompletionDueDate,
                viewmodel.TaskStatusId,
                viewmodel.CompanyId,
                viewmodel.FurtherControlMeasureTaskId,
                viewmodel.TaskAssignedToId.GetValueOrDefault(),
                viewmodel.TaskReoccurringTypeId,
                viewmodel.FirstDueDate,
                viewmodel.TaskReoccurringEndDate,
                CurrentUser.UserId,
                documentsToSaveViewModel.CreateDocumentRequests,
                documentsToSaveViewModel.DeleteDocumentRequests,
                !viewmodel.DoNotSendTaskNotification,
                !viewmodel.DoNotSendTaskCompletedNotification,
                !viewmodel.DoNotSendTaskOverdueNotification,
                !viewmodel.DoNotSendTaskDueTomorrowNotification);

            _furtherControlMeasureTaskService.Update(saveTaskRequest);

            if(existingTask.TaskAssignedTo.Id != viewmodel.TaskAssignedToId.GetValueOrDefault())
            {
                _bus.Publish(new TaskAssigned { TaskGuid = existingTask.TaskGuid });
            }

            return Json(new { Success = true, Id = viewmodel.FurtherControlMeasureTaskId });
        }
        public AddEditFurtherControlMeasureTaskViewModel GetViewModel()
        {

            var furtherActionTaskDto = _furtherControlMeasureTaskService.GetByIdAndCompanyId(_furtherControlMeasureTaskId, _companyId);

            var viewModel = new AddEditFurtherControlMeasureTaskViewModel()
                                {
                                    FurtherControlMeasureTaskId = furtherActionTaskDto.Id,
                                    RiskAssessmentTitle = furtherActionTaskDto.RiskAssessment.Title,
                                    Title = furtherActionTaskDto.Title,
                                    Reference = furtherActionTaskDto.Reference,
                                    Description = furtherActionTaskDto.Description,
                                    TaskStatusId = furtherActionTaskDto.TaskStatusId,
                                    TaskStatus = furtherActionTaskDto.TaskStatusString,
                                    CompanyId = _companyId,
                                    TaskAssignedToId = furtherActionTaskDto.TaskAssignedTo.Id,
                                    TaskAssignedTo = furtherActionTaskDto.TaskAssignedTo.FullName,
                                    TaskCompletionDueDate = furtherActionTaskDto.TaskCompletionDueDate,
                                    CompletedComments = furtherActionTaskDto.TaskCompletedComments,
                                    TaskReoccurringTypeId = (int)furtherActionTaskDto.TaskReoccurringType,
                                    TaskReoccurringType = furtherActionTaskDto.TaskReoccurringType,
                                    TaskReoccurringEndDate = furtherActionTaskDto.TaskReoccurringEndDate,
                                    TaskReoccurringTypes = new TaskReoccurringType().ToSelectList(),
                                    DoNotSendTaskNotification = !furtherActionTaskDto.SendTaskNotification,
                                    DoNotSendTaskCompletedNotification = !furtherActionTaskDto.SendTaskCompletedNotification,
                                    DoNotSendTaskOverdueNotification = !furtherActionTaskDto.SendTaskOverdueNotification,
                                    DoNotSendTaskDueTomorrowNotification = !furtherActionTaskDto.SendTaskDueTomorrowNotification,
                                    ExistingDocuments = _existingDocumentsViewModelFactory
                                        .WithCanDeleteDocuments(_canDeleteDocuments)
                                        .WithDefaultDocumentType(furtherActionTaskDto.DefaultDocumentType)
                                        .GetViewModel(furtherActionTaskDto.Documents),
                                    IsRecurring = furtherActionTaskDto.IsReoccurring
                                };

            return viewModel;
        }