<commit_before>﻿using AspNet.Identity.RavenDB.Entities;
using Microsoft.AspNet.Identity;
using Raven.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace AspNet.Identity.RavenDB.Stores
{
    public sealed class RavenUserStore<TUser> : RavenIdentityStore<TUser>,
        IUserLoginStore<TUser>,
        IUserClaimStore<TUser>,
        IUserPasswordStore<TUser>,
        IUserSecurityStampStore<TUser>,
        IUserTwoFactorStore<TUser>,
        IUserStore<TUser> where TUser : RavenUser
    {
        public RavenUserStore(IAsyncDocumentSession documentSession) : this(documentSession, true)
        {
        }

        public RavenUserStore(IAsyncDocumentSession documentSession, bool disposeDocumentSession) : base(documentSession, disposeDocumentSession)
        {
        }

        // IUserStore

        /// <summary>
        /// </summary>
        /// <remarks>
        /// This method doesn't perform uniquness. That's the responsibility of the session provider.
        /// </remarks>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task CreateAsync(TUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            await DocumentSession.StoreAsync(user).ConfigureAwait(false);
            await DocumentSession.SaveChangesAsync().ConfigureAwait(false);
        }

        public Task<TUser> FindByIdAsync(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentException("Input cannot be null, empty or white space", "userId");
            }

            return GetUser(userId);
        }

        public Task<TUser> FindByNameAsync(string userName)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentException("Input cannot be null, empty or white space", "userName");
            }

            return GetUserByUserName(userName);
        }

        /// <summary>
        /// </summary>
        /// <remarks>
        /// This method assumes that incomming TUser parameter is tracked in the session. So, this method literally behaves as SaveChangeAsync
        /// </remarks>
        /// <param name="user"></param>
        /// <returns></returns>
        public Task UpdateAsync(TUser user)
        {
            return DocumentSession.SaveChangesAsync();
        }

        public Task DeleteAsync(TUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            DocumentSession.Delete<TUser>(user);
            return DocumentSession.SaveChangesAsync();
        }

        // IUserLoginStore
<commit_msg>clean up<commit_after>﻿using AspNet.Identity.RavenDB.Entities;
using Microsoft.AspNet.Identity;
using Raven.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace AspNet.Identity.RavenDB.Stores
{
    public sealed class RavenUserStore<TUser> : RavenIdentityStore<TUser>,
        IUserLoginStore<TUser>,
        IUserClaimStore<TUser>,
        IUserPasswordStore<TUser>,
        IUserSecurityStampStore<TUser>,
        IUserTwoFactorStore<TUser>,
        IUserStore<TUser> where TUser : RavenUser
    {
        public RavenUserStore(IAsyncDocumentSession documentSession) : this(documentSession, true)
        {
        }

        public RavenUserStore(IAsyncDocumentSession documentSession, bool disposeDocumentSession) : base(documentSession, disposeDocumentSession)
        {
        }

        // IUserStore

        /// <remarks>
        /// This method doesn't perform uniquness. That's the responsibility of the session provider.
        /// </remarks>
        public async Task CreateAsync(TUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            await DocumentSession.StoreAsync(user).ConfigureAwait(false);
            await DocumentSession.SaveChangesAsync().ConfigureAwait(false);
        }

        public Task<TUser> FindByIdAsync(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentException("Input cannot be null, empty or white space", "userId");
            }

            return GetUser(userId);
        }

        public Task<TUser> FindByNameAsync(string userName)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentException("Input cannot be null, empty or white space", "userName");
            }

            return GetUserByUserName(userName);
        }

        /// <remarks>
        /// This method assumes that incomming TUser parameter is tracked in the session. So, this method literally behaves as SaveChangeAsync
        /// </remarks>
        public Task UpdateAsync(TUser user)
        {
            return DocumentSession.SaveChangesAsync();
        }

        public Task DeleteAsync(TUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            DocumentSession.Delete<TUser>(user);
            return DocumentSession.SaveChangesAsync();
        }

        // IUserLoginStore

{'fraction_non_alphanumeric': 0.09179008959590419, 'fraction_numerical': 0.0, 'mean_word_length': 2.062709966405375, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2490502', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1375, 'n_words': 321}