Example #1
0
        static int InsertContactInformation(string contactData, int contactDataType)
        {
            //Email is inserted with the Person

            var contactInfoTypeId          = 0;
            var personContactInformationId = 0;

            //Call AssignHandleTextType() for each Mploy handleType column (0-3)
            //0:
            if (contactDataType != 0 && contactDataType != 3)
            {
                //Calls a method to find the ContactTypeId of the handleText from the Candidate file, and inserts it into the ContactInformation table in the DB.
                contactInfoTypeId = LookupValue.AssignHandleTextType(contactDataType, contactData);
                List <int?> result;
                switch (contactInfoTypeId)
                {
                case 1:
                case 5:
                case 6:
                case 14:
                {
                    result = _db.InsertPersonContactInformation(_personId, contactInfoTypeId, contactData, true, false, 0).ToList();
                }
                break;

                case 2:
                {
                    result = _db.InsertPersonContactInformation(_personId, contactInfoTypeId, contactData, false, true, 0).ToList();
                }
                break;

                default:
                    result = _db.InsertPersonContactInformation(_personId, contactInfoTypeId, contactData, false, false, 0).ToList();
                    break;
                }

                personContactInformationId = Convert.ToInt32(result[0]);
            }

            return(personContactInformationId);
        }
        public static void InsertCandidate(Model.Person candidateRecord, int personId)
        {
            //Get the source type for the candidate:
            var sourceTypeIdForCandidate = ImportHelperMethods.GetSourceTypeId(candidateRecord.Source);

            //Get the candidate type id:
            var candidateStatusTypeId = GetCandidateStatusTypeId(candidateRecord.IdStatus);

            Candidate candidateData = new Candidate();

            if (!string.IsNullOrEmpty(candidateRecord.xdata))
            {
                candidateData = LookupValue.ParseXML(candidateRecord.xdata, candidateData);
            }

            //Get the org id:
            var orgId = ImportHelperMethods.GetIdOrganization(candidateRecord.IdOrganization);

            var candidateId = -1;

            //Insert as a Candidate
            //Returns the Candidate record
            var candidateResult = _db.InsertCandidate(personId, candidateStatusTypeId, null, null, null, sourceTypeIdForCandidate, candidateData.MaxTravelTypeId, null, null, candidateData.CurrentSalary, candidateData.DesiredSalary, candidateData.CurrentRate, candidateData.DesiredRate, null, candidateData.IsOpenToRelocation, 0, candidateRecord.Created, orgId).ToList();

            foreach (var item in candidateResult)
            {
                candidateId = item.Id;
            }


            //Insert the Candidate's Mailing Address and Contact Information and Notes:
            InsertPersonContactInfoAndMailAddress(candidateRecord, personId, candidateId);



            Debug.WriteLine("\n" + "Person imported: " + personId + " " + candidateRecord.FirstName + " " + candidateRecord.LastName + " Customer Id: " + candidateId);
        }
        //static List<KeyValuePair<int, string>> _sourceList = new List<KeyValuePair<int, string>>();


        public static void JobImport()
        {
            using (_db = new Entities())
            {
                try
                {
                    //Reads in the job record from tbJob MPLOY table:
                    var jobData = _db.ReadJob().ToList();

                    //For each job record from the job file table:
                    foreach (var requirementRecord in jobData)
                    {
                        // Sets requirement fields to job data coming from MPLOY
                        var Name      = requirementRecord.PositionTitle;
                        var vMSField  = requirementRecord.RequirementNumber;
                        var startDate = requirementRecord.StartDate;
                        var requirementDescription    = requirementRecord.Description;
                        var requirementTypeId         = requirementRecord.idJobType;
                        var requirementPriorityTypeId = requirementRecord.Priority;
                        var createDate           = requirementRecord.Created;
                        var MPLOYIdUser          = requirementRecord.iduser;
                        var MPLOYIdJob           = requirementRecord.idJob;
                        var MPLOYIdUserRecruiter = requirementRecord.idUserRecruiter;
                        var MPLOYIdUserClosed    = requirementRecord.idUserClosed;
                        var MPLOYIdUserFilled    = requirementRecord.idUserFilled;

                        //var requirementCity = String.Empty;
                        //var requirementState = String.Empty;
                        //if (!string.IsNullOrEmpty(requirementRecord.City))
                        //{

                        //}

                        //These come from XData -->  Get RequirementStatusTypeId, Get IsTravelRequired, Get MinRate, Get MaxRate, Get RequirementDuration
                        Requirement requirementData = new Requirement();

                        //Set the needed variables to a default. If there is xdata for these fields, they will be reset in the ParseJobXML:
                        requirementData.IsBackgroundCheckRequired = false;
                        requirementData.IsDrugTestRequired        = false;
                        requirementData.IsTravelRequired          = false;
                        requirementData.IsWorkFromHome            = false;

                        if (!string.IsNullOrEmpty(requirementRecord.XData))
                        {
                            requirementData = LookupValue.ParseJobXML(requirementRecord.XData, requirementData);
                        }

                        var priorityType = GetRequirementPriorityTypeId(Convert.ToInt32(requirementPriorityTypeId));

                        var reqStatusTypeId = GetRequirementStatusTypeId(requirementRecord.Closed);

                        var insertRequirement = _db.InsertRequirement(
                            Name
                            , requirementDescription
                            , vMSField
                            , requirementTypeId
                            , priorityType
                            , 3
                                << << << < HEAD
                                , null
                                , null
                                == == == =
                                , requirementRecord.City
                                , requirementRecord.State
                                >> >> >> > 9dc0ab1491ec17863937115775e8178ebadf2f1e
                                , 3
                                , 11
                                , requirementData.PaymentTermTypeId
                                , requirementRecord.Created
                                , null
                                , null
                                , null
                                , requirementRecord.Closed
                                , requirementData.MinRate
                                , requirementData.MaxRate
                                , requirementData.Budget
                                , requirementData.Duration
                                , requirementData.ContractDetails
                                , requirementData.IsTravelRequired
                                , requirementData.IsDrugTestRequired
                                , requirementData.IsBackgroundCheckRequired
                                , requirementData.IsWorkFromHome
                                , createDate
                                , 0
                                , MPLOYIdJob
                                , requirementRecord.idContactManager
                                , MPLOYIdUserFilled
                                , MPLOYIdUserClosed
                                , MPLOYIdUserRecruiter
                                , MPLOYIdUser).ToList();

                        //Get the Requirement Info:
                        //var reqInfo = _db.FindRequirementInfo(requirementRecord.idJob).ToList();

                        foreach (var item in insertRequirement)
                        {
                            _requirementId = item.Id;
                        }


                        if (!string.IsNullOrEmpty(requirementRecord.InternalNote))
                        {
                            var requirementNoteId = _db.InsertRequirementNote(_requirementId, requirementRecord.InternalNote, createDate, 0);
                        }
                        //Store the Closed Reason from Mploy as a RequirementNote:
                        if (!string.IsNullOrEmpty(requirementRecord.ClosedReason))
                        {
                            //Add a new requirement note record for the closed reason, append "Closed Reason" to the front for clarity of where the note came from in the MPLOY db:
                            var reqClosedReasonNote = "Closed Reason: " + requirementRecord.ClosedReason;
                            var requirementNoteId   = _db.InsertRequirementNote(_requirementId, reqClosedReasonNote, createDate, 0);
                        }


                        //*********************** Create the RequirementCustomer records ****************
                        //The idContact on the Requirement should be associated to a customer. Create that requirementCustomer association here.
                        //It will be updated during the HiringActivity import if there is a newer association from teh hiring activities.

                        var returnedIds = _db.GetRequirementContactAssociation(requirementRecord.idJob,
                                                                               requirementRecord.idContactManager);

                        //Find the customeid in intersect that matches the mploy contact
                        var errorString = string.Empty;
                        var personId    = -1;
                        foreach (var result in returnedIds)
                        {
                            _requirementId = Convert.ToInt32(result.jobId);
                            _candidateId   = Convert.ToInt32(result.candidateId);
                            _customerId    = Convert.ToInt32(result.customerId);
                            personId       = Convert.ToInt32(result.personId);
                            errorString    = Convert.ToString(result.errorString);
                        }
                        //***** This RequirementCustomer Relationship is populated during the Requirement import process *****
                        //Insert the new record into the RequirementCustomer table if the _customerId is not null:
                        if (_customerId != 0)
                        {
                            var requirementCustomer = _db.InsertRequirementCustomer(_requirementId, _customerId, true, 0, requirementRecord.Created, requirementRecord.iduser);
                        }


                        Debug.WriteLine("\n" + "Requirement imported: " + MPLOYIdJob + " : " + Name + " CustomerId: " + _customerId);
                    }
                }
                catch
                (Exception ex)
                {
                    new LogWriterFactory().Create().Write(ex.Expand("Error occured with RequirementId: " + _requirementId));
                }
            }
        }