コード例 #1
0
ファイル: SaveTests.cs プロジェクト: mnasif786/Business-Safe
        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>());
        }
コード例 #2
0
        public JsonResult SaveAndNext(OverviewViewModel overviewModel,DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            Validate(overviewModel);

            if (ModelState.IsValid)
            {
                UpdateAccidentRecordOverview(overviewModel, documentsToSaveViewModel);
                return Json(new { Success = true });
            }
            else
            {   
                return ModelStateErrorsAsJson();
            }
        }
コード例 #3
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 OverviewViewModel GetViewModel()
        {
            var accidentRecord = _accidentRecordService.GetByIdAndCompanyIdWithAccidentRecordDocuments(_accidentRecordId, _companyId);
            var viewModel = new OverviewViewModel();

            viewModel.AccidentRecordId = _accidentRecordId;
            viewModel.CompanyId = _companyId;
            viewModel.DescriptionHowAccidentHappened = accidentRecord.DescriptionHowAccidentHappened;
            viewModel.IsReportable = accidentRecord.IsReportable;
            viewModel.DoNotSendEmailNotification = accidentRecord.DoNotSendEmailNotification;
            viewModel.EmailNotificationSent = accidentRecord.EmailNotificationSent;
            viewModel.Documents = new DocumentsViewModel()
                                                    {
                                                        CompanyId = _companyId,
                                                        RiskAssessmentId = 0,
                                                        ExistingDocumentsViewModel = new ExistingDocumentsViewModel()
                                                                                         {
                                                                                             CanDeleteDocuments = true,
                                                                                             CanEditDocumentType = false,
                                                                                             DocumentOriginTypeId = 1,
                                                                                             DocumentTypeId = (int) DocumentTypeEnum.AccidentRecord
                                                                                         }
                                                    };

            viewModel.Documents.ExistingDocumentsViewModel.PreviouslyAddedDocuments = accidentRecord.AccidentRecordDocuments
                .Select(x => new PreviouslyAddedDocumentGridRowViewModel()
                                 {
                                     Description = x.Description,
                                     DocumentLibraryId = x.DocumentLibraryId,
                                     DocumentOriginType = DocumentOriginType.TaskCompleted,
                                     DocumentTypeName = x.DocumentType.Name,
                                     Filename = x.Filename,
                                     Id = x.Id
                                 }).ToList();
            viewModel.NextStepsVisible = accidentRecord.NextStepsAvailable;

            if (accidentRecord.SiteWhereHappened != null)
            {
                var accidentRecordNotificationMemberEmails =
                    _siteService.GetAccidentRecordNotificationMembers(accidentRecord.SiteWhereHappened.Id).Where(a => a.HasEmail());

                viewModel.AccidentRecordNotificationMemberEmails = accidentRecordNotificationMemberEmails
                                                    .Select( a => new AccidentRecordNotificationMemberEmail(){Email =  a.Email(), Name = a.FullName()} ).ToList();

            }

            return viewModel;
        }
コード例 #5
0
ファイル: SaveTests.cs プロジェクト: mnasif786/Business-Safe
        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);
        }
コード例 #6
0
ファイル: SaveTests.cs プロジェクト: mnasif786/Business-Safe
        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")));
        }
コード例 #7
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);
            }
        }
コード例 #8
0
 private void Validate(OverviewViewModel viewModel)
 {
     if (String.IsNullOrEmpty(viewModel.DescriptionHowAccidentHappened))
     {
         ModelState.AddModelError("EventsDescription", "Briefly describe how the accident happened.");
     }
 }
コード例 #9
0
 private ActionResult InvalidAddAccidentDocumentsViewResult(OverviewViewModel model)
 {
     return View("Index", GetViewModel(model.AccidentRecordId, CurrentUser.CompanyId));
 }
コード例 #10
0
ファイル: SaveTests.cs プロジェクト: mnasif786/Business-Safe
        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());
        }