public void Given_valid_model_state_When_NewFurtherControlMeasureTask_Request_Then_should_call_correct_methods()
        {
            // Given
            var controller = GetTarget();
            var viewModel = new AddEditFireRiskAssessmentFurtherControlMeasureTaskViewModel()
                                {
                                    CompanyId = 123L,
                                    RiskAssessmentId = 789L,
                                    Title = "TItle",
                                    Description = "A description",
                                    Reference = "My reference",
                                    SignificantFindingId = 888L,
                                    TaskStatusId = 3
                                };
            var documentsToSave = new DocumentsToSaveViewModel();

            var result = new FireRiskAssessmentFurtherControlMeasureTaskDto();
            _furtherControlMeasureTaskService
                .Setup(x => x.AddFurtherControlMeasureTask(It.Is<SaveFurtherControlMeasureTaskRequest>(
                    y => y.CompanyId == viewModel.CompanyId &&
                         y.RiskAssessmentId == viewModel.RiskAssessmentId &&
                         y.Title == viewModel.Title &&
                         y.Description == viewModel.Description &&
                         y.Reference == viewModel.Reference &&
                         y.SignificantFindingId == viewModel.SignificantFindingId &&
                         y.TaskStatus == (TaskStatus)viewModel.TaskStatusId
                    )))
                .Returns(result);

            // When
            controller.NewFurtherControlMeasureTask(viewModel, documentsToSave);

            // Then
            _furtherControlMeasureTaskService.VerifyAll();
        }
Пример #2
0
        public void Given_valid_request_with_documents_to_attach_and_detach_When_save_Then_should_call_correct_methods()
        {
            // Given
            var controller = GetTarget();
            
            var savingDocumentsViewModel = new DocumentsToSaveViewModel()
            {
                CreateDocumentRequests = new List<CreateDocumentRequest>() { new CreateDocumentRequest() },
                DeleteDocumentRequests = new List<long>() { 1, 2 }
            };

            _attachmentService
                .Setup(x => x.AttachDocumentsToRiskAssessment(It.Is<AttachDocumentsToRiskAssessmentRequest>
                                                                  (y => y.CompanyId == _companyId &&
                                                                        y.RiskAssessmentId == _riskAssessmentId &&
                                                                        y.UserId == controller.CurrentUser.UserId &&
                                                                        y.DocumentsToAttach == savingDocumentsViewModel.CreateDocumentRequests)));

            _attachmentService
                .Setup(x => x.DetachDocumentsToRiskAssessment(It.Is<DetachDocumentsFromRiskAssessmentRequest>
                                                                  (y => y.CompanyId == _companyId &&
                                                                        y.RiskAssessmentId == _riskAssessmentId &&
                                                                        y.UserId == controller.CurrentUser.UserId &&
                                                                        y.DocumentsToDetach == savingDocumentsViewModel.DeleteDocumentRequests)));

            // When
            controller.Save(_companyId, _riskAssessmentId, savingDocumentsViewModel);

            // Then
            _attachmentService.VerifyAll();
        }
