public ActionResult LogIn(LinkedInApiProfile profile) { try { // If the user is already logged in then associate the profile with the user. if (CurrentRegisteredUser != null) { // Only support employers at the moment. if (CurrentEmployer == null) { return(Json(new LinkedInAuthenticationModel { Status = AuthenticationStatus.Failed.ToString() })); } var linkedInProfile = new LinkedInProfile { Id = profile.Id, UserId = CurrentEmployer.Id }; _linkedInCommand.UpdateProfile(linkedInProfile); return(Json(new LinkedInAuthenticationModel { Status = AuthenticationStatus.Authenticated.ToString() })); } else { if (LogIn(profile.Id)) { return(Json(new LinkedInAuthenticationModel { Status = AuthenticationStatus.Authenticated.ToString() })); } // Save the profile. var linkedInProfile = CreateLinkedInProfile(profile); _linkedInCommand.UpdateProfile(linkedInProfile); return(Json(new LinkedInAuthenticationModel { Status = AuthenticationStatus.Failed.ToString() })); } } catch (UserException ex) { ModelState.AddModelError(ex, new StandardErrorHandler()); } return(Json(new JsonResponseModel())); }
private LinkedInProfile CreateLinkedInProfile(LinkedInApiProfile profile) { // Use the id of the current anonymous user as the UserId. return(new LinkedInProfile { Id = profile.Id, UserId = CurrentAnonymousUser.Id, FirstName = profile.FirstName, LastName = profile.LastName, OrganisationName = profile.OrganisationName, Industries = _linkedInQuery.GetIndustries(profile.Industry), Location = _linkedInQuery.GetLocation(profile.Country, profile.Location), }); }