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);
        }
        public static void OrganizationImport()
        {
            using (_db = new Entities())
            {
                try
                {
                    //Read in the data from the TempOrganizationFileTable:
                    var organizationData = _db.ReadOrganization().ToList();



                    //For each record in from TempOrganizationFileTable (Organization Mploy file):
                    foreach (var orgRecord in organizationData)
                    {
                        Company insertCompany = new Company();

                        var companyTypeId = GetCompanyType(orgRecord.idOrganizationType.ToString());

                        //Get the Id for the person assigned to this comapny based on the mploy user id:
                        //This Id is used in the SP to assign the Sales or Recruiting Person down the road.
                        int?personIdFromUser = 0;
                        if (orgRecord.idUserOwner != null && orgRecord.idUserOwner != 0)
                        {
                            var result = _db.GetUserFromMployUserId(Convert.ToInt32(orgRecord.idUserOwner)).ToList();
                            personIdFromUser = Convert.ToInt32(result[0]);
                        }
                        else
                        {
                            personIdFromUser = null;
                        }

                        //Send the correct IdUser into the SP to insert a company:
                        int?idUser = -1;
                        if (orgRecord.idUserOwner == null || orgRecord.idUserOwner == 0)
                        {
                            idUser = null;
                        }
                        else
                        {
                            idUser = Convert.ToInt32(orgRecord.idUserOwner);
                        }


                        //If the Organization name is not null or empty, then insert the Org:
                        if (!string.IsNullOrEmpty(orgRecord.Organization))
                        {
                            var companyInsertResult = _db.InsertCompany(orgRecord.Organization, companyTypeId, null, null, null, null, null, personIdFromUser, 0, Convert.ToInt32(orgRecord.idOrganization), idUser).ToList();

                            foreach (var item in companyInsertResult)
                            {
                                _companyId      = item.Id;
                                _globalEntityId = item.GlobalEntityId;
                            }

                            Debug.WriteLine("\n" + orgRecord.Organization);

                            //Call the function to insert the Company Mailing Address:
                            InsertCompanyMailingAddress(orgRecord);

                            //Call the function to insert the Company Contact Information:
                            InsertCompanyContactInformation(orgRecord);

                            //Insert the Company Notes if they have notes associated to the incoming record:
                            if (!string.IsNullOrEmpty(orgRecord.InternalNote))
                            {
                                var noteResult = _db.InsertCompanyNote(_companyId, orgRecord.InternalNote, 0);
                            }

                            if (!string.IsNullOrEmpty(orgRecord.ExternalNote))
                            {
                                var noteResult = _db.InsertCompanyNote(_companyId, orgRecord.ExternalNote, 0);
                            }

                            //Insert into the CompanyBranch table
                            var branchId            = ImportHelperMethods.GetBranchId(orgRecord.State, orgRecord.City);
                            var companyBranchResult = _db.InsertCompanyBranch(_companyId, branchId, orgRecord.Created, 0,
                                                                              orgRecord.idUserOwner);
                        }
                        else
                        {
                            Debug.WriteLine("\n" + "***** Organization does not have a name: " + orgRecord.idOrganization + " *****");
                        }
                    }
                }
                catch
                (Exception ex)
                {
                    new LogWriterFactory().Create().Write(ex.Expand("Error occured with Mploy Organization Id: " + _companyId));
                }
            }
        }
