public void Update(CreateEditRiskAssessorRequest request)
        {
            _log.Add(request);

            var riskAssessor = _riskAssessorRepository.GetByIdAndCompanyId(request.RiskAssessorId, request.CompanyId);

            riskAssessor.Update(
                GetSiteStructureElement(request.SiteId, request.CompanyId),
                request.HasAccessToAllSites,
                request.DoNotSendReviewDueNotification,
                request.DoNotSendTaskOverdueNotifications,
                request.DoNotSendReviewDueNotification,
                GetUser(request.CreatingUserId, request.CompanyId)
                );

            _riskAssessorRepository.Save(riskAssessor);

        }
        public long Create(CreateEditRiskAssessorRequest request)
        {
            _log.Add(request);

            var employee = _employeeRepository.GetByIdAndCompanyId(request.EmployeeId, request.CompanyId);
            employee.UpdateRiskAssessorDetails(true,
                request.DoNotSendTaskOverdueNotifications,
                request.DoNotSendTaskCompletedNotifications,
                request.DoNotSendReviewDueNotification,
                GetUser(request.CreatingUserId, request.CompanyId));

            employee.RiskAssessor.HasAccessToAllSites = request.HasAccessToAllSites;
            employee.RiskAssessor.Site = GetSiteStructureElement(request.SiteId, request.CompanyId);

            _siteStructureElementRepository.Initialize(employee.RiskAssessor.Site);

            _riskAssessorRepository.Save(employee.RiskAssessor);
            return employee.RiskAssessor.Id;


        }
        private long CreateNewRiskAssessor(AddEditRiskAssessorViewModel viewModel)
        {
            var request = new CreateEditRiskAssessorRequest
                          {
                              CompanyId = CurrentUser.CompanyId,
                              CreatingUserId = CurrentUser.UserId,
                              EmployeeId = viewModel.EmployeeId.Value,
                              SiteId = viewModel.SiteId,
                              DoNotSendTaskOverdueNotifications = viewModel.DoNotSendTaskOverdueNotifications,
                              DoNotSendTaskCompletedNotifications = viewModel.DoNotSendTaskCompletedNotifications,
                              DoNotSendReviewDueNotification = viewModel.DoNotSendReviewDueNotification,
                              HasAccessToAllSites = viewModel.HasAccessToAllSites
                          };

            return _riskAssessorService.Create(request);
        }
Пример #4
0
        public void Setup()
        {
            _siteId = 456L;
            _companyId = 123L;
            _employeeId = Guid.NewGuid();
            _userForAuditingId = Guid.NewGuid();

            _request = new CreateEditRiskAssessorRequest()
            {
                CompanyId = _companyId,
                CreatingUserId = _userForAuditingId,
                DoNotSendReviewDueNotification = true,
                DoNotSendTaskCompletedNotifications = false,
                DoNotSendTaskOverdueNotifications = true,
                EmployeeId = _employeeId,
                SiteId = _siteId,
                HasAccessToAllSites = false
            };

            _riskAssessorRepository = new Mock<IRiskAssessorRepository>();

            _riskAssessorRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(new RiskAssessor());

            _riskAssessorRepository
                .Setup(x => x.Save(It.IsAny<RiskAssessor>()));


            _employee = new Employee()
                           {
                               Id = _employeeId,
                               CompanyId = _companyId
                           };

            _employeeRepository = new Mock<IEmployeeRepository>();
            _employeeRepository
                .Setup(x => x.GetByIdAndCompanyId(_employee.Id, _employee.CompanyId))
                .Returns(_employee);

            _site = new Site
                       {
                           Id = _siteId,
                           ClientId = _companyId,
                           Name = "Middle Earth"
                       };

            _siteRepository = new Mock<ISiteRepository>();
            _siteRepository
                .Setup(x => x.GetByIdAndCompanyId(_siteId, _companyId))
                .Returns(_site);

            _siteStructureElementRepository = new Mock<ISiteStructureElementRepository>();
            _siteStructureElementRepository
                .Setup(x => x.GetByIdAndCompanyId(_siteId, _companyId))
                .Returns(_site);

            _userForAuditing = new UserForAuditing
                                  {
                                      Id = _userForAuditingId,
                                      CompanyId = _companyId
                                  };

            _userForAuditingRepository = new Mock<IUserForAuditingRepository>();
            _userForAuditingRepository
                .Setup(x => x.GetByIdAndCompanyId(_userForAuditingId, _companyId))
                .Returns(_userForAuditing);

            _riskAssessor = new RiskAssessor
                            {
                                Id = 1119L
                            };

            _log = new Mock<IPeninsulaLog>();
            _log
                .Setup(x => x.Add(It.IsAny<object>()));
        }
        public JsonResult Edit(AddEditRiskAssessorViewModel viewModel)
        {
            Validate(viewModel);

            if (viewModel.RiskAssessorId.HasValue == false)
                throw new ArgumentNullException("RiskAssessorId not defined");

            if (!ModelState.IsValid)
            {
                return ModelStateErrorsWithKeysAsJson();
            }

            var request = new CreateEditRiskAssessorRequest()
                              {
                                  CompanyId = CurrentUser.CompanyId,
                                  CreatingUserId = CurrentUser.UserId,
                                  DoNotSendReviewDueNotification = viewModel.DoNotSendReviewDueNotification,
                                  DoNotSendTaskCompletedNotifications = viewModel.DoNotSendTaskCompletedNotifications,
                                  DoNotSendTaskOverdueNotifications = viewModel.DoNotSendTaskOverdueNotifications,
                                  EmployeeId = viewModel.EmployeeId.Value,
                                  HasAccessToAllSites = viewModel.HasAccessToAllSites,
                                  SiteId = viewModel.SiteId,
                                  RiskAssessorId = viewModel.RiskAssessorId.Value
                              };
            _riskAssessorService.Update(request);
            var riskAssessor = _riskAssessorService.GetByIdAndCompanyId(viewModel.RiskAssessorId.Value, CurrentUser.CompanyId);
            return Json(new
            {
                Success = true,
                RiskAssessorId = viewModel.RiskAssessorId.Value,
                Forename = riskAssessor.Employee.Forename,
                Surname = riskAssessor.Employee.Surname,
                SiteName = riskAssessor.SiteName,
                DoNotSendReviewDueNotification = riskAssessor.DoNotSendReviewDueNotification,
                DoNotSendTaskCompletedNotifications = riskAssessor.DoNotSendTaskCompletedNotifications,
                DoNotSendTaskOverdueNotifications = riskAssessor.DoNotSendTaskOverdueNotifications,
                FormattedName = riskAssessor.Employee.FullName,
            });
        }