Advertisement
NLinker

Dvorkin's task

Apr 2nd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. // [14:34:56] Pavel  Dvorkin:  
  2. public async Task<bool> AddClanMember(int id, int newMemberId, int clanId, ClanRole role)
  3.   {
  4.    using (var connection = await GetConnection())
  5.    {
  6.     await ExecuteNonQueryAsync(connection, "LOCK TABLES userclan WRITE, clans WRITE;");
  7.  
  8.     if (await IsPlayerInClan(connection, newMemberId) || !await CanMemberBeAddedToClan(connection, clanId) || !await CanPlayerAddMembersToClan(connection, id, clanId))
  9.     {
  10.      await ExecuteNonQueryAsync(connection, "UNLOCK TABLES;");
  11.      return false;
  12.     }
  13.  
  14.     var rowsAffected = await ExecuteNonQueryAsync(
  15.      connection,
  16.      "INSERT INTO userclan (fid_user, fid_clan, fclanrole) VALUES (@id, @fid_clan, @fclanrole);",
  17.      Param("@id", id),
  18.      Param("@fid_clan", clanId),
  19.      Param("@fclanrole", (int)role)
  20.      );
  21.  
  22.     await ExecuteNonQueryAsync(connection, "UNLOCK TABLES;");
  23.     return rowsAffected > 0;
  24.    }
  25.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement