Пример #1
0
        public async Task <MemeMessage> InsertMessage(
            string teamId,
            string teamDomain,
            string channelId,
            string channelName,
            ChannelType channelType,
            string userId,
            string userName,
            string templateId,
            string message,
            string imageUrl,
            bool isAnonymous)
        {
            if (teamId == null)
            {
                throw new ArgumentNullException(nameof(teamId));
            }
            if (teamDomain == null)
            {
                throw new ArgumentNullException(nameof(teamDomain));
            }
            if (channelId == null)
            {
                throw new ArgumentNullException(nameof(channelId));
            }
            if (channelName == null)
            {
                throw new ArgumentNullException(nameof(channelName));
            }
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }
            if (userName == null)
            {
                throw new ArgumentNullException(nameof(userName));
            }
            if (templateId == null)
            {
                throw new ArgumentNullException(nameof(templateId));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (imageUrl == null)
            {
                throw new ArgumentNullException(nameof(imageUrl));
            }

            channelType.Validate(nameof(channelType));

            var parameters = new
            {
                guid = Format(Guid.NewGuid()),
                now  = Format(DateTime.UtcNow),
                teamId,
                teamDomain,
                channelId,
                channelName,
                channelType = Format(channelType),
                userId,
                userName,
                templateId,
                message,
                imageUrl,
                isAnonymous,
            };

            return(await _connection.QuerySingleAsync <MemeMessage>($@"
                INSERT INTO {MESSAGE_TABLE} (
                    {nameof(MemeMessage.Guid)},
                    {nameof(MemeMessage.CreateDate)},
                    {nameof(MemeMessage.UpdateDate)},
                    {nameof(MemeMessage.TeamId)},
                    {nameof(MemeMessage.TeamDomain)},
                    {nameof(MemeMessage.ChannelId)},
                    {nameof(MemeMessage.ChannelName)},
                    {nameof(MemeMessage.ChannelType)},
                    {nameof(MemeMessage.UserId)},
                    {nameof(MemeMessage.UserName)},
                    {nameof(MemeMessage.TemplateId)},
                    {nameof(MemeMessage.Message)},
                    {nameof(MemeMessage.ImageUrl)},
                    {nameof(MemeMessage.IsAnonymous)}
                ) VALUES (
                    @{nameof(parameters.guid)},
                    @{nameof(parameters.now)},
                    @{nameof(parameters.now)},
                    @{nameof(parameters.teamId)},
                    @{nameof(parameters.teamDomain)},
                    @{nameof(parameters.channelId)},
                    @{nameof(parameters.channelName)},
                    @{nameof(parameters.channelType)},
                    @{nameof(parameters.userId)},
                    @{nameof(parameters.userName)},
                    @{nameof(parameters.templateId)},
                    @{nameof(parameters.message)},
                    @{nameof(parameters.imageUrl)},
                    @{nameof(parameters.isAnonymous)}
                );
                SELECT *
                    FROM {MESSAGE_VIEW}
                    WHERE {nameof(MemeMessage.Id)} = last_insert_rowid();", parameters));
        }