public UpdateEmployeeRequest Map(EmployeeViewModel viewModel, Guid userId)
        {
            var result = new UpdateEmployeeRequest()
            {
                EmployeeId = viewModel.EmployeeId.GetValueOrDefault(),
                EmployeeReference = viewModel.EmployeeReference,
                Title = (string.IsNullOrEmpty(viewModel.NameTitle) || viewModel.NameTitle.ToLower().Contains("select") ? string.Empty : viewModel.NameTitle),
                Forename = viewModel.Forename,
                Surname = viewModel.Surname,
                MiddleName = viewModel.MiddleName,
                PreviousSurname = viewModel.PreviousSurname,
                Sex = viewModel.Sex,
                DateOfBirth = viewModel.DateOfBirth.GetValueOrDefault(),
                NationalityId = viewModel.NationalityId,
                HasDisability = viewModel.HasDisability,
                DisabilityDescription = viewModel.DisabilityDescription,
                SiteId = viewModel.SiteId,
                JobTitle = viewModel.JobTitle,
                EmploymentStatusId = viewModel.EmploymentStatusId,
                NINumber = viewModel.NINumber,
                PassportNumber = viewModel.PassportNumber,
                PPSNumber = viewModel.PPSNumber,
                WorkVisaNumber = viewModel.WorkVisaNumber,
                WorkVisaExpirationDate = viewModel.WorkVisaExpirationDate.GetValueOrDefault(),
                DrivingLicenseNumber = viewModel.DrivingLicenseNumber,
                DrivingLicenseExpirationDate = viewModel.DrivingLicenseExpirationDate.GetValueOrDefault(),
                HasCompanyVehicle = viewModel.HasCompanyVehicle,
                CompanyVehicleTypeId = viewModel.CompanyVehicleTypeId,
                CompanyVehicleRegistration = viewModel.CompanyVehicleRegistration,
                Address1 = viewModel.Address1,
                Address2 = viewModel.Address2,
                Address3 = viewModel.Address3,
                Town = viewModel.Town,
                County = viewModel.County,
                CountryId = viewModel.CountryId.GetValueOrDefault(),
                Postcode = viewModel.Postcode,
                Telephone = viewModel.Telephone,
                Mobile = viewModel.Mobile,
                Email = viewModel.Email,
                UserId = userId,
                CompanyId = viewModel.CompanyId,
                ContactDetailId = viewModel.ContactDetailId,
                IsRiskAssessor = viewModel.IsRiskAssessor,
                DoNotSendTaskOverdueNotifications = viewModel.DoNotSendTaskOverdueNotifications,
                DoNotSendTaskCompletedNotifications = viewModel.DoNotSendTaskCompletedNotifications,
                DoNotSendReviewDueNotification = viewModel.DoNotSendReviewDueNotification,
                RiskAssessorHasAccessToAllSites = viewModel.RiskAssessorHasAccessToAllSites,
                RiskAssessorSiteId = viewModel.RiskAssessorSiteId.HasValue ? viewModel.RiskAssessorSiteId.Value : 0,
                NotificationType = MapNotificationType(viewModel.NotificationType),
                NotificiationFrequency = viewModel.NotificationFrequency

            };
            result.UserId = userId;
            return result;
        }
Ejemplo n.º 2
0
 private AddUpdateEmployeeParameters GetUpdatingEmployeeParameters(UpdateEmployeeRequest addEmployeeRequest)
 {
     return _employeeParametersMapper.Map(addEmployeeRequest);
 }
Ejemplo n.º 3
0
        private static bool CanSendUpdateRegistrationRequest(UpdateEmployeeRequest request, Employee employee)
        {
            bool sendUpdateRegistrationRequest = (request.Telephone != (employee.ContactDetails.Any()
                ? employee.ContactDetails[0].Telephone1 : null))
                                                 ||
                                                 (request.Email != (employee.ContactDetails.Any()
                                                     ? employee.ContactDetails[0].Email : null))
                                                 ||
                                                 (request.Mobile != (employee.ContactDetails.Any()
                                                     ? employee.ContactDetails[0].Telephone2 : null));


            // check employee has user associated otherwise exception thrown
            if (employee.User != null && sendUpdateRegistrationRequest == true)
            {
                sendUpdateRegistrationRequest = employee.User.IsRegistered != true && employee.User.Deleted != true;
            }
            else
            {
                // don't update is user details arent added
                sendUpdateRegistrationRequest = false;
            }
            return sendUpdateRegistrationRequest;
        }
