public async Task <List <LivechatMessagePack> > LoadLastMessages(LivechatUserSession livechatSession, LivechatChannel userCurrentChannel)
        {
            using (var db = sqlFactory.GetNewConnection())
            {
                var messages = await db.QueryAsync <LivechatMessagePack>(
                    $"select * from {nameof(LivechatMessagePack)} where ChannelId = @ChannelId order by CreatedAt desc",
                    new
                {
                    ChannelId = userCurrentChannel.ChannelId
                });

                var result = messages.AsList();

                foreach (var message in result)
                {
                    if (!string.IsNullOrEmpty(message.SerializedElements))
                    {
                        message.Elements = JsonConvert.DeserializeObject <List <ElementUI> >(message.SerializedElements);
                    }
                }

                result.Reverse();

                return(result);
            }
        }
 public async Task CreateNewSession(LivechatUserSession livechatSession)
 {
     using (var db = sqlFactory.GetNewConnection())
     {
         await db.ExecuteAsync(
             $"insert {nameof(LivechatUserSession)}(LivechatUserId, ConnectionId) values (@LivechatUserId, @ConnectionId)",
             new
         {
             LivechatUserId = livechatSession.LivechatUserId,
             ConnectionId   = livechatSession.ConnectionId
         });
     }
 }