Пример #3
0
 public void Setup()
 {
     _businessSafeSessionManager = new Mock<IBusinessSafeSessionManager>();
     _businessSafeSessionManager.Setup(x => x.CloseSession());
    _responsibilityTaskService = new Mock<IResponsibilityTaskService>();
     _completeViewModel = new CompleteResponsibilityTaskViewModel
                         {
                             CompanyId = 1234L,
                             CompletedComments = "comments",
                             ResponsibilityId = 4653L,
                             ResponsibilitySummary = new ResponsibilitySummaryViewModel
                                                     {
                                                         Description = "description",
                                                         Id = 45763L,
                                                         Title = "title"
                                                     },
                                                     ResponsibilityTask = new ViewResponsibilityTaskViewModel
                                                                          {
                                                                              ResponsibilityTaskId = _responsibilityTaskId
                                                                          },
                             ResponsibilityTaskId = _responsibilityTaskId
                         };
     _documentsToSaveViewModel = new DocumentsToSaveViewModel
                                 {
                                     CreateDocumentRequests = new List<CreateDocumentRequest>
                                                              {
                                                                  new CreateDocumentRequest() { }
                                                              },
                                     DeleteDocumentRequests = new List<long> { 1234L, 3573L }
                                 };
 }
        public void When_CreateFurtherControlMeasureTask_called_Then_correct_methods_are_called()
        {
            // Arrange
            var target = GetTarget();

            var documentsToSaveViewModel = new DocumentsToSaveViewModel();
            var viewmodel = new AddRiskAssessmentFurtherControlMeasureTaskViewModel()
                                {
                                    TaskAssignedToId = Guid.NewGuid(),
                                    RiskAssessmentHazardId = 500,
                                    
                                };

            var userId = target.CurrentUser.UserId;

            var result = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto()
                             {
                                 CreatedDate = DateTime.Now.ToShortDateString()
                             };

            _furtherControlMeasureTaskService
                .Setup(x => x.AddFurtherControlMeasureTask(It.Is<SaveFurtherControlMeasureTaskRequest>(y => y.CompanyId == viewmodel.CompanyId &&
                                                                                           y.Title == viewmodel.Title &&
                                                                                           y.Description == viewmodel.Description &&
                                                                                           y.Reference == viewmodel.Reference &&
                                                                                           y.UserId == userId)))
                .Returns(result);

            // Act
            target.CreateFurtherControlMeasureTask(viewmodel, documentsToSaveViewModel);

            // Assert
            _furtherControlMeasureTaskService.VerifyAll();
            _businessSafeSessionManager.Verify(x => x.CloseSession(), Times.Exactly(1));
        }
Пример #5
0
        public void Given_Get_When_Save_Then_Returns_OverviewViewModel()
        {
            // Given
            var target = GetTarget();
            var viewModel = new OverviewViewModel();
            var viewDocModel = new DocumentsToSaveViewModel();
            
            // When
            var result = target.Save(_accidentRecordId, _companyId, viewModel, viewDocModel) as ViewResult;

            // Then
            Assert.That(result.Model, Is.InstanceOf<OverviewViewModel>());
        }
Пример #6
0
        public JsonResult SaveAndNext(OverviewViewModel overviewModel,DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            Validate(overviewModel);

            if (ModelState.IsValid)
            {
                UpdateAccidentRecordOverview(overviewModel, documentsToSaveViewModel);
                return Json(new { Success = true });
            }
            else
            {   
                return ModelStateErrorsAsJson();
            }
        }