Ejemplo n.º 4
0
        public UpdateEmployeeResponse Update(UpdateEmployeeRequest request)
        {
            _log.Add(request);

            try
            {
                var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
                var employee = _employeeRepository.GetByIdAndCompanyId(request.EmployeeId, request.CompanyId);
                var employeeParameters = GetUpdatingEmployeeParameters(request);
                var contactDetailsParameters = GetEmployeeContactDetailParameters(request);
                var riskAssessorSite = request.RiskAssessorSiteId > 0 ? _siteStructureElementRepository.GetByIdAndCompanyId(request.RiskAssessorSiteId, request.CompanyId) : null;

                // to prevent the dreaded,  "was not processed by flush()",  nhibernate error, load the risk assessor site
                if (employee.RiskAssessor != null && employee.RiskAssessor.Site != null)
                {
                    _siteStructureElementRepository.Initialize(employee.RiskAssessor.Site);
                }

                employee.Update(employeeParameters, contactDetailsParameters, user);
                employee.UpdateRiskAssessorDetails(request.IsRiskAssessor, request.RiskAssessorHasAccessToAllSites, riskAssessorSite, request.DoNotSendTaskOverdueNotifications, request.DoNotSendTaskCompletedNotifications, 
                    request.DoNotSendReviewDueNotification, user);

                _employeeRepository.SaveOrUpdate(employee);

                if (CanSendUpdateRegistrationRequest(request, employee))
                {
                    _bus.Send(new UpdateUserRegistration
                    {
                        UserId = employee.User.Id,
                        ActioningUserId = user.Id,
                        SecurityAnswer = String.IsNullOrEmpty(request.Telephone) ? request.Mobile : request.Telephone,
                        Email = request.Email
                    });
                }
                return new UpdateEmployeeResponse
                {
                    Success = true
                };

            }
            catch (InvalidAddUpdateEmployeeContactDetailsParameters ex)
            {
                return new UpdateEmployeeResponse
                {
                    Success = false,
                    Errors = ex.Errors
                };
            }

        }
 public AddUpdateEmployeeParameters Map(UpdateEmployeeRequest request)
 {
     var employeeParameters = CreateEmployeeParameters(request);
     return employeeParameters;
 }
 public UpdateEmployeeRequest Build()
 {
     _request = new UpdateEmployeeRequest
                    {
                        EmployeeReference = _employeeReference,
                        Title = _title,
                        Forename = _forename,
                        Surname = _surname,
                        MiddleName = _middleName,
                        PreviousSurname = _previousSurname,
                        Sex = _sex,
                        DateOfBirth = DateTime.Parse(_dob),
                        NationalityId = _nationalityId,
                        HasDisability = _hasDisability,
                        DisabilityDescription = _disabilityDescription,
                        NINumber = _niNumber,
                        PassportNumber = _passportNumber,
                        PPSNumber = _pps,
                        WorkVisaNumber = _workingVisaNumber,
                        WorkVisaExpirationDate = _workingVisaExpirationDate,
                        DrivingLicenseNumber = _drivingLicenseNumber,
                        DrivingLicenseExpirationDate = _drivingLicenseExpirationDate,
                        HasCompanyVehicle = _hasCompanyVehicle,
                        CompanyVehicleRegistration = _registration,
                        CompanyVehicleTypeId = _companyVehicleTypeId,
                        SiteId = _siteId,
                        JobTitle = _jobTitle,
                        EmploymentStatusId = _employmentStatusId,
                        Address1 = _address1,
                        Address2 = _address2,
                        Address3 = _address3,
                        County = _county,
                        Postcode = _postcode,
                        CountryId = _countryId,
                        Telephone = _telephone,
                        Mobile = _mobile,
                        Email = _email,
                        UserId = _userId,
                        EmployeeId = _employeeId
                    };
     return _request;
 }
Ejemplo n.º 7
0
 private static Expression<Func<Employee, bool>> matchesAddEmployeeRequestProperties(UpdateEmployeeRequest request)
 {
     return y => y.EmployeeReference == request.EmployeeReference &&
                 y.Title == request.Title &&
                 y.Forename == request.Forename &&
                 y.Surname == request.Surname &&
                 y.MiddleName == request.MiddleName &&
                 y.PreviousSurname == request.PreviousSurname &&
                 y.Sex == request.Sex &&
                 y.DateOfBirth == request.DateOfBirth &&
                 y.Nationality.Id == request.NationalityId &&
                 y.HasDisability == request.HasDisability &&
                 y.DisabilityDescription == request.DisabilityDescription &&
                 y.NINumber == request.NINumber &&
                 y.PassportNumber == request.PassportNumber &&
                 y.PPSNumber == request.PPSNumber &&
                 y.WorkVisaNumber == request.WorkVisaNumber &&
                 y.WorkVisaExpirationDate == request.WorkVisaExpirationDate &&
                 y.DrivingLicenseNumber == request.DrivingLicenseNumber &&
                 y.DrivingLicenseExpirationDate == request.DrivingLicenseExpirationDate &&
                 y.HasCompanyVehicle == request.HasCompanyVehicle &&
                 y.CompanyVehicleRegistration == request.CompanyVehicleRegistration &&
                 y.CompanyVehicleType.Id == request.CompanyVehicleTypeId &&
                 y.Site.Id == request.SiteId &&
                 y.JobTitle == request.JobTitle &&
                 y.EmploymentStatus.Id == request.EmploymentStatusId &&
                 y.ContactDetails.First().Address1 == request.Address1 &&
                 y.ContactDetails.First().Address2 == request.Address2 &&
                 y.ContactDetails.First().Address3 == request.Address3 &&
                 y.ContactDetails.First().County == request.County &&
                 y.ContactDetails.First().PostCode == request.Postcode &&
                 y.ContactDetails.First().Country.Id == request.CountryId &&
                 y.ContactDetails.First().Telephone1 == request.Telephone &&
                 y.ContactDetails.First().Telephone2 == request.Mobile && 
                 y.ContactDetails.First().Email == request.Email;
 }