示例#1
0
        private Account LoadAccountByLoginNameByJsonQuery(string loginName, string password, EntityFrameworkContext context)
        {
            var manager = this.RepositoryManager as RepositoryManager;

            if (manager != null)
            {
                var accountInfo = context.Context.Set <Account>()
                                  .Select(a => new { a.Id, a.LoginName, a.PasswordHash })
                                  .FirstOrDefault(a => a.LoginName == loginName && BCrypt.Verify(password, a.PasswordHash, false));
                if (accountInfo != null)
                {
                    manager.EnsureCachesForCurrentGameConfiguration();

                    context.Context.Database.OpenConnection();
                    try
                    {
                        var objectLoader = new AccountJsonObjectLoader();
                        return(objectLoader.LoadObject <Account>(accountInfo.Id, context.Context));
                    }
                    finally
                    {
                        context.Context.Database.CloseConnection();
                    }
                }
            }

            return(null);
        }
示例#2
0
 /// <inheritdoc />
 public override Account GetById(Guid id)
 {
     ((CachingRepositoryManager)this.RepositoryManager).EnsureCachesForCurrentGameConfiguration();
     using var context = this.GetContext();
     context.Context.Database.OpenConnection();
     try
     {
         var objectLoader = new AccountJsonObjectLoader();
         var account      = objectLoader.LoadObject <Account>(id, context.Context);
         context.Context.Attach(account);
         return(account);
     }
     finally
     {
         context.Context.Database.CloseConnection();
     }
 }
示例#3
0
        /// <inheritdoc />
        public override Account?GetById(Guid id)
        {
            ((CachingRepositoryManager)this.RepositoryManager).EnsureCachesForCurrentGameConfiguration();
            using var context = this.GetContext();
            context.Context.Database.OpenConnection();
            try
            {
                var objectLoader = new AccountJsonObjectLoader();
                var account      = objectLoader.LoadObject <Account>(id, context.Context);
                if (account != null && !(context.Context.Entry(account) is { } entry&& entry.State != EntityState.Detached))
                {
                    context.Context.Attach(account);
                }

                return(account);
            }
            finally
            {
                context.Context.Database.CloseConnection();
            }
        }