Пример #7
0
        public ActionResult Save(long accidentRecordId, long companyId, OverviewViewModel overviewModel, DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            Validate(overviewModel);

            if (!ModelState.IsValid)
            {
                return InvalidAddAccidentDocumentsViewResult(overviewModel);
            }

            UpdateAccidentRecordOverview(overviewModel, documentsToSaveViewModel);
            TempData["Notice"] = "Accident overview successfully updated";

            return View("Index", GetViewModel(accidentRecordId, CurrentUser.CompanyId));

        }
        public JsonResult CreateFurtherControlMeasureTask(AddRiskAssessmentFurtherControlMeasureTaskViewModel viewmodel, DocumentsToSaveViewModel documentsToSave)
        {
            if (!ModelState.IsValid)
            {
                return Json(new { Success = false, Errors = ModelState.GetErrorMessages() });
            }

            MultiHazardRiskAssessmentFurtherControlMeasureTaskDto result;
            Guid taskGuid = Guid.NewGuid();
            using (var session = _businessSafeSessionManager.Session)
            {
                if(!viewmodel.IsRecurring)
                {
                    viewmodel.TaskReoccurringTypeId = (int)TaskReoccurringType.None;
                }

                var saveTaskRequest = SaveFurtherControlMeasureTaskRequest.Create(
                    viewmodel.Title,
                    viewmodel.Description,
                    viewmodel.Reference,
                    viewmodel.TaskCompletionDueDate,
                    viewmodel.TaskStatusId,
                    viewmodel.CompanyId,
                    0,
                    viewmodel.RiskAssessmentHazardId,
                    viewmodel.TaskAssignedToId.Value,
                    (int)viewmodel.FurtherControlMeasureTaskCategory,
                    viewmodel.TaskReoccurringTypeId,
                    viewmodel.FirstDueDate,
                    viewmodel.TaskReoccurringEndDate,
                    !viewmodel.DoNotSendTaskNotification,
                    !viewmodel.DoNotSendTaskCompletedNotification,
                    !viewmodel.DoNotSendTaskOverdueNotification,
                    !viewmodel.DoNotSendTaskDueTomorrowNotification,
                    CurrentUser.UserId,
                    documentsToSave.CreateDocumentRequests,
                    taskGuid
                    );

                result = _furtherControlMeasureTaskService.AddFurtherControlMeasureTask(saveTaskRequest);

                _businessSafeSessionManager.CloseSession();
            }

            _bus.Publish(new TaskAssigned { TaskGuid = taskGuid });

            return Json(new { Success = true, result.Id, viewmodel.RiskAssessmentHazardId, CreatedOn = result.CreatedDate });
        }
        public void Given_invalid_model_state_When_NewFurtherControlMeasureTask_Request_Then_returns_correct_result()
        {
            // Given
            var controller = GetTarget();
            var viewModel = new AddEditFireRiskAssessmentFurtherControlMeasureTaskViewModel();
            var documentsToSave = new DocumentsToSaveViewModel();

            controller.ModelState.AddModelError("error", "some problem");

            // When
            var result = controller.NewFurtherControlMeasureTask(viewModel, documentsToSave) as JsonResult;

            // Then
            Assert.That(result, Is.InstanceOf<JsonResult>());
            Assert.That(result.Data.ToString(), Is.EqualTo("{ Success = False, Errors = System.String[] }"));
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var formCollection = new FormCollection(controllerContext.HttpContext.Request.Form);

            var documentRequestMapper = ObjectFactory.GetInstance<IDocumentRequestMapper>();
            
            var createDocumentRequests = documentRequestMapper.MapCreateRequests(formCollection);
            var deleteDocumentRequests = documentRequestMapper.MapDeleteRequests(formCollection);

            var result = new DocumentsToSaveViewModel()
                             {
                                 CreateDocumentRequests = createDocumentRequests,
                                 DeleteDocumentRequests = deleteDocumentRequests
                             };
            return result;
        }
Пример #11
0
        public void Given_get_When_Save_Then_Returns_View()
        {
            // Given
            var target = GetTarget();
            var viewModel = new OverviewViewModel()
            {
                AccidentRecordId = _accidentRecordId,
                DescriptionHowAccidentHappened = "desc"
            };
            var viewDocModel = new DocumentsToSaveViewModel();

            // When
            var result = target.Save(_accidentRecordId, _companyId, viewModel, viewDocModel);

            // Then
            Assert.IsInstanceOf<ViewResult>(result);
        }