Esempio n. 3
0
        public static void ContactImport()
        {
            using (_db = new Entities())
            {
                try
                {
                    //Read in the temp Contact table from the DB:
                    var contactData = _db.ReadContact().ToList(x => new ConsoleApplication1.Model.Person
                    {
                        FirstName      = x.FirstName,
                        LastName       = x.LastName,
                        MiddleName     = x.MiddleName,
                        Gender         = x.Gender,
                        Address        = x.Address,
                        City           = x.City,
                        State          = x.State,
                        Zip            = x.Zip,
                        Email          = x.eMail,
                        handle0type    = Convert.ToInt32(x.handle0type),
                        handle0text    = x.handle0text,
                        handle1type    = Convert.ToInt32(x.handle1type),
                        handle1text    = x.handle1text,
                        handle2type    = Convert.ToInt32(x.handle2type),
                        handle2text    = x.handle2text,
                        handle3type    = Convert.ToInt32(x.handle3type),
                        handle3text    = x.handle3text,
                        IdOrganization = Convert.ToInt32(x.idOrganization),
                        Title          = x.Title,
                        Created        = Convert.ToDateTime(x.Created),
                        IdContact      = Convert.ToInt32(x.idContact),
                        IdContactType  = Convert.ToInt32(x.idContactType),
                        IdUser         = Convert.ToInt32((x.idUserOwner)),
                        Source         = Convert.ToInt32(x.IdSource),
                        IdStatus       = x.IdStatus
                    });


                    foreach (var contactRecord in contactData)
                    {
                        //Check if the contact record's IdContact is in the Candidate file.
                        //Returns a list of the contact records found in the Candidate file.
                        //var checkForDuplicateRecords = _db.CheckCustomerAgainstCandidateData(contactRecord.IdContact).ToList();
                        ////If the contact file has any records that are also in the Candidate file, then do not import the contact.
                        //if (!checkForDuplicateRecords.Any())
                        //{

                        //If the contact record is a contact (contactTypeId of 1) AND the orgainization record id is not null or 4 (the id of the blank organization record):
                        if (contactRecord.IdContactType == 1 && contactRecord.IdOrganization != 0 &&
                            contactRecord.IdOrganization != 4)
                        {
                            //if (contactRecord.IdContact == 20551)
                            //{
                            //    var name = contactRecord.IdContactType;
                            //}

                            //Get the Contacts with the typeId = 1 that have hiring activities:

                            //Add a catch to skip those records, they are added as a Candidate instead.

                            //Get the user id:
                            var idUserVar = ImportHelperMethods.GetUserId(contactRecord.IdUser);

                            //Get the Organization Id:
                            var orgId = ImportHelperMethods.GetIdOrganization(contactRecord.IdOrganization);

                            var genderTypeId = ImportHelperMethods.GetGenderTypeId(contactRecord.Gender);

                            //Insert the Contact as a Person record first:
                            //Returns the PersonId
                            var personResult =
                                _db.InsertPerson(null, contactRecord.FirstName, contactRecord.LastName, genderTypeId, 0,
                                                 contactRecord.Created, contactRecord.IdContact, idUserVar).ToList();
                            _personId = Convert.ToInt32(personResult[0]);


                            //Get the source type:
                            //var sourceTypeList = _db.ReadSourceType().ToList();
                            var sourceTypeIdForContact = ImportHelperMethods.GetSourceTypeId(contactRecord.Source);

                            //Get the customers associated org id:
                            var customerOrgId = _db.FindCustomerOrganizationId(_personId,
                                                                               Convert.ToInt32(contactRecord.IdOrganization));
                            foreach (var org in customerOrgId)
                            {
                                orgId = org;
                            }

                            //Get the customer type id:
                            var customerTypeId = GetCustomerTypeId(contactRecord.IdStatus);


                            //Insert as a Customer
                            //Returns the Customer record
                            //***********CHANGED THE MPLOY Org Id to the IDORGANIZATION LIKE IT SHOULD BE...
                            var customerResult =
                                _db.InsertCustomer(orgId, _personId, sourceTypeIdForContact, customerTypeId,
                                                   contactRecord.Title, null, null, contactRecord.Created, 0, contactRecord.IdOrganization).ToList();
                            foreach (var item in customerResult)
                            {
                                _customerId = item.Id;
                            }



                            //Insert Contact Information
                            //Returns the PersonContactInformation.Id
                            var personContactInformationId = -1;

                            //Insert Email address:
                            var personEmail =
                                _db.InsertPersonContactInformation(_personId, 2, contactRecord.Email, null, true, 0)
                                .ToList();

                            //0:
                            personContactInformationId = InsertContactInformation(contactRecord.handle0text,
                                                                                  contactRecord.handle0type);

                            //1:
                            personContactInformationId = InsertContactInformation(contactRecord.handle1text,
                                                                                  contactRecord.handle1type);

                            //2:
                            personContactInformationId = InsertContactInformation(contactRecord.handle2text,
                                                                                  contactRecord.handle2type);

                            //3:
                            personContactInformationId = InsertContactInformation(contactRecord.handle3text,
                                                                                  contactRecord.handle3type);


                            //Insert Mailing Address & PersonMailAddress
                            //Inserts into the MailAddress table and the PersonMailAddress table
                            if (!string.IsNullOrEmpty(contactRecord.Address) &&
                                !string.IsNullOrEmpty(contactRecord.City) && !string.IsNullOrEmpty(contactRecord.State) &&
                                !string.IsNullOrEmpty(contactRecord.Zip))
                            {
                                //Returns the PersonMailAddress.Id
                                var personMailAddressResult =
                                    _db.InsertPersonMailingAddress(_personId, contactRecord.Address, contactRecord.City,
                                                                   contactRecord.State, contactRecord.Zip, 0).ToList();
                                _personMailAddressId = Convert.ToInt32(personMailAddressResult[0]);
                            }


                            //Insert Customer Notes
                            //Inserts into the CustomerNote table
                            if (!string.IsNullOrEmpty(contactRecord.Notes))
                            {
                                //Returns the CustomerNote.Id
                                var customerNoteResult =
                                    _db.InsertCustomerNote(_customerId, contactRecord.Notes, contactRecord.CreatedDate,
                                                           0).ToList();
                            }


                            //THIS NEEDS TO BE UPDATED IN THE DB SO THE BRANCH CAN BE ADDED!!!!!!!!!
                            //Insert the CustomerBranch record:
                            var branchId = ImportHelperMethods.GetBranchId(contactRecord.State, contactRecord.City);
                            //var customerBranchResult = _db.InsertCustomerBranch(_customerId, branchId, contactRecord.Created, 0, contactRecord.IdUser);



                            //Update the Person table 'Preferred' columns for email, phone, and home address:
                            _db.UpdatePersonPreferredData(contactRecord.IdContact);

                            Debug.WriteLine("\n" + "Person imported: " + _personId + " " + contactRecord.FirstName + " " +
                                            contactRecord.LastName + " Customer Id: " + _customerId);
                        }
                        else
                        {
                            //Write out the skipped records here:
                        }

                        //}
                    }
                }
                catch
                (Exception ex)
                {
                    new LogWriterFactory().Create().Write(ex.Expand("Error occured with Customer Id: " + _customerId + " and Person Id: " + _personId));
                }
            }
        }
        public static void TestUpdate()
        {
            using (_db = new Entities())
            {
                try
                {
                    //Reads in the Candidate record from the Temp table in the DB and uses our custom model.
                    var data = _db.ReadPerson().ToList(x => new Model.Person
                    {
                        FirstName  = x.FirstName,
                        LastName   = x.LastName,
                        MiddleName = x.MiddleName,
                        Gender     = x.Gender,
                        //Status = x.Status,
                        Address     = x.Address,
                        City        = x.City,
                        State       = x.State,
                        Zip         = x.Zip,
                        Email       = x.eMail,
                        handle0type = Convert.ToInt32(x.handle0type),
                        handle0text = x.handle0text,
                        handle1type = Convert.ToInt32(x.handle1type),
                        handle1text = x.handle1text,
                        handle2type = Convert.ToInt32(x.handle2type),
                        handle2text = x.handle2text,
                        handle3type = Convert.ToInt32(x.handle3type),
                        handle3text = x.handle3text,
                        xdata       = x.Xdata,
                        Notes       = x.Notes,
                        ResumeText  = x.ResumeText,
                        //Source = x.Source,
                        IdContact     = Convert.ToInt32(x.idContact),
                        IdContactType = Convert.ToInt32(x.idContactType),
                        IdUser        = Convert.ToInt32((x.idUserOwner)),
                        Source        = Convert.ToInt32(x.IdSource),
                        IdStatus      = x.IdStatus,
                        Created       = Convert.ToDateTime(x.Created)
                    });



                    //For each person record from the Candidate file table:
                    foreach (var candidateRecord in data)
                    {
                        //Check that the incoming contact record is of the Candidate type:
                        if (candidateRecord.IdContactType == 2 || candidateRecord.IdContactType == 5)
                        {
                            //Call method to Insert the data as a person and candidate:
                            //if (candidateRecord.FirstName != "Unknown" && candidateRecord.LastName != "Unknown")
                            //{


                            _mployContactId = candidateRecord.IdContact;

                            //Get the user id:
                            var idUserVar = ImportHelperMethods.GetUserId(candidateRecord.IdUser);

                            //Get the GenderTypeId of the person being inserted:
                            var genderTypeId = ImportHelperMethods.GetGenderTypeId(candidateRecord.Gender);

                            //Insert the contact as a Person first:
                            //Returns the PersonId
                            var personId = -1;

                            var personResult = _db.InsertPerson(null, candidateRecord.FirstName, candidateRecord.LastName, genderTypeId, 0, candidateRecord.Created, candidateRecord.IdContact, idUserVar).ToList();
                            personId = Convert.ToInt32(personResult[0]);

                            InsertCandidate(candidateRecord, personId);

                            //Update the Person table 'Preferred' columns for email, phone, and home address:
                            _db.UpdatePersonPreferredData(candidateRecord.IdContact);

                            //}
                        }
                    }
                    //Import the contacts that are customers with hiring activities:
                }
                catch
                (Exception ex)
                {
                    new LogWriterFactory().Create().Write(ex.Expand("Error occured with Contact Id: " + _mployContactId));
                }
            }
        }