예제 #1
0
        public ActionResult Save(SaveHazardsViewModel viewModel)
        {
            UpdateRiskAssessmentFireSafetyControlMeasuresAndPeopleAtRisk(viewModel);

            TempData["Notice"] = "Hazards have been saved.";

            return RedirectToAction("Index", new { companyId = viewModel.CompanyId, riskAssessmentId = viewModel.RiskAssessmentId });
        }
예제 #2
0
 private void UpdateRiskAssessmentHazards(SaveHazardsViewModel viewModel)
 {
     _multiHazardRiskAssessmentAttachmentService.AttachHazardsToRiskAssessment(new AttachHazardsToRiskAssessmentRequest
     {
         CompanyId = viewModel.CompanyId,
         UserId = CurrentUser.UserId,
         RiskAssessmentId = viewModel.RiskAssessmentId,
         Hazards = viewModel.HazardIds.Select((hazardId,index) => new AttachHazardsToRiskAssessmentHazardDetail() { Id = hazardId, OrderNumber = index+1}).ToList()
     });
 }
예제 #3
0
        public void Given_valid_viewmodel_When_save_Then_should_call_correct_methods()
        {
            //Given
            var target = GetTarget();
            Guid userId = target.CurrentUser.UserId;

            var viewModel = new SaveHazardsViewModel()
            {
                CompanyId = 500,
                RiskAssessmentId = 588,
                HazardIds = new []{ 1L},
                PeopleAtRiskIds = new[] {2L}
            };

            var expectedAttachHazardsToRiskAssessmentHazardDetail = new AttachHazardsToRiskAssessmentHazardDetail() { Id = viewModel.HazardIds[0], OrderNumber = 1 };

            AttachHazardsToRiskAssessmentRequest passedAttachHazardsToRiskAssessmentRequest = null;

            _multiHazardRiskAssessmentAttachmentService
                .Setup(x => x.AttachHazardsToRiskAssessment(It.IsAny<AttachHazardsToRiskAssessmentRequest>()))
                .Callback<AttachHazardsToRiskAssessmentRequest>(parameter =>
                {
                    passedAttachHazardsToRiskAssessmentRequest = parameter;

                });

            //When
            target.Save(viewModel);

            //Then
            Assert.That(passedAttachHazardsToRiskAssessmentRequest.CompanyId, Is.EqualTo(viewModel.CompanyId));
            Assert.That(passedAttachHazardsToRiskAssessmentRequest.RiskAssessmentId, Is.EqualTo(viewModel.RiskAssessmentId));
            Assert.That(passedAttachHazardsToRiskAssessmentRequest.UserId, Is.EqualTo(userId));
            Assert.That(passedAttachHazardsToRiskAssessmentRequest.Hazards[0].Id, Is.EqualTo(expectedAttachHazardsToRiskAssessmentHazardDetail.Id));
            Assert.That(passedAttachHazardsToRiskAssessmentRequest.Hazards[0].OrderNumber, Is.EqualTo(expectedAttachHazardsToRiskAssessmentHazardDetail.OrderNumber));

            _riskAssessmentAttachmentService
                .Verify(x => x.AttachPeopleAtRiskToRiskAssessment(It.Is<AttachPeopleAtRiskToRiskAssessmentRequest>(y =>
                    y.CompanyId == viewModel.CompanyId &&
                    y.RiskAssessmentId == viewModel.RiskAssessmentId &&
                    y.PeopleAtRiskIds == viewModel.PeopleAtRiskIds &&
                    y.UserId == userId)));
        }
예제 #4
0
        public void Given_valid_viewmodel_When_save_Then_should_return_correct_result()
        {
            //Given
            var target = GetTarget();

            var viewModel = new SaveHazardsViewModel()
                                {
                                    CompanyId = 500,
                                    RiskAssessmentId = 588,
                                    HazardIds = new[] { 1L },
                                    PeopleAtRiskIds = new[] { 2L }
                                };

            //When
            var result = target.SaveAndNext(viewModel) as JsonResult;

            //Then
            Assert.That(result.Data.ToString(), Contains.Substring("{ Success = True }"));
            
        }
예제 #5
0
        public void Given_valid_viewmodel_When_save_Then_should_return_correct_result()
        {
            //Given
            var target = GetTarget();
            
            var viewModel = new SaveHazardsViewModel()
            {
                CompanyId = 500,
                RiskAssessmentId = 588,
                HazardIds = new[] { 1L },
                PeopleAtRiskIds = new[] { 2L }
            };

            //When
            var result = target.Save(viewModel) as RedirectToRouteResult;

            //Then
            Assert.That(result.RouteValues["controller"], Is.Null);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
            Assert.That(result.RouteValues["companyId"], Is.EqualTo(viewModel.CompanyId));
            Assert.That(result.RouteValues["riskAssessmentId"], Is.EqualTo(viewModel.RiskAssessmentId));
        }