Пример #12
0
        public void Given_valid_request_with_no_documents_to_attach_or_detach_When_save_Then_should_call_correct_methods()
        {
            // Given
            var controller = GetTarget();

            var savingDocumentsViewModel = new DocumentsToSaveViewModel()
            {
                CreateDocumentRequests = new List<CreateDocumentRequest>() {  },
                DeleteDocumentRequests = new List<long>() { }
            };
            
            // When
            controller.Save(_companyId, _riskAssessmentId, savingDocumentsViewModel);

            // Then
            _attachmentService.Verify(x => x.AttachDocumentsToRiskAssessment(It.IsAny<AttachDocumentsToRiskAssessmentRequest>()), Times.Never());
            _attachmentService.Verify(x => x.DetachDocumentsToRiskAssessment(It.IsAny<DetachDocumentsFromRiskAssessmentRequest>()), Times.Never());
        }
        public JsonResult NewFurtherControlMeasureTask(AddEditFireRiskAssessmentFurtherControlMeasureTaskViewModel viewModel, DocumentsToSaveViewModel documentsToSave)
        {
            if (!ModelState.IsValid)
                return Json(new { Success = false, Errors = ModelState.GetErrorMessages() });

            if(!viewModel.IsRecurring)
            {
                viewModel.TaskReoccurringTypeId = (int)TaskReoccurringType.None;
            }
            
            var taskGuid = Guid.NewGuid();
            SaveFurtherControlMeasureTaskRequest request = SaveFurtherControlMeasureTaskRequest.Create(
                                                                                                        viewModel.Title,
                                                                                                        viewModel.Description,
                                                                                                        viewModel.Reference,
                                                                                                        viewModel.TaskCompletionDueDate,
                                                                                                        viewModel.TaskStatusId,
                                                                                                        viewModel.CompanyId,
                                                                                                        viewModel.RiskAssessmentId,
                                                                                                        viewModel.SignificantFindingId,
                                                                                                        viewModel.TaskAssignedToId.GetValueOrDefault(),
                                                                                                        viewModel.TaskReoccurringTypeId,
                                                                                                        viewModel.FirstDueDate, 
                                                                                                        viewModel.TaskReoccurringEndDate, 
                                                                                                        CurrentUser.UserId,
                                                                                                        documentsToSave.CreateDocumentRequests,
                                                                                                        documentsToSave.DeleteDocumentRequests,
                                                                                                        !viewModel.DoNotSendTaskNotification,
                                                                                                        !viewModel.DoNotSendTaskCompletedNotification,
                                                                                                        !viewModel.DoNotSendTaskOverdueNotification,
                                                                                                        !viewModel.DoNotSendTaskDueTomorrowNotification,
                                                                                                        taskGuid);

            FireRiskAssessmentFurtherControlMeasureTaskDto result;
            using (var session = _businessSafeSessionManager.Session)
            {
                result = _furtherControlMeasureTaskService.AddFurtherControlMeasureTask(request);
                _businessSafeSessionManager.CloseSession();
            }


            _eventPublisher.PublishTaskAssigned(taskGuid);
            return Json(new { Success = true, result.Id, CreatedOn = result.CreatedDate });
        }
Пример #14
0
        public void When_post_to_save_next_Then_should_return_correct_result()
        {
            
            // Given
            var target = CreateController();
            
            var savingDocumentsViewModel = new DocumentsToSaveViewModel()
            {
                CreateDocumentRequests = new List<CreateDocumentRequest>() { new CreateDocumentRequest() },
                DeleteDocumentRequests = new List<long>() { 1, 2 }
            };

            // When
            var result = target.SaveAndNext(_companyId, _riskAssessmentId, savingDocumentsViewModel) as JsonResult;

            // Assert
            dynamic data = result.Data;
            Assert.That(data.ToString(), Contains.Substring("Success = True"));
        }
