public async Task <RestfulQrCode> CreateAsync(RestfulQrCode restfulQrCode) { using var connection = new NpgsqlConnection(connectionString); var id = await connection.ExecuteScalarAsync <Guid>( @"INSERT INTO qr_codes.qr_codes (id, created_by, created, type, render_type, filename, model, public_url) VALUES (@Id, @CreatedBy, @Created, @Type, @RenderType, @Filename, @Model, @PublicUrl) RETURNING id", new { restfulQrCode.Id, restfulQrCode.CreatedBy, restfulQrCode.Created, restfulQrCode.Type, restfulQrCode.RenderType, restfulQrCode.Filename, restfulQrCode.PublicUrl, Model = JsonSerializer.Serialize(restfulQrCode.Model) }); return(await GetAsync(id)); }
private async Task <IActionResult> HandleAsync(byte[] result, QrCodeType qrCodeType, object model) { // Generate a file name for the qr code var id = Guid.NewGuid(); var filename = $"{id}.{ImageUtils.GetFileExtensionFromImageType(renderOptions.RenderType)}"; var host = config["HostUrl"] ?? $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}"; // Generate a database result for the file var qrCode = new RestfulQrCode { Id = id, Created = DateTime.Now.ToUniversalTime(), CreatedBy = apiKeyProvider.ApiKey.Id, Filename = filename, Model = model, RenderType = renderOptions.RenderType, Type = qrCodeType, PublicUrl = string.Join(@"/", host, "images", apiKeyProvider.ApiKey.LocationId, filename) }; // Save the file in S3 var s3Result = await imageService.UploadAsync(apiKeyProvider.ApiKey, filename, result); if (!s3Result) { return(StatusCode(500)); } // Save the db var saveResult = await imageService.CreateAsync(qrCode); if (saveResult == null) { return(StatusCode(500)); } return(Created(qrCode.PublicUrl, qrCode)); }
public async Task <RestfulQrCode> CreateAsync(RestfulQrCode restfulQrCode) { return(await repository.CreateAsync(restfulQrCode)); }