예제 #6
0
        public void Given_valid_viewmodel_When_save_Then_should_call_correct_methods()
        {
            //Given
            var target = GetTarget();
            Guid userId = target.CurrentUser.UserId;

            var viewModel = new SaveHazardsViewModel()
                                {
                                    CompanyId = 500,
                                    RiskAssessmentId = 588,
                                    HazardIds = new []{ 1L},
                                    PeopleAtRiskIds = new []{2L},
                                    SourceOfFuelsIds = new[]{3L}
                                };

            //When
            target.Save(viewModel);

            //Then
            _riskAssessmentAttachmentService.Verify(x => x.AttachPeopleAtRiskToRiskAssessment(It.Is<AttachPeopleAtRiskToRiskAssessmentRequest>(y => y.CompanyId == viewModel.CompanyId &&
                                                                                                                         y.RiskAssessmentId == viewModel.RiskAssessmentId &&
                                                                                                                         y.PeopleAtRiskIds == viewModel.PeopleAtRiskIds &&
                                                                                                                         y.UserId == userId)));

            _riskAssessmentAttachmentService.Verify(x => x.AttachFireSafetyControlMeasuresToRiskAssessment(It.Is<AttachFireSafetyControlMeasuresToRiskAssessmentRequest>(y => y.CompanyId == viewModel.CompanyId &&
                                                                                                                         y.RiskAssessmentId == viewModel.RiskAssessmentId &&
                                                                                                                         y.FireSafetyControlMeasureIds == viewModel.FireSafetyControlMeasureIds &&
                                                                                                                         y.UserId == userId)));

            _riskAssessmentAttachmentService.Verify(x => x.AttachSourcesOfFuelToRiskAssessment(It.Is<AttachSourceOfFuelToRiskAssessmentRequest>(y => y.CompanyId == viewModel.CompanyId &&
                                                                                                             y.RiskAssessmentId == viewModel.RiskAssessmentId &&
                                                                                                             y.SourceOfFuelIds == viewModel.SourceOfFuelsIds &&
                                                                                                             y.UserId == userId)));

            _riskAssessmentAttachmentService.Verify(x => x.AttachSourcesOfIgnitionToRiskAssessment(It.Is<AttachSourceOfIgnitionToRiskAssessmentRequest>(y => y.CompanyId == viewModel.CompanyId &&
                                                                                                             y.RiskAssessmentId == viewModel.RiskAssessmentId &&
                                                                                                             y.SourceOfIgnitionIds == viewModel.SourceOfIgnitionIds &&
                                                                                                             y.UserId == userId)));
        }
예제 #7
0
        private void UpdateRiskAssessmentFireSafetyControlMeasuresAndPeopleAtRisk(SaveHazardsViewModel viewModel)
        {
            _fireRiskAssessmentAttachmentService.AttachPeopleAtRiskToRiskAssessment(new AttachPeopleAtRiskToRiskAssessmentRequest
            {
                CompanyId = viewModel.CompanyId,
                UserId = CurrentUser.UserId,
                RiskAssessmentId =
                    viewModel.RiskAssessmentId,
                PeopleAtRiskIds =
                    viewModel.PeopleAtRiskIds
            });

            _fireRiskAssessmentAttachmentService.AttachFireSafetyControlMeasuresToRiskAssessment(new AttachFireSafetyControlMeasuresToRiskAssessmentRequest()
            {
                CompanyId = viewModel.CompanyId,
                UserId = CurrentUser.UserId,
                RiskAssessmentId =
                    viewModel.RiskAssessmentId,
                FireSafetyControlMeasureIds = 
                    viewModel.FireSafetyControlMeasureIds
            });

            _fireRiskAssessmentAttachmentService.AttachSourcesOfFuelToRiskAssessment(new AttachSourceOfFuelToRiskAssessmentRequest()
            {
                CompanyId = viewModel.CompanyId,
                UserId = CurrentUser.UserId,
                RiskAssessmentId =
                    viewModel.RiskAssessmentId,
                SourceOfFuelIds = 
                    viewModel.SourceOfFuelsIds
            });

            _fireRiskAssessmentAttachmentService.AttachSourcesOfIgnitionToRiskAssessment(new AttachSourceOfIgnitionToRiskAssessmentRequest()
            {
                CompanyId = viewModel.CompanyId,
                UserId = CurrentUser.UserId,
                RiskAssessmentId =
                    viewModel.RiskAssessmentId,
                SourceOfIgnitionIds = 
                    viewModel.SourceOfIgnitionIds
            });
        }
예제 #8
0
 public JsonResult SaveAndNext(SaveHazardsViewModel viewModel)
 {
     UpdateRiskAssessmentFireSafetyControlMeasuresAndPeopleAtRisk(viewModel);
     return Json(new { Success = true });
 }
예제 #9
0
 public ActionResult Save(SaveHazardsViewModel viewModel)
 {
     UpdateRiskAssessmentHazards(viewModel);
     return RedirectToAction("Index", new { companyId = viewModel.CompanyId, riskAssessmentId = viewModel.RiskAssessmentId });
 }
예제 #10
0
 public JsonResult SaveAndNext(SaveHazardsViewModel viewModel)
 {
     UpdateRiskAssessmentHazards(viewModel);
     return Json(new { Success = true });
 }