Пример #15
0
        public void Posting_Valid_FormCollection_to_Index_Returns_Success_Json()
        {
            // Given
            _addedDocumentsService.Setup(x => x.Add(It.IsAny<List<CreateDocumentRequest>>(), It.IsAny<Guid>(), It.IsAny<long>()));

            var documentsToSaveViewModel = new DocumentsToSaveViewModel()
                                               {
                                                   CreateDocumentRequests = new List<CreateDocumentRequest>()
                                                                                {
                                                                                    new CreateDocumentRequest()
                                                                                }
                                               };

            // When
            var result = _target.Index(documentsToSaveViewModel);

            // Then
            Assert.That(result, Is.InstanceOf<JsonResult>());
            _addedDocumentsService.VerifyAll();
        }
        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 JsonResult CompleteTask(CompleteTaskViewModel completeTaskViewModel, DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new ArgumentException("Invalid Arguments To Complete Task");
            }

            var request = new CompleteTaskRequest
                              {
                                  CompanyId = completeTaskViewModel.CompanyId,
                                  FurtherControlMeasureTaskId = completeTaskViewModel.FurtherControlMeasureTaskId,
                                  CompletedComments = completeTaskViewModel.CompletedComments,
                                  UserId = CurrentUser.UserId,
                                  CreateDocumentRequests = documentsToSaveViewModel.CreateDocumentRequests,
                                  DocumentLibraryIdsToDelete = documentsToSaveViewModel.DeleteDocumentRequests,
                                  CompletedDate = DateTimeOffset.Now
                              };

            using (var session = _businessSafeSessionManager.Session)
            {
                _furtherControlMeasureTaskService.CompleteFurtherControlMeasureTask(request);
                _businessSafeSessionManager.CloseSession();
            }

            using (var session = _businessSafeSessionManager.Session)
            {
                _furtherControlMeasureTaskService.SendTaskCompletedEmail(request);
                 _businessSafeSessionManager.CloseSession();
            }

            return Json(new SaveTaskResultViewModel
            {
                Success = true,
                Id = completeTaskViewModel.FurtherControlMeasureTaskId,
            });
        }
        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;
        }
        public JsonResult CreateResponsibilityTask(CreateUpdateResponsibilityTaskViewModel viewModel, DocumentsToSaveViewModel documentsToSave)
        {
            JsonResult result = Json(new { Success = false });

            if (!ModelState.IsValid)
            {
                result = Json(new { Success = false, Errors = ModelState.GetErrorMessages() });
            }
            else
            {
                try
                {
                    var taskGuid = Guid.NewGuid();
                    SaveResponsibilityTaskResponse response = null;

                    using (var session = _businessSafeSessionManager.Session)
                    {
                        // move this to Task base entity
                        if(!viewModel.IsRecurring)
                        {
                            viewModel.TaskReoccurringTypeId = (int)TaskReoccurringType.None;
                        }

                        var request = SaveResponsibilityTaskRequest.Create(
                            viewModel.CompanyId,
                            viewModel.ResponsibilityId,
                            viewModel.TaskId = viewModel.TaskId,
                            viewModel.Title,
                            viewModel.Description,
                            viewModel.TaskReoccurringTypeId,
                            viewModel.CompletionDueDate,
                            viewModel.ReoccurringEndDate,
                            CurrentUser.UserId,
                            viewModel.AssignedToId.Value,
                            (int) TaskStatus.Outstanding,
                            viewModel.ReoccurringStartDate,
                            !viewModel.DoNotSendTaskAssignedNotification,
                            !viewModel.DoNotSendTaskCompletedNotification,
                            !viewModel.DoNotSendTaskOverdueNotification,
                            !viewModel.DoNotSendTaskDueTomorrowNotification,
                            taskGuid,
                            viewModel.ResponsibilityTaskSiteId.Value,
                            documentsToSave.CreateDocumentRequests);

                        response = _responsibilitiesService.SaveResponsibilityTask(request);
                        _businessSafeSessionManager.CloseSession();
                    }
                        
                    _bus.Publish(new TaskAssigned {TaskGuid = taskGuid});
                    result = Json(new { Success = true, response.HasMultipleFrequencyChangeToTrue });

                }
                catch (ValidationException validationException)
                {
                    ModelState.AddValidationErrors(validationException);
                }
            }
                        
            return result;
        }
