public int lastMessageID()
 {
     using (MessageContext db = new MessageContext())
     {
         if (db.Messages.Count() != 0)
             return db.Messages.Max(el => el.id);
         else return 0;
     }
 }
 public string[] getMessagesList(String user, String dialogue, DateTime connTime, int messageID)
 {
     lock (usersOnline)
     {
         usersOnline[user] = connTime;
     }
     using (MessageContext db = new MessageContext())
     {
         string[] sendMssgs;
         if(dialogue != "commonDialogue")
             sendMssgs = db.Messages.Where(el => el.id >= messageID && ((el.loginAddressee == user && el.loginSender == dialogue) || (el.loginAddressee == dialogue && el.loginSender == user))).Select(el => el.loginSender + " " + el.time + " : " + el.message).ToArray();
         else
             sendMssgs = db.Messages.Where(el => el.id >= messageID && el.loginAddressee == dialogue).Select(el => el.loginSender + " " + el.time + " : " + el.message).ToArray();
         Console.WriteLine("The list of messages was updated on the client side.");
         return sendMssgs;
     }
 }
 public string verifyMessage(String msg, String user, String dialogue, DateTime connTime)
 {
     lock (usersOnline)
     {
         usersOnline[user] = connTime;
     }
     Regex regex1 = new Regex("з[^а-я]*а[^а-я]*м");
     Regex regex2 = new Regex("д[^а-я]*а[^а-я]*н");
     if (msg.Length > 100)
     {
         Console.WriteLine("The user's message wasn't accepted (>100 symbols).");
         return "LONGMESSAGE";
     }
     else if (regex1.IsMatch(msg) || regex2.IsMatch(msg))
     {
         Console.WriteLine("The user's message wasn't accepted (banned word).");
         return "BANNEDWORD";
     }
     else
     {
         using (MessageContext db = new MessageContext())
         {
             //if (db.Messages.Count() != 0)
             //    messages.Add(messages.ElementAt(messages.Count - 1).Key + 1, dialogue + "|" + user + " " + connTime.ToShortTimeString() + " : " + msg);
             //else
             //    messages.Add(0, dialogue + "|" + user + " " + connTime.ToShortTimeString() + " : " + msg);
             Message newMsg = new Message { loginSender = user, loginAddressee = dialogue, message = msg, time = connTime.ToShortTimeString() };
             db.Messages.Add(newMsg);
             db.SaveChanges();
         }
         Console.WriteLine("The user's message was accepted.");
         return "MESSAGEACCEPTED";
     }
 }