public int calculateScore(ScorableData ScorableData) { int nExperinceScore = 0; int nSkillsScore = 0; int nEducationScore = 0; if (ScorableData.experince.Count > 0) { int nCurrYears = 0; string strYears = "0"; // To find years of experience foreach (ProfileExperience nYear in ScorableData.experince) { int nPlaceMonths; int nPlaceYear = nYear.Experience.IndexOf("years"); if (nPlaceYear == -1) { nPlaceMonths = nYear.Experience.IndexOf("months"); if (nPlaceMonths != -1) { nCurrYears = 1; } } else { strYears = nYear.Experience.Substring(nYear.Experience.IndexOf("(") + 1, nPlaceYear - nYear.Experience.IndexOf("(") - 1).ToString().Trim(); Int32.TryParse(strYears, out nCurrYears); } nExperinceScore += nCurrYears * 100; } } if (ScorableData.skills.Count > 0) { nSkillsScore = ScorableData.skills.Count; } // Calc education score if (ScorableData.education.Count > 0) { nEducationScore = CalcEducationScore(ScorableData.education); } return(nEducationScore + nExperinceScore + nSkillsScore); }
public async Task <IHttpActionResult> AddProfile(LinkedinURL profile) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string linkedInProfileUrl = profile.LinkedInUri; string linkedinProfileHtml; // If the user didnt put the url if (string.IsNullOrEmpty(linkedInProfileUrl)) { return(BadRequest("is empty")); } if (!UrlIsValid(linkedInProfileUrl)) { return(BadRequest("url is not valid")); } // Check if the url is of linkedin website int startIndex = linkedInProfileUrl.IndexOf(".com"); string checkProfileUrl = linkedInProfileUrl.Substring(0, startIndex + 4); if (linkedinWebSite != checkProfileUrl) { return(BadRequest("url is not the requested url")); } // 999 Request denied //try //{ // linkedinProfileHtml = httpRequetsMaker.getResponse(linkedInProfileUrl); //} //catch (Exception ex) //{ // return InternalServerError(ex); //} // ProfileDetails linkedinProfile = linkedInProfileHtmlParser.parse(linkedinProfileHtml); // read the html from file string strHtml = File.ReadAllText(@"C:\Users\aya\Documents\Visual Studio 2015\Projects\LinkedinProject\exempleProfile.txt"); ProfileDetails linkedinProfile = linkedInProfileHtmlParser.parse(strHtml); ScorableData profileScoreData = new ScorableData(linkedinProfile.ProfileExperience, linkedinProfile.ProfileEducation, linkedinProfile.ProfileSkills); // calc the score linkedinProfile.Score = scoreCalc.calculateScore(profileScoreData); await pesrsistenceManager.addProfile(linkedinProfile); } catch (Exception ex) { Console.WriteLine(String.Format(" Error:{0}", ex.ToString())); return(InternalServerError(ex)); } return(Ok("Profile was added succesfuly")); }