public UserProfiles Add(UserProfiles userProfile)
        {
            context.UserProfiles.Add(userProfile);
            context.SaveChanges();

            return userProfile;
        }
        public override Task AuthenticateExternalAsync(ExternalAuthenticationContext context)
        {
            var provider = context.ExternalIdentity.Provider;
            UserProfiles existingUser = null;
            switch(provider)
            {
                case "Facebook":
                    existingUser = dbContext.UserProfiles.FirstOrDefault(x => x.FacebookId == context.ExternalIdentity.ProviderId);
                    break;
                case "Google":
                    existingUser = dbContext.UserProfiles.FirstOrDefault(x => x.GoogleId == context.ExternalIdentity.ProviderId);
                    break;
            }

            if(existingUser == null)
            {
                var newUser = new UserProfiles();
                // Add other claims
                newUser.EmailAddress = context.ExternalIdentity.Claims.FirstOrDefault(x => x.Type == IdentityServer3.Core.Constants.ClaimTypes.Email).Value;
                newUser.FirstName = context.ExternalIdentity.Claims.FirstOrDefault(x => x.Type == IdentityServer3.Core.Constants.ClaimTypes.GivenName).Value;
                newUser.LastName = context.ExternalIdentity.Claims.FirstOrDefault(x => x.Type == IdentityServer3.Core.Constants.ClaimTypes.FamilyName).Value;
                newUser.CreatedDate = DateTime.UtcNow;

                switch (provider)
                {
                    case "Facebook":
                        newUser.FacebookId = context.ExternalIdentity.ProviderId;
                        break;
                    case "Google":
                        newUser.GoogleId = context.ExternalIdentity.ProviderId;
                        break;
                }

                dbContext.UserProfiles.Add(newUser);
                dbContext.SaveChanges();

                existingUser = newUser;
            }

            // Add other claims
            List<Claim> existingUserClaims = new List<Claim>();
            existingUserClaims.Add(new Claim(ClaimTypes.Email, existingUser.EmailAddress));

            context.AuthenticateResult = new AuthenticateResult(
                existingUser.Id.ToString(),
                existingUser.FirstName,
                existingUserClaims,
                provider,
                provider);

            return Task.FromResult(0);
            //return base.AuthenticateExternalAsync(context);
        }
 public void Update(UserProfiles userProfile)
 {
     context.UserProfiles.Update(userProfile);
     context.SaveChanges();
 }