public async Task <IActionResult> Post([FromBody] QueuCreateReqDto queuDto, [FromQuery] bool explicid = true) { this.logger.LogTrace("Call Post for Queu name='{0}', topic pattern='{1}', Notification Adress='{2}'.", queuDto.Name, queuDto.TopicPattern, queuDto.NotificationAdress); if (explicid == true) { Guid id = await this.queuRepository.CreateAsync(queuDto).ConfigureAwait(false); await this.notificationSender.SetNotificationAdress(id, queuDto.NotificationAdress).ConfigureAwait(false); QueuDto dto = await this.queuRepository.GetByIdAsync(id).ConfigureAwait(false); this.logger.LogInformation("Create queu with id={0}", dto.Id); return(this.CreatedAtAction(nameof(this.Get), new { id = id }, dto)); } else { QueuDto dto = await this.queuRepository.GetByNameOrDefaultAsync(queuDto.Name).ConfigureAwait(false); if (dto == null) { Guid id = await this.queuRepository.CreateAsync(queuDto).ConfigureAwait(false); await this.notificationSender.SetNotificationAdress(id, queuDto.NotificationAdress).ConfigureAwait(false); dto = await this.queuRepository.GetByIdAsync(id).ConfigureAwait(false); this.logger.LogInformation("Create queu with id={0}", dto.Id); return(this.CreatedAtAction(nameof(this.Get), new { id = id }, dto)); } else { return(this.Ok(dto)); } } }
public async Task <Guid> CreateAsync(QueuCreateReqDto queuDto) { if (queuDto == null) { throw new ArgumentNullException(nameof(queuDto)); } Guid id = Guid.NewGuid(); using SqlConnection connection = new SqlConnection(this.connectionString); await connection.OpenAsync().ConfigureAwait(false); using SqlCommand command = connection.CreateCommand(); command.CommandText = @"INSERT INTO [dbo].[QueuRecord] ([Id], [Name], [TopicPattern],[Created]) VALUES (@id, @name, @topicPattern, @created)"; command.CommandType = System.Data.CommandType.Text; command.Parameters.AddWithValue("@created", this.timeAccessor.UtcNow); command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@name", queuDto.Name); command.Parameters.AddWithValue("@topicPattern", queuDto.TopicPattern ?? DBNull.Value as object); await command.ExecuteNonQueryAsync().ConfigureAwait(false); return(id); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='explicid'> /// </param> /// <param name='body'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> CreateQueuAsync(this IPassiveMQAPI operations, bool?explicid = true, QueuCreateReqDto body = default(QueuCreateReqDto), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateQueuWithHttpMessagesAsync(explicid, body, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='explicid'> /// </param> /// <param name='body'> /// </param> public static object CreateQueu(this IPassiveMQAPI operations, bool?explicid = true, QueuCreateReqDto body = default(QueuCreateReqDto)) { return(Task.Factory.StartNew(s => ((IPassiveMQAPI)s).CreateQueuAsync(explicid, body), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }