private void SaveOrUpdateRegistration(UserLoginType loginType, IServiceBase resolver, IOAuthTokens authToken, Dictionary<string, string> authInfo) { ViewContext context = resolver.ResolveService<ViewContext>(); CommandBus commandBus = resolver.ResolveService<CommandBus>(); IEntityIdGenerator entityIdGenerator = resolver.ResolveService<IEntityIdGenerator>(); Logger.Debug("Login type: {0}", loginType); UserDocument existingUser = context.Users .AsQueryable() .FirstOrDefault(user => user.ThirdPartyId == authToken.UserId && user.LoginType == loginType); if (existingUser != null) { UpdateUserRegistration command = new UpdateUserRegistration() { AggregateId = existingUser.Id, FirstName = authInfo["first_name"], LastName = authInfo["last_name"], AccessToken = authToken.AccessToken, PhotoSmallUri = authInfo["photo"], PhotoBigUri = authInfo["photo_big"], }; Logger.Info("Existing user: {0}", command.Dump()); UserId = existingUser.Id; commandBus.Send(command, UserId); } else { RegisterUser command = new RegisterUser { AggregateId = entityIdGenerator.Generate(), FirstName = authInfo["first_name"], LastName = authInfo["last_name"], LoginType = loginType, ThirdPartyId = authToken.UserId, AccessToken = authToken.AccessToken, PhotoSmallUri = authInfo["photo"], PhotoBigUri = authInfo["photo_big"] }; Logger.Info("New user: {0}", command.Dump()); UserId = command.AggregateId; commandBus.Send(command, UserId); } ICacheClient cacheClient = resolver.ResolveService<ICacheClient>(); UpdateSession(cacheClient); }