예제 #1
0
        public async Task <bool> AssignNewClanleader(string clanName, string leaderName, ulong leaderID)
        {
            bool wasSuccess = false;

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

                    if (clan != null & leaderID > 0 & !string.IsNullOrEmpty(leaderName))
                    {
                        clan.LeaderID   = leaderID;
                        clan.LeaderName = leaderName;
                        await db.SaveChangesAsync();

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

            return(wasSuccess);
        }
예제 #2
0
        public async Task <bool> CreateNewClan(Clan clan)
        {
            bool wasSuccess = false;

            try
            {
                using (var db = new ClanStorage())
                {
                    if (await db.Clan.AnyAsync(x => x.ClanName.ToLower() == clan.ClanName.ToLower()))
                    {
                        wasSuccess = false;
                    }
                    else
                    {
                        await db.Clan.AddAsync(clan);

                        await db.SaveChangesAsync();

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

            return(wasSuccess);
        }
예제 #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);
        }
예제 #4
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);
        }
예제 #5
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);
        }