Пример #20
0
        public void Given_Description_Not_Added_Check_Description_Not_Saved()
        {
            //given
            var target = GetTarget();
            var viewModel = new OverviewViewModel();
            var viewDocModel = new DocumentsToSaveViewModel();

            //when
            target.Save(_accidentRecordId, _companyId, viewModel, viewDocModel);

            //Then
            _accidentRecordService.Verify(x => x.SetAccidentRecordOverviewDetails(It.IsAny<AccidentRecordOverviewRequest>()), Times.Never());
        }
        public void Given_valid_model_state_When_NewFurtherControlMeasureTask_Request_Then_should_return_correct_result()
        {
            // Given
            var controller = GetTarget();
            var viewModel = new AddEditFireRiskAssessmentFurtherControlMeasureTaskViewModel()
            {
                CompanyId = 123L,
                RiskAssessmentId = 789L,
                Title = "TItle",
                Description = "A description",
                Reference = "My reference",
                SignificantFindingId = 888L,
                TaskStatusId = 3
            };
            var documentsToSave = new DocumentsToSaveViewModel();

            _furtherControlMeasureTaskService
                .Setup(x => x.AddFurtherControlMeasureTask(It.IsAny<SaveFurtherControlMeasureTaskRequest>()))
                .Returns(new FireRiskAssessmentFurtherControlMeasureTaskDto());

            // When
            var result = controller.NewFurtherControlMeasureTask(viewModel, documentsToSave) as JsonResult;

            // Then
            Assert.That(result.Data.ToString(), Is.EqualTo("{ Success = True, Id = 0, CreatedOn =  }"));
        }
        public void Given_is_recurring_is_false_When_NewFurtherControlMeasureTask_Request_Then_set_recurringtype_to_none()
        {
            // Given
            var controller = GetTarget();
            var viewModel = new AddEditFireRiskAssessmentFurtherControlMeasureTaskViewModel()
            {
                CompanyId = 123L,
                RiskAssessmentId = 789L,
                Title = "TItle",
                Description = "A description",
                Reference = "My reference",
                SignificantFindingId = 888L,
                TaskStatusId = 3,
                IsRecurring = false,
                TaskReoccurringTypeId = (int)TaskReoccurringType.Annually
            };
            var documentsToSave = new DocumentsToSaveViewModel();

            _furtherControlMeasureTaskService
                .Setup(x => x.AddFurtherControlMeasureTask(It.IsAny<SaveFurtherControlMeasureTaskRequest>()))
                .Returns(new FireRiskAssessmentFurtherControlMeasureTaskDto());

            // When
            var result = controller.NewFurtherControlMeasureTask(viewModel, documentsToSave);

            // Then
            _furtherControlMeasureTaskService
                .Verify(x => x.AddFurtherControlMeasureTask(It.Is<SaveFurtherControlMeasureTaskRequest>(y => y.TaskReoccurringTypeId == (int)TaskReoccurringType.None)));
        }
Пример #23
0
        public void given_description_added_check_saved()
        {
            //given
            var target = GetTarget();
            var viewModel = new OverviewViewModel
            {
                AccidentRecordId = _accidentRecordId,
                DescriptionHowAccidentHappened = "desc"
            };

            var viewDocModel = new DocumentsToSaveViewModel();

            //when
            target.Save(_accidentRecordId, _companyId, viewModel, viewDocModel);

            //Then
            _accidentRecordService.Verify(
                x =>
                    x.SetAccidentRecordOverviewDetails(
                      It.Is<AccidentRecordOverviewRequest>(y => y.Description == "desc")));
        }
Пример #24
0
        public void Given_valid_request_When_save_Then_should_return_correct_action_result()
        {
            // Given
            var controller = GetTarget();

            var savingDocumentsViewModel = new DocumentsToSaveViewModel()
            {
                CreateDocumentRequests = new List<CreateDocumentRequest>() { new CreateDocumentRequest() },
                DeleteDocumentRequests = new List<long>() { 1, 2 }
            };

            // When
            var result = controller.Save(_companyId, _riskAssessmentId, savingDocumentsViewModel) as RedirectToRouteResult;

            // Then
            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
            Assert.That(result.RouteValues["controller"], Is.EqualTo("Documents"));
            Assert.That(result.RouteValues["companyId"], Is.EqualTo(_companyId));
            Assert.That(result.RouteValues["riskAssessmentId"], Is.EqualTo(_riskAssessmentId));
        }
