Exemple #1
0
 public void addNewJobModel(JobModels jm)
 {
     if (jm != null)
     {
         jobs.Add(jm);
     }
 }
Exemple #2
0
 public bool removeJob(JobModels jm)
 {
     return(jobs.Remove(jm));
 }
Exemple #3
0
        public void read()
        {
            try {
                file = File.Open(fileName, FileMode.Open);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("ERROR! " + fileName + " could not open the dataFile!");
                Console.WriteLine(ex.Message);
                return;
            }
            file.Close();
            IEnumerable <string> lines = File.ReadLines(fileName);

            JobModels         curJob = null;
            ApplicationModels curApp = null;

            string[] splitter = null;

            foreach (string line in lines)
            {
                // Test for new objects
                if (line.Contains("->Job"))
                {
                    if (curApp != null)
                    {
                        applications.Add(curApp);
                    }
                    curApp = null;
                    if (curJob != null)
                    {
                        jobs.Add(curJob);
                    }
                    curJob = new JobModels();
                    continue;
                }
                if (line.Contains("->Application"))
                {
                    if (curApp != null)
                    {
                        applications.Add(curApp);
                    }
                    curApp = new ApplicationModels();
                    if (curJob != null)
                    {
                        jobs.Add(curJob);
                    }
                    curJob = null;
                    continue;
                }

                splitter = line.Split(new char[] { ':' });
                if (splitter.Count() < 2)
                {
                    continue;
                }



                switch (splitter[0])
                {
                case "-|ID":
                    if (curJob != null)
                    {
                        curJob.id = getIntFromString(splitter[1]);
                    }
                    else if (curApp != null)
                    {
                        curApp.id = getIntFromString(splitter[1]);
                    }
                    break;

                case "-|Title":
                    if (curJob != null)
                    {
                        curJob.Title = splitter[1];
                    }
                    break;

                case "-|Description":
                    if (curJob != null)
                    {
                        curJob.description = splitter[1];
                    }
                    break;

                case "-|Skills":
                    if (curApp != null)
                    {
                        curApp.skills = splitter[1];
                    }
                    else if (curJob != null)
                    {
                        curJob.skills = splitter[1];
                    }
                    break;

                case "-|Location":
                    if (curJob != null)
                    {
                        curJob.Location = splitter[1];
                    }
                    break;

                case "-|Salary":
                    if (curJob != null)
                    {
                        curJob.salary = splitter[1];
                    }
                    break;

                case "-|Name":
                    if (curApp != null)
                    {
                        curApp.Name = splitter[1];
                    }
                    break;

                case "-|City":
                    if (curApp != null)
                    {
                        curApp.City = splitter[1];
                    }
                    break;

                case "-|State":
                    if (curApp != null)
                    {
                        curApp.State = splitter[1];
                    }
                    break;

                case "-|Education":
                    if (curApp != null)
                    {
                        curApp.education = splitter[1];
                    }
                    break;

                case "-|Reason":
                    if (curApp != null)
                    {
                        curApp.reason = splitter[1];
                    }
                    break;

                case "-|JobID":
                    if (curApp != null)
                    {
                        curApp.jobID = getIntFromString(splitter[1]);
                    }
                    break;
                }
            } // End of foreach


            foreach (JobModels jm in jobs)
            {
                foreach (ApplicationModels am in applications)
                {
                    if (jm.id == am.jobID)
                    {
                        jm.applications.Add(am);
                    }
                }
            }
        }
        // GET api/values/5
        public async System.Threading.Tasks.Task <IEnumerable <JobModels> > GetAsync(string name)
        {
            JobModels jobModels = new JobModels();
            var       listJob   = new List <JobModels>();

            var url = "https://id.indeed.com/lowongan-kerja?q=" + name;

            var httpClient = new HttpClient();
            var html       = await httpClient.GetStringAsync(url);

            var salary = "";

            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(html);

            var JobsHtml = htmlDocument.DocumentNode.Descendants("td")
                           .Where(node => node.GetAttributeValue("id", "")
                                  .Equals("resultsCol")).ToList();
            var JobListItems = JobsHtml[0].Descendants("div")
                               .Where(node => node.GetAttributeValue("id", "")
                                      .Contains("p_")).ToList();

            foreach (var JobListItem in JobListItems)
            {
                Console.ForegroundColor = (ConsoleColor)10;

                var jobId = JobListItem.GetAttributeValue("id", "");

                var jobTitle = JobListItem.Descendants("a")
                               .Where(node => node.GetAttributeValue("data-tn-element", "")
                                      .Equals("jobTitle")).FirstOrDefault().InnerText;

                var companyName = JobListItem.Descendants("span")
                                  .Where(node => node.GetAttributeValue("class", "")
                                         .Equals("company")).FirstOrDefault().InnerText;

                var location = JobListItem.Descendants("span")
                               .Where(node => node.GetAttributeValue("class", "")
                                      .Contains("location")).FirstOrDefault().InnerText;

                var linkDetail = JobListItem.Descendants("a")
                                 .FirstOrDefault().GetAttributeValue("href", "");


                var urlDetail = "https://id.indeed.com" + linkDetail;

                var html2 = await httpClient.GetStringAsync(urlDetail);

                var htmlDocument2 = new HtmlDocument();
                htmlDocument2.LoadHtml(html2);

                var jobDesc = htmlDocument2.DocumentNode.Descendants("div")
                              .Where(node => node.GetAttributeValue("id", "")
                                     .Equals("jobDescriptionText")).FirstOrDefault().InnerText;

                try
                {
                    salary = JobListItem.Descendants("span")
                             .Where(node => node.GetAttributeValue("class", "")
                                    .Equals("salaryText")).FirstOrDefault().InnerText;
                }
                catch (Exception e)
                {
                }

                var date = JobListItem.Descendants("span")
                           .Where(node => node.GetAttributeValue("class", "")
                                  .Contains("date")).FirstOrDefault().InnerText;


                listJob.Add(new JobModels {
                    JobName     = jobTitle,
                    JobSalary   = salary,
                    JobDate     = date,
                    JobLink     = urlDetail,
                    JobCompany  = companyName,
                    JobLocation = location,
                    JobDesc     = jobDesc,
                });
            }
            return(listJob);
        }