Ejemplo n.º 1
0
        public async Task <IActionResult> SearchBans(string key)
        {
            var ckey = KeyUtilities.GetCanonicalKey(key);

            if (string.IsNullOrWhiteSpace(ckey) || ckey.Length < 3)
            {
                return(View("badsearch", new BanSearchViewModel()
                {
                    CKey = ckey
                }));
            }

            var searchResults = await _banService.SearchSummariesForKeyAsync(key);

            // If there is only one result, just view it
            if (searchResults.Count() == 1)
            {
                return(RedirectToAction("ViewBans", new { key = searchResults.First().CKey }));
            }

            return(View(new BanSearchViewModel()
            {
                CKey = ckey, Data = searchResults
            }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ViewBans(string key, bool onlyActive = false)
        {
            var bans = await _banService.GetBansForKeyAsync(key, null, onlyActive);

            return(View(new BanViewViewModel()
            {
                CKey = KeyUtilities.GetCanonicalKey(key), Bans = bans, OnlyActive = onlyActive
            }));
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <KeySummary> > SearchSummariesForKeyAsync(string key)
        {
            key = KeyUtilities.GetCanonicalKey(key);
            var query = _dbContext.Bans.GroupBy(x => x.CKey,
                                                (k, g) => new KeySummary
            {
                CKey       = k,
                ServerBans = g.Sum(y => y.BanType == BanType.Server ? 1 : 0),
                JobBans    = g.Sum(y => y.BanType == BanType.Job ? 1 : 0),
                LatestBan  = g.Max(x => x.BannedOn)
            }).Where(x => x.CKey.ToLower().Contains(key));

            return(await query.OrderByDescending(x => x.LatestBan)
                   .ToListAsync());
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <BanData> > GetBansForKeyAsync(string key, int?source, bool onlyActive = false)
        {
            var ckey  = KeyUtilities.GetCanonicalKey(key);
            var query = _dbContext.Bans
                        .Include(x => x.JobBans)
                        .Include(x => x.SourceNavigation)
                        .Where(x => x.CKey == ckey);

            if (source.HasValue)
            {
                query = query.Where(x => x.Source == source);
            }
            if (onlyActive)
            {
                query = query.Where(x => x.UnbannedBy == null && (x.Expires == null || x.Expires > DateTime.UtcNow));
            }
            return(await query.OrderByDescending(x => x.BannedOn)
                   .Select(x => BanData.FromBan(x))
                   .ToListAsync());
        }
Ejemplo n.º 5
0
        public void GetCanonicalKey_FromRaw_ReturnTrue()
        {
            var rawKey = "B o bbahbrown";

            Assert.True("bobbahbrown" == KeyUtilities.GetCanonicalKey(rawKey));
        }
Ejemplo n.º 6
0
 public void GetCanonicalKey_NullArgument_ThrowsException()
 {
     Assert.Throws <ArgumentNullException>(() => KeyUtilities.GetCanonicalKey(null));
 }
Ejemplo n.º 7
0
 public static void MakeKeysCanonical(this Ban ban)
 {
     ban.CKey       = ban.CKey == null ? null : KeyUtilities.GetCanonicalKey(ban.CKey);
     ban.BannedBy   = ban.BannedBy == null ? null : KeyUtilities.GetCanonicalKey(ban.BannedBy);
     ban.UnbannedBy = ban.UnbannedBy == null ? null : KeyUtilities.GetCanonicalKey(ban.UnbannedBy);
 }