public void Update(ParsedMessage entity)
        {
            using (var conn = new SqlConnection(Settings.Default.ConnectionString))
            {
                conn.Open();

                conn.Execute("UPDATE ParsedMessage SET " +
                             "BodyParsed = @BodyParsed, " +
                             "BodyPlain = @BodyPlain, " +
                             "BodyRich = @BodyRich, " +
                             "ClientType = @ClientType, " +
                             "CreatedAt = @CreatedAt, " +
                             "IsDirectMessage = @IsDirectMessage, " +
                             "GroupId = @GroupId, " +
                             "RepliedToId = @RepliedToId, " +
                             "SenderId = @SenderId, " +
                             "ThreadId = @ThreadId, " +
                             "Url = @Url, " +
                             "WebUrl = @WebUrl, " +
                             "LikedByCount = @LikedByCount, " +
                             "LikedByNames = @LikedByNames " +
                             "WHERE Id = @Id",
                             entity);
            }
        }
        public void Add(ParsedMessage entity)
        {
            using (var conn = new SqlConnection(Settings.Default.ConnectionString))
            {
                conn.Open();

                conn.Execute("INSERT INTO ParsedMessage (Id, BodyParsed, BodyPlain, BodyRich, ClientType, CreatedAt, IsDirectMessage, " +
                    "GroupId, RepliedToId, SenderId, ThreadId, Url, WebUrl, LikedByCount, LikedByNames) VALUES " +
                    "(@Id, @BodyParsed, @BodyPlain, @BodyRich, @ClientType, @CreatedAt, @IsDirectMessage, " +
                    "@GroupId, @RepliedToId, @SenderId, @ThreadId, @Url, @WebUrl, @LikedByCount, @LikedByNames)", entity);
            }
        }
        public void Run()
        {
            var messages = _messageService.GetAll();

            foreach (var message in messages)
            {
                var messageObj = JObject.Parse(message.RawContent);
                var parsedMessage = new ParsedMessage();
                parsedMessage.Id = (long) messageObj["id"];
                parsedMessage.BodyParsed = (string) messageObj.SelectToken("body.parsed");
                parsedMessage.BodyPlain = (string) messageObj.SelectToken("body.plain");
                parsedMessage.BodyRich = (string) messageObj.SelectToken("body.rich");
                parsedMessage.ClientType = (string) messageObj["client_type"];
                parsedMessage.CreatedAt = DateTimeOffset.Parse((string) messageObj["created_at"]);
                parsedMessage.IsDirectMessage = (bool) messageObj["direct_message"];
                parsedMessage.GroupId = (long?) messageObj["group_id"];
                parsedMessage.RepliedToId = (long?) messageObj["replied_to_id"];
                parsedMessage.SenderId = (long?) messageObj["sender_id"];
                parsedMessage.ThreadId = (long) messageObj["thread_id"];
                parsedMessage.Url = (string) messageObj["url"];
                parsedMessage.WebUrl = (string) messageObj["web_url"];
                parsedMessage.LikedByCount = (int?) messageObj.SelectToken("liked_by.count");
                parsedMessage.LikedByNames = string.Join(", ", messageObj.SelectToken("liked_by.names"));

                var existingParsedMessage = _parsedMessageService.GetById(parsedMessage.Id);
                if (existingParsedMessage == null)
                {
                    _parsedMessageService.Add(parsedMessage);
                    Console.WriteLine("Added " + parsedMessage.Id);
                }
                else
                {
                    _parsedMessageService.Update(parsedMessage);
                    Console.WriteLine("Updated " + parsedMessage.Id);
                }
            }
        }