//TODO refactor this /// <summary> /// Renders information received from authentication service. /// </summary> public ActionResult GoogleAuth(string code, string error) { UserInfo userInfo; try { userInfo = googleClient.GetUserInfo(googleClient.GetAccessToken(code, error)); } catch { return RedirectToAction("LogOn"); } var user = repository.Query<User>(x => x.RelatedPerson, x => x.Teams) .SingleOrDefault(x => x.GoogleId == userInfo.Id); if (null == user) { user = new User { GoogleId = userInfo.Id, RelatedPerson = repository.Query<Person>().SingleOrDefault(x => x.Email == userInfo.Email) }; if (null == user.RelatedPerson) { var person = new Person { Email = userInfo.Email, FirstName = userInfo.FirstName, LastName = userInfo.LastName, PhotoUri = userInfo.PhotoUri, Role = PersonRole.Employee, CreationDate = DateTime.Now }; user.RelatedPerson = person; repository.Save(person); } repository.Save(user); } appContext.User = user; return RedirectToRoute("Default"); }
private void SaveCurrentUserAndCurrentTeam(User value) { appContext.CurrentTeam = value.CurrentTeam; if (value.CurrentTeam!=null) repository.Save(value.CurrentTeam); repository.Save(value); }