public void Save(SaveFireRiskAssessmentChecklistRequest request)
        {
            _log.Add(request);

            try
            {
                var fireRiskAssessmentChecklist = _fireRiskAssessmentChecklistRepository.GetById(request.FireRiskAssessmentChecklistId);
                var currentUser = _userForAuditingRepository.GetByIdAndCompanyId(request.CurrentUserId, request.CompanyId);
                var submitAnswerParameterClasses = new List<SubmitFireAnswerParameters>();

                foreach (var submitAnswerRequest in request.Answers)
                {
                    var question = _questionRepository.GetById(submitAnswerRequest.QuestionId);

                    submitAnswerParameterClasses.Add(new SubmitFireAnswerParameters
                    {
                        AdditionalInfo = submitAnswerRequest.AdditionalInfo,
                        YesNoNotApplicableResponse = submitAnswerRequest.YesNoNotApplicableResponse,
                        Question = question
                    });
                }

                fireRiskAssessmentChecklist.Save(submitAnswerParameterClasses, currentUser);
                _fireRiskAssessmentChecklistRepository.Save(fireRiskAssessmentChecklist);
            }
            catch (Exception ex)
            {
                _log.Add(ex);
                throw;
            }
        }
 public static SaveFireRiskAssessmentChecklistRequest CreateSaveRequest(this FireRiskAssessmentChecklistViewModel viewModel, CustomPrincipal user)
 {
     var request = new SaveFireRiskAssessmentChecklistRequest
     {
         FireRiskAssessmentId = viewModel.RiskAssessmentId,
         FireRiskAssessmentChecklistId = viewModel.FireRiskAssessmentChecklistId,
         CompanyId = viewModel.CompanyId,
         Answers = viewModel.CreateFireAnswerRequests(),
         CurrentUserId = user.UserId
     };
     return request;
 }
        public void SaveFireRiskAssessmentChecklist(SaveFireRiskAssessmentChecklistRequest request)
        {
            _log.Add(request);

            var fireRiskAssessment = _fireRiskAssessmentRepository.GetById(request.FireRiskAssessmentId);
            var currentUser = _auditedUserRepository.GetByIdAndCompanyId(request.CurrentUserId, request.CompanyId);

            var submitAnswerParameterClasses = CreateSubmitAnswerParameters(request.Answers);

            fireRiskAssessment.SaveFireRiskAssessmentChecklist(submitAnswerParameterClasses, currentUser);
            _fireRiskAssessmentRepository.Save(fireRiskAssessment);

        }
Esempio n. 4
0
        public void TestFixtureSetUp()
        {
            _fireRiskAssessmentChecklistId = 234L;
            _companyId = 4251L;
            _userId = Guid.NewGuid();
            _fireRiskAssessmentChecklistRepository = new Mock<IFireRiskAssessmentChecklistRepository>();
            _userRepository = new Mock<IUserForAuditingRepository>();
            _questionRepository = new Mock<IQuestionRepository>();
            _log = new Mock<IPeninsulaLog>();
            _fireRiskAssessmentChecklist = new Mock<FireRiskAssessmentChecklist>();

            _request = new SaveFireRiskAssessmentChecklistRequest
                              {
                                  FireRiskAssessmentChecklistId = _fireRiskAssessmentChecklistId,
                                  CurrentUserId = _userId,
                                  CompanyId = _companyId,
                                  Answers = new List<SubmitFireAnswerRequest>
                                                {
                                                    new SubmitFireAnswerRequest
                                                        {
                                                            QuestionId = 201L,
                                                            YesNoNotApplicableResponse = YesNoNotApplicableEnum.Yes,
                                                            AdditionalInfo = "Test Additional Info 1"
                                                        },
                                                    new SubmitFireAnswerRequest
                                                        {
                                                            QuestionId = 202L,
                                                            YesNoNotApplicableResponse = YesNoNotApplicableEnum.No
                                                        },
                                                    new SubmitFireAnswerRequest
                                                        {
                                                            QuestionId = 203L,
                                                            YesNoNotApplicableResponse =
                                                                YesNoNotApplicableEnum.NotApplicable
                                                        },
                                                    new SubmitFireAnswerRequest
                                                        {
                                                            QuestionId = 204L
                                                        },
                                                }
                              };

            _fireRiskAssessmentChecklistRepository
                .Setup(x => x.GetById(_fireRiskAssessmentChecklistId))
                .Returns(_fireRiskAssessmentChecklist.Object);

            _userRepository
                .Setup(x => x.GetById(_userId))
                .Returns(new UserForAuditing());

            _questionRepository
                .Setup(x => x.GetById(201L))
                .Returns(new Question{ Id = 201L });

            _questionRepository
                .Setup(x => x.GetById(202L))
                .Returns(new Question { Id = 202L });

            _questionRepository
                .Setup(x => x.GetById(203L))
                .Returns(new Question { Id = 203L });

            _questionRepository
                .Setup(x => x.GetById(204L))
                .Returns(new Question { Id = 204L });

            var fireRiskAssessmentChecklistService = new FireRiskAssessmentChecklistService(
                _fireRiskAssessmentChecklistRepository.Object,
                _userRepository.Object,
                _questionRepository.Object,
                _log.Object,
                null);

            fireRiskAssessmentChecklistService.Save(_request);
        }