public bool UploadDocument() { var httpRequest = HttpContext.Current.Request; JobDocument jobDocument = new JobDocument(); jobDocument.JobId = Convert.ToInt64(httpRequest.Params["JobId"]); jobDocument.JdrCode = httpRequest.Params["JdrCode"]; jobDocument.DocTypeId = Convert.ToInt32(httpRequest.Params["DocTypeId"]); jobDocument.StatusId = 1; jobDocument.JdrTitle = !string.IsNullOrEmpty(jobDocument.JdrCode) ? new string(jobDocument.JdrCode.Take(20).ToArray()) : string.Empty; if (httpRequest.Files.Count > 0) { List <DocumentAttachment> listDocumentAttachment = new List <DocumentAttachment>(); for (var i = 0; i < httpRequest.Files.Count; i++) { byte[] fileData = null; var postedFile = httpRequest.Files[i]; using (var binaryReader = new BinaryReader(postedFile.InputStream)) { fileData = binaryReader.ReadBytes(postedFile.ContentLength); } listDocumentAttachment.Add(new DocumentAttachment() { Name = postedFile.FileName, Content = fileData }); } jobDocument.DocumentAttachment = listDocumentAttachment; } return(_jobServicesCommands.UploadDocument(jobDocument, Models.ApiContext.ActiveUser)); }
private JobDocument BuildJob(string relativeUrl) { JobDocument job = null; var url = string.Format("{0}{1}", DICE_BASE_URL, relativeUrl); var webGet = new HtmlWeb(); if (webGet.Load(url) is HtmlDocument document) { var schemaOrgNodes = document.DocumentNode.SelectNodes(".//*[@itemprop]").ToList(); var urlNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"url\"")).FirstOrDefault(); if (urlNode != null) { job = new JobDocument(); job.id = alpahNumericRegex.Replace(urlNode.Attributes["data-jobid"].Value, ""); job.jobUrl = string.Format("{0}{1}", DICE_BASE_URL, urlNode.Attributes["content"].Value); } else { return(null); } var datePostedNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"datePosted\"")).FirstOrDefault(); if (datePostedNode != null) { DateTime dt; if (DateTime.TryParse(datePostedNode.Attributes["content"].Value, out dt)) { job.postedDate = dt; } } var titleNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"title\"")).FirstOrDefault(); if (titleNode != null) { job.jobTitle = titleNode.InnerHtml; } var descriptionNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"description\"") && x.Name.ToLower() == "div").FirstOrDefault(); if (descriptionNode != null) { job.description = RemoveUnwantedTags(descriptionNode.InnerHtml.Replace("\n", string.Empty).Replace("\t", string.Empty).Replace("\r", string.Empty)); } var empNameNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"name\"") && x.Name.ToLower() == "span").FirstOrDefault(); if (empNameNode != null) { job.employerName = empNameNode.InnerHtml.Replace("\n", string.Empty).Replace("\t", string.Empty).Replace("\r", string.Empty); } var city = string.Empty; var state = string.Empty; var zipCode = string.Empty; var cityNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"addressLocality\"") && x.Name == "meta").FirstOrDefault(); if (cityNode != null) { city = cityNode.Attributes["content"].Value; } var stateNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"addressRegion\"") && x.Name == "meta").FirstOrDefault(); if (stateNode != null) { state = stateNode.Attributes["content"].Value; } var postalNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"postalCode\"") && x.Name == "meta").FirstOrDefault(); if (postalNode != null) { zipCode = postalNode.Attributes["content"].Value; } job.locationText = string.Format("{0} {1} {2}", city, state, zipCode); var latNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"latitude\"") && x.Name == "meta").FirstOrDefault(); var lonNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"longitude\"") && x.Name == "meta").FirstOrDefault(); if (latNode != null && lonNode != null) { job.locationPoint = new Location { type = "Point", coordinates = new List <decimal> { decimal.Parse(lonNode.Attributes["content"].Value), decimal.Parse(latNode.Attributes["content"].Value) } }; } var skillsNode = schemaOrgNodes.Where(x => x.OuterHtml.Contains("itemprop=\"skills\"")).FirstOrDefault(); if (skillsNode != null) { job.skills = skillsNode.InnerHtml.Replace("\n", string.Empty).Replace("\t", string.Empty).Replace("\r", string.Empty).Split(',').ToList(); } job.keyPhrases = DetectKeyPhrases(job.description); } return(job); }