public ReassignActionTaskViewModel GetViewModel()
        {
            var action = _actionService.GetByIdAndCompanyId(_actionId, _companyId);
            var task = action.ActionTasks.FirstOrDefault();

            if (task == null)
            {
                throw new TaskNotFoundException(default(long));
            }

            var model = new ReassignActionTaskViewModel
            {
                CompanyId = _companyId,
                ActionPlanId = _actionplanId,
                ActionId = action.Id,
                Title = task.Title,
                Description = task.Description,
                GuidanceNotes = action.GuidanceNote,
                DueDate = task.TaskCompletionDueDate,
                ActionTaskAssignedToId = task.TaskAssignedTo.Id,
                ActionTaskAssignedTo = task.TaskAssignedTo.FullName,
                DoNotSendTaskCompletedNotification = !task.SendTaskCompletedNotification,
                DoNotSendTaskOverdueNotification = !task.SendTaskOverdueNotification,
                DoNotSendTaskAssignedNotification = !task.SendTaskNotification,
                DoNotSendTaskDueTomorrowNotification = !task.SendTaskDueTomorrowNotification
            };

            model.ExistingDocuments = _existingDocumentsViewModelFactory
                    .WithCanDeleteDocuments(false)
                    .WithCanEditDocumentType(true)
                    .WithDefaultDocumentType(DocumentTypeEnum.Action)
                    .WithDocumentOriginType(DocumentOriginType.TaskUpdated)
                    .GetViewModel(task.Documents ?? new List<TaskDocumentDto>());

            return model;
        }
        public void Given_companyid_when_when_get_viewmodel_with_taskId_then_result_contains_matching_companyId()
        {
            //given
            var companyId = 123L;
            var taskId = 1L;
            var target = GetTarget();
            target.WithCompanyId(companyId);

            _actionTaskService.
                Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(new ActionTaskDto
                {
                    Id = 1111,
                    Title = "Title",
                    
                    Description = "Description",
                    TaskCompletionDueDate = DateTime.Now.ToShortDateString(),
                    TaskAssignedTo = new EmployeeDto
                    {
                       Id = Guid.Parse("8c195637-79e2-47c8-b422-bf901c328a83"),
                       FullName = "Employee Name"
                    },
                    Action = new ActionDto()
                    {
                        Id = 2222,
                        ActionPlan = new Domain.Entities.ActionPlan()
                        {
                            Id = 1
                        }
                    }
                });

            ReassignActionTaskViewModel taskViewModel = new ReassignActionTaskViewModel()
            {
                ActionId = 2222,
                ActionPlanId = 1,
                Title = "Title",
                ActionTaskAssignedToId = Guid.Parse("8c195637-79e2-47c8-b422-bf901c328a83"),
                CompanyId = 1111,
                Description = "Description"
            };

            //when
            var result = target.WithTaskId(taskId)
                         .WithCompanyId(companyId)
                         .GetViewModelByTask();

            //then
            Assert.That(result.CompanyId, Is.EqualTo(companyId));
            Assert.That(result.Title, Is.EqualTo(taskViewModel.Title));
            Assert.That(result.ActionId, Is.EqualTo(taskViewModel.ActionId));
            Assert.That(result.ActionPlanId, Is.EqualTo(taskViewModel.ActionPlanId));
            Assert.That(result.ActionTaskAssignedToId, Is.EqualTo(taskViewModel.ActionTaskAssignedToId));
        }
        private void ValidateReassignViewModel(ReassignActionTaskViewModel model)
        {
            if (model.ActionTaskAssignedToId == null || model.ActionTaskAssignedToId == Guid.Empty)
            {
                ModelState.AddModelError("AssignedTo", "Please select an assignee for the selected task.");
            }

            DateTime dueDate = DateTime.MinValue;
            if (model.DueDate == null || !DateTime.TryParse(model.DueDate, out dueDate))
            {
                ModelState.AddModelError("DueDate", "Please select a valid due date for the selected task.");
            }
            else
            {
                if (dueDate < DateTime.Now.Date)
                {
                    ModelState.AddModelError("DueDate", "Due date cannot be in the past.");
                }
            }
        }
        public JsonResult Reassign(ReassignActionTaskViewModel model, DocumentsToSaveViewModel documentsToSave)
        {
            JsonResult result;
            
            ValidateReassignViewModel(model);

            if (ModelState.IsValid)
            {
                var command =
                    _assignActionPlanTaskCommand
                        .WithCompanyId(CurrentUser.CompanyId)
                        .WithUserId(CurrentUser.UserId)
                        .WithActionId(model.ActionId)
                        .WithAssignedTo(model.ActionTaskAssignedToId)
                        .WithDueDate(model.DueDate)
                  		.WithSendTaskNotification(!model.DoNotSendTaskAssignedNotification)
                  		.WithSendTaskCompletedNotification(!model.DoNotSendTaskCompletedNotification)
                  		.WithSendTaskOverdueNotification(!model.DoNotSendTaskOverdueNotification)
                        .WithDocuments(documentsToSave.CreateDocumentRequests)
                        .WithAreaOfNonCompliance(model.Title)
                        .WithActionRequired(model.Description);

                command.Execute();
               
                result = Json(new { Success = true });       
            }
            else
            {
                result = ModelStateErrorsAsJson();
            }
            return result;
        }