public async Task <IActionResult> UpdateTemplateDetails(Guid id, ConfigTemplateCreateDto dto, CancellationToken cancellationToken = default) { var record = await _dbContext.ConfigTemplates.FindAsync(new object[] { id }, cancellationToken : cancellationToken); _ = _mapper.Map(dto, record); await _dbContext.SaveChangesAsync(cancellationToken); return(NoContent()); }
public async Task <IActionResult> CreateTemplate(ConfigTemplateCreateDto dto, CancellationToken cancellationToken = default) { var templateExists = await _dbContext.ConfigTemplates.AnyAsync(e => e.Key == dto.Key, cancellationToken); if (templateExists) { return(BadRequest(new ProblemDetails { Detail = $"A template with key '{dto.Key}' already exists" })); } var template = _mapper.Map <ConfigTemplate>(dto); await _dbContext.AddAsync(template, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); return(Ok()); }