Esempio n. 1
0
 public static bool DeleteType(long accountId, string type, string value)
 {
     using (var ctx = DatabaseFactory.CreateConnection())
     {
         using (var txn = ctx.BeginTransaction())
         {
             var res = ctx.Execute($"delete from {TableMapper.TypeToName<APIAccountRole>()} " +
                                   $"where {ColumnMapper.Enclose("AccountId")} = @AccountId " +
                                   $"and {ColumnMapper.Enclose("Type")} = @Type " +
                                   $"and {ColumnMapper.Enclose("Value")} = @Value", new { AccountId = accountId, Type = type, Value = value }, transaction: txn);
             txn.Commit();
             return(res > 0);
         }
     }
 }
Esempio n. 2
0
        public static bool DeleteAccount(long accountId)
        {
            using (var ctx = DatabaseFactory.CreateConnection())
            {
                using (var txn = ctx.BeginTransaction())
                {
                    //Remove all roles
                    ctx.Execute($"delete from {TableMapper.TypeToName<APIAccountRole>()} " +
                                $"where {ColumnMapper.Enclose("AccountId")} = @AccountId ", new { AccountId = accountId }, transaction: txn);

                    //Remove the account
                    var res = ctx.Execute($"delete from {TableMapper.TypeToName<APIAccount>()} " +
                                          $"where {ColumnMapper.Enclose("Id")} = @Id ", new { Id = accountId }, transaction: txn);
                    txn.Commit();
                    return(res > 0);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Finds a list of accounts matching a prefix
 /// </summary>
 /// <returns>The account username prefix.</returns>
 /// <param name="search">Search prefix.</param>
 public static string[] FindAccountsByPrefix(string search)
 {
     using (var ctx = DatabaseFactory.CreateConnection())
     {
         using (var txn = ctx.BeginTransaction())
             return(ctx.Query <APIAccount>($"select * from {TableMapper.TypeToName<APIAccount>()} where {ColumnMapper.Enclose("Username")} like @Username", new { Username = search + '%' }, transaction: txn)
                    .Select(x => x.Username)
                    .ToArray());
     }
 }
        /// <summary>
        /// Finds a list of users matching a prefix
        /// </summary>
        /// <returns>The users by prefix.</returns>
        /// <param name="search">Search.</param>
        public static string[] FindPlayersByPrefix(string search, bool includeOp = false)
        {
#if DAPPER
            using (var ctx = DatabaseFactory.CreateConnection())
            {
                using (var txn = ctx.BeginTransaction())
                    return(ctx.Query <DbPlayer>($"select * from {TableMapper.TypeToName<DbPlayer>()} where {ColumnMapper.Enclose("Name")} like @Name", new { Name = '%' + search + '%' }, transaction: txn)
                           .Select(x => includeOp && x.Operator ? x.Name + " [Op]" : x.Name)
                           .ToArray());
            }
#else
            using (var ctx = new TContext())
            {
#if ENTITY_FRAMEWORK_6
                if (OTA.Data.EF6.OTAContext.IsSQLite)
                {
                    var lowered = search.ToLower();
                    return(ctx.Players
                           .Where(x => x.Name.Length >= search.Length && x.Name.Substring(0, search.Length).ToLower() == lowered)
                           .Select(x => x.Name)
                           .ToArray());
                }
                else
                {
#endif
                return(ctx.Players
                       .Where(x => x.Name.StartsWith(search))
                       .Select(x => x.Name)
                       .ToArray());

#if ENTITY_FRAMEWORK_6
            }
#endif
#endif
        }