Exemplo n.º 1
0
        // TODO: move into imported record class
        private AddEmployeeRequest MapEmployeeRecordToAddEmployeeRequest(ImportedData importedData, int idx)
        {
            var addEmployeeRequest = new AddEmployeeRequest();

            var dictionary = importedData.GetRecordAsDictionary(idx);

            addEmployeeRequest.CompanyId = _clientID;
            addEmployeeRequest.UserId = SystemUserId;


            // Mandatory fields
            addEmployeeRequest.Forename = dictionary["Forename"];
            if (String.IsNullOrEmpty(addEmployeeRequest.Forename))
            {
                throw new Exception("Record " + (idx + 1).ToString() + " - Forename cannot be empty");
            }

            addEmployeeRequest.Surname = dictionary["Surname"];
            if (String.IsNullOrEmpty(addEmployeeRequest.Surname))
            {
                throw new Exception("Record " + (idx + 1).ToString() + " - Surname cannot be empty");
            }

            // Non-mandatory fields
            addEmployeeRequest.EmployeeReference = GetStringValueByKeyReturnNullIfNotFound(dictionary, "EmployeeReference");
            addEmployeeRequest.Title = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Title");
            addEmployeeRequest.Sex = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Gender");
            addEmployeeRequest.DateOfBirth = DateOfBirth(dictionary);
            addEmployeeRequest.NationalityId = GetIntValueByKeyReturnNullIfNotFound(dictionary, "NationalityId");
            addEmployeeRequest.NINumber = GetStringValueByKeyReturnNullIfNotFound(dictionary, "NI Number");
            addEmployeeRequest.DrivingLicenseNumber = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Driving Licence No.");
            addEmployeeRequest.PPSNumber = GetStringValueByKeyReturnNullIfNotFound(dictionary, "PPSNumber");
            addEmployeeRequest.PassportNumber = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Passport No");
            addEmployeeRequest.WorkVisaNumber = GetStringValueByKeyReturnNullIfNotFound(dictionary, "WorkVisaNumber");
            addEmployeeRequest.WorkVisaExpirationDate = GetDateTimeValueByKeyReturnNullIfNotFound(dictionary, "WorkVisaExpiryDate");
            addEmployeeRequest.HasDisability = GetBooleanValueByKeyReturnFalseIfNotFound(dictionary, "Disabled");
            addEmployeeRequest.HasCompanyVehicle = GetBooleanValueByKeyReturnFalseIfNotFound(dictionary, "CompanyCar");
            addEmployeeRequest.Address1 = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Address Line 1");
            addEmployeeRequest.Address2 = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Address Line 2");
            addEmployeeRequest.Address3 = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Address Line 3");
            addEmployeeRequest.Town = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Town");
            addEmployeeRequest.County = GetStringValueByKeyReturnNullIfNotFound(dictionary, "County");
            addEmployeeRequest.Postcode = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Postcode");
            addEmployeeRequest.Telephone = GetStringValueByKeyReturnNullIfNotFound(dictionary,
                                                                                   new string[]
                                                                                                   {
                                                                                                       "Telephone",
                                                                                                       "Home Telephone"
                                                                                                   });
            addEmployeeRequest.Mobile = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Mobile");
            addEmployeeRequest.Mobile = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Mobile No.");
            addEmployeeRequest.Email = GetStringValueByKeyReturnNullIfNotFound(dictionary, "Email");
            addEmployeeRequest.JobTitle = GetStringValueByKeyReturnNullIfNotFound(dictionary,
                                                                                  new string[]
                                                                                                  {
                                                                                                      "Job Title",
                                                                                                      "Job Role"
                                                                                                  });

            return addEmployeeRequest;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="importedData"></param>
        private void WriteToBso( ImportedData importedData)
        {          
            var sessionFactory = GetSessionFactory(_connectionString);
            var session = sessionFactory.OpenSession();

            CurrentSessionContext.Bind(session);

            using (var transaction = session.BeginTransaction())
            {
                try
                {
                    for (int idx = 0; idx < importedData.Records.Count; idx++ )
                    {                        
                        AddEmployeeRequest addEmployeeRequest = MapEmployeeRecordToAddEmployeeRequest(importedData, idx);
                                                                     
                        if (!DoesEmployeeAlreadyExistForThisClient(addEmployeeRequest))
                        {
                           _employeeService.Add(addEmployeeRequest);

                           Console.WriteLine(string.Format("Client {0} import - added employee {1} {2}",
                                                            _CAN, addEmployeeRequest.Forename.ToUpper(), addEmployeeRequest.Surname.ToUpper() ));
                        }
                        else
                        {
                            Console.WriteLine(string.Format("{0} {1} already exists for client {2} and cannot be imported.",
                                                        addEmployeeRequest.Forename.ToUpper(), addEmployeeRequest.Surname.ToUpper(), _CAN ));                          
                        }
                    }
                    session.Flush();
                    transaction.Commit();
                }
                finally
                {
                    sessionFactory.GetCurrentSession().Dispose();
                    CurrentSessionContext.Unbind(sessionFactory);
                }                
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private ImportedData ReadFile(FileInfo file)
        {
            ImportedData importedData =  new ImportedData();

            using (var fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var streamReader = new StreamReader(fileStream))
                {
                    importedData.AddHeaderRow(streamReader.ReadLine());

                    while (streamReader.Peek() >= 0)
                    {
                        importedData.AddRecord(streamReader.ReadLine());
                    }
                }

                fileStream.Close();
            }
            
            return importedData;
        }