public void AddMessage(string UserName, string MessageText) { var _user = UsersTable.FirstOrDefault(x => x.UserName.ToLower() == UserName.ToLower()); if (_user != null) { MessageTable.Add(new Message() { Text = MessageText, user = _user }); AddToHistory(new UserMessage() { Message = MessageText, UserName = _user.UserName }, false); SaveChanges(); } }