private async Task <UserInfo> GetUserFromAccessTokenAsync1(string token) { var apiClient = new HttpClient { BaseAddress = new Uri("https://api.linkedin.com") }; var url = $"/v1/people/~:({LinkedinUserInfoParameters})?oauth2_access_token={token}&format=json"; var response = await apiClient.GetAsync(url); var jsonResponse = await response.Content.ReadAsStringAsync(); var r = JsonConvert.DeserializeObject <UserInfo>(jsonResponse); // return JsonConvert.DeserializeObject<UserInfo>(jsonResponse); // var check = db.linkedinAccounts.Where(s => s.url == (r.PublicProfileUrl) ); linkedinAccount lk = new linkedinAccount(); if (lk.email == r.EmailAddress) { } return(r); }
public ActionResult SaveLinkedinData(int studentnumber, string FirstName, string LastName, string pemail, string semail, string campus, string url, string s1, string s2, string s3, string Program_Fast_Name, string position, DateTime date, string password, string picurl) { student st = new student(); linkedinAccount lk = new linkedinAccount(); lk.linkedinAccount_Id = st.record_id; lk.firstname = FirstName; lk.lastname = LastName; lk.positions = position; lk.imgurl = picurl; lk.url = url; lk.email = pemail; db.linkedinAccounts.Add(lk); db.SaveChanges(); st.alumni_id = studentnumber; st.record_id = lk.linkedinAccount_Id; // st.firstname = FirstName; // st.lastname = LastName; // st.primaryemail = pemail; st.secondaryemail = semail; st.Campus = campus; // st.linkedinacct = url; st.skill_1 = s1; st.skill_2 = s2; st.skill_3 = s3; st.programfast = Program_Fast_Name; // st.currentposition = "HardCode"; st.graduationdate = date; st.password = password; st.comment = ""; st.linkedinAccount = lk; db.students.Add(st); try { db.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } return(RedirectToAction("studentlogin1")); }