Exemple #1
0
        public async Task <bool> DeleteClan(string clanName)
        {
            bool wasSuccess = false;

            try
            {
                using (var db = new ClanStorage())
                {
                    var clan = await db.Clan.FirstOrDefaultAsync(x => x.ClanName.ToLower() == clanName);

                    if (clan != null)
                    {
                        db.Clan.Remove(clan);
                        await db.SaveChangesAsync();

                        wasSuccess = true;
                    }
                }
            }
            catch (Exception ex)
            {
                await ExceptionHandler.HandleExceptionQuietly(GetType().FullName, ExceptionHandler.GetAsyncMethodName(), ex);
            }

            return(wasSuccess);
        }
Exemple #2
0
        public async Task <bool> CheckIfSameClan(ulong clanleaderID, ulong playerID)
        {
            bool clanIsSame = false;

            try
            {
                using (var db = new ClanStorage())
                {
                    var clanLeaderClan = await db.Clan.FirstOrDefaultAsync(x => x.LeaderID == clanleaderID);

                    var playerClan = await db.ClanUser.FirstOrDefaultAsync(x => x.UserID == playerID);

                    if (clanLeaderClan != null && playerClan != null)
                    {
                        if (playerClan.ClanID == clanLeaderClan.ClanID)
                        {
                            clanIsSame = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await ExceptionHandler.HandleExceptionQuietly(GetType().FullName, ExceptionHandler.GetAsyncMethodName(), ex);
            }

            return(clanIsSame);
        }
Exemple #3
0
        public async Task <bool> KickClanMember(ulong clanLeaderID, ulong userID)
        {
            bool wasSuccess = false;

            try
            {
                using (var db = new ClanStorage())
                {
                    var targetClan = await db.Clan.FirstOrDefaultAsync(x => x.LeaderID == clanLeaderID);

                    if (targetClan.ClanID > 0)
                    {
                        var targetUser = await db.ClanUser.FirstOrDefaultAsync(x => x.UserID == userID);

                        if (targetUser != null)
                        {
                            db.ClanUser.Remove(targetUser);
                            await db.SaveChangesAsync();

                            wasSuccess = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await ExceptionHandler.HandleExceptionQuietly(GetType().FullName, ExceptionHandler.GetAsyncMethodName(), ex);
            }

            return(wasSuccess);
        }
Exemple #4
0
        public async Task <bool> AssignNewClanMember(ulong clanLeaderID, string userName, ulong userID)
        {
            bool wasSuccess = false;

            try
            {
                using (var db = new ClanStorage())
                {
                    var targetClan = await db.Clan.FirstOrDefaultAsync(x => x.LeaderID == clanLeaderID);

                    if (targetClan.ClanID > 0)
                    {
                        ClanUser clanUser = new ClanUser
                        {
                            ClanID        = targetClan.ClanID,
                            DateRecruited = DateTime.UtcNow,
                            UserID        = userID
                        };

                        await db.ClanUser.AddAsync(clanUser);

                        await db.SaveChangesAsync();

                        wasSuccess = true;
                    }
                }
            }
            catch (Exception ex)
            {
                await ExceptionHandler.HandleExceptionQuietly(GetType().FullName, ExceptionHandler.GetAsyncMethodName(), ex);
            }

            return(wasSuccess);
        }
Exemple #5
0
        public async Task <bool> CheckIfExistingClanLeader(ulong clanleaderID)
        {
            bool userAlreadyClanLeader = false;

            try
            {
                using (var db = new ClanStorage())
                {
                    userAlreadyClanLeader = await db.Clan.AnyAsync(x => x.LeaderID == clanleaderID);
                }
            }
            catch (Exception ex)
            {
                await ExceptionHandler.HandleExceptionQuietly(GetType().FullName, ExceptionHandler.GetAsyncMethodName(), ex);
            }

            return(userAlreadyClanLeader);
        }
Exemple #6
0
        public async Task <bool> CheckIfExistingClanmember(ulong userID)
        {
            bool wasSuccess = false;

            try
            {
                using (var db = new ClanStorage())
                {
                    wasSuccess = await db.ClanUser.AnyAsync(x => x.UserID == userID);
                }
            }
            catch (Exception ex)
            {
                await ExceptionHandler.HandleExceptionQuietly(GetType().FullName, ExceptionHandler.GetAsyncMethodName(), ex);
            }

            return(wasSuccess);
        }
Exemple #7
0
        public async Task <string> GetClanName(ulong clanLeaderID)
        {
            string clanName = string.Empty;

            try
            {
                using (var db = new ClanStorage())
                {
                    var clan = await db.Clan.FirstOrDefaultAsync(x => x.LeaderID == clanLeaderID);

                    if (clan != null)
                    {
                        clanName = clan.ClanName;
                    }
                }
            }
            catch (Exception ex)
            {
                await ExceptionHandler.HandleExceptionQuietly(GetType().FullName, ExceptionHandler.GetAsyncMethodName(), ex);
            }

            return(clanName);
        }