コード例 #1
0
 public bool HasBox(string input)
 {
     if (BoxDatabase.TryFindExactBox(input, out Box? result))
     {
         return(_context.BoxEntries.Any(x => x.User.Id == _user.Id && (x.Text == input || x.Box !.Id == result.Id)));
     }
     return(_context.BoxEntries.Any(x => x.User.Id == _user.Id && x.Text == input));
 }
コード例 #2
0
        public void ReAssociateBoxes()
        {
            List <BoxEntry> userBoxEntries = _context.BoxEntries.Where(x => x.User.Id == _user.Id).ToList();

            foreach (BoxEntry entry in userBoxEntries)
            {
                entry.Box = BoxDatabase.TryFindExactBox(entry.Text, out Box? result) ? result : null;
            }
            _context.SaveChanges();
        }
コード例 #3
0
        public BoxEntry AddBox(string input)
        {
            BoxEntry entry = new BoxEntry();

            entry.User = _user;
            entry.Text = input;

            if (BoxDatabase.TryFindExactBox(input, out Box? result))
            {
                entry.Box = result;
                _context.Boxes.Attach(result);
            }

            _context.BoxEntries.Add(entry);
            _context.SaveChanges();
            return(entry);
        }
コード例 #4
0
 public void Run(IrcMessage theMessage)
 {
     using (var context = new BotContext())
     {
         IQueryable <BoxEntry> filtered;
         if (BoxDatabase.TryFindExactBox(theMessage.CommandLine, out Box? result))
         {
             filtered = context.BoxEntries.Where(x => x.Box !.Id == result.Id);
         }
         else
         {
             filtered = context.BoxEntries.Where(x => x.Text.Contains(theMessage.CommandLine));
         }
         string besitzer = filtered.Select(x => x.User.LastUsedName.Name).Where(x => !String.IsNullOrEmpty(x)).Distinct().OrderBy(x => x).Join(", ");
         if (!String.IsNullOrEmpty(besitzer))
         {
             theMessage.SendPrivateMessage("Folgende Benutzer scheinen diese Box zu besitzen: " + besitzer);
         }
         else
         {
             theMessage.SendPrivateMessage("Diese Box scheint niemand zu besitzen!");
         }
     }
 }