Пример #25
0
        public void UpdateAccidentRecordOverview(OverviewViewModel overviewModel,DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            if (documentsToSaveViewModel.CreateDocumentRequests.Count > 0)
            {
                var request = new AddDocumentToAccidentReportRequest
                {
                    AccidentRecordId = overviewModel.AccidentRecordId
                    ,
                    UserId = CurrentUser.UserId,
                    CompanyId = CurrentUser.CompanyId
                    ,
                    DocumentLibraryIds = documentsToSaveViewModel.CreateDocumentRequests.Select(x => new DocumentLibraryFile() { Description = x.Description, Filename = x.Filename, Id = x.DocumentLibraryId }).ToList()
                };
                
                _accidentRecordService.AddAccidentRecordDocument(request);
            }

            if (documentsToSaveViewModel.DeleteDocumentRequests.Count > 0)
            {
                var request = new RemoveDocumentsFromAccidentRecordRequest()
                {
                    AccidentRecordId = overviewModel.AccidentRecordId,
                    UserId = CurrentUser.UserId,
                    CompanyId = CurrentUser.CompanyId,
                    DocumentLibraryIds = documentsToSaveViewModel.DeleteDocumentRequests
                };

                _accidentRecordService.RemoveAccidentRecordDocuments(request);
            }

            var accidentRecordOverviewRequest = new AccidentRecordOverviewRequest()
                              {
                                  AccidentRecordId = overviewModel.AccidentRecordId,
                                  CompanyId = CurrentUser.CompanyId,
                                  UserId = CurrentUser.UserId,
                                  Description = overviewModel.DescriptionHowAccidentHappened,
                                  DoNotSendEmailNotification = overviewModel.DoNotSendEmailNotification
                              };


            _accidentRecordService.SetAccidentRecordOverviewDetails(accidentRecordOverviewRequest);
            
            if (!overviewModel.DoNotSendEmailNotification)
            {
                _accidentRecordService.SendAccidentRecordEmails(overviewModel.AccidentRecordId, CurrentUser.CompanyId, CurrentUser.UserId);
            }
        }
        public JsonResult Complete(CompleteResponsibilityTaskViewModel viewModel, DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new ArgumentException("Invalid Arguments To Complete Responsibility Task");
            }

            var request = new CompleteResponsibilityTaskRequest
                              {
                                  CompanyId = viewModel.CompanyId,
                                  ResponsibilityTaskId = viewModel.ResponsibilityTaskId,
                                  CompletedComments = viewModel.CompletedComments,
                                  UserId = CurrentUser.UserId,
                                  CreateDocumentRequests = documentsToSaveViewModel.CreateDocumentRequests,
                                  DocumentLibraryIdsToDelete = documentsToSaveViewModel.DeleteDocumentRequests,
                                  CompletedDate = DateTimeOffset.Now
                              };

            using (var session = _businessSafeSessionManager.Session)
            {
                _responsibilityTaskService.Complete(request);
                _businessSafeSessionManager.CloseSession();
            }

            using (var session = _businessSafeSessionManager.Session)
            {
                _responsibilityTaskService.SendTaskCompletedNotificationEmail(request);
                _businessSafeSessionManager.CloseSession();
            }

            return Json(new 
            {
                Success = true,
                Id = viewModel.ResponsibilityTaskId,
            });
        }
Пример #27
0
 private void SaveDocuments(long companyId, long riskAssessmentId, DocumentsToSaveViewModel documentsToSaveViewModel)
 {
     AttachDocumentsToRiskAssessment(companyId, riskAssessmentId, documentsToSaveViewModel.CreateDocumentRequests);
     DetachDocumentsFromRiskAssessment(companyId, riskAssessmentId, documentsToSaveViewModel.DeleteDocumentRequests);
 }
Пример #28
0
        public JsonResult SaveAndNext(long companyId, long riskAssessmentId, DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            SaveDocuments(companyId, riskAssessmentId, documentsToSaveViewModel);

            return Json(new { Success = true });
        }
Пример #29
0
        public ActionResult Save(long companyId, long riskAssessmentId, DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            SaveDocuments(companyId, riskAssessmentId, documentsToSaveViewModel);

            return RedirectToAction("Index", "Documents", new { riskAssessmentId, companyId });
        }
 public JsonResult Index(DocumentsToSaveViewModel documentsToSaveViewModel)
 {
     _addedDocumentsService.Add(documentsToSaveViewModel.CreateDocumentRequests, CurrentUser.UserId, CurrentUser.CompanyId);
     return Json(new { Success = true });
 }