Example #1
0
        public async Task <CreateQrCodeResult> CreateJsonQrCodeAsync(string jsonContent)
        {
            // Create the data
            var data = await qrCodeDataService.GenerateJsonQrCodeDataAsync(jsonContent);

            // Create the image
            var bmp = await qrCodeRenderingService.RenderQrCodeAsBitmapAsync(data);

            // Create a name for the file
            var file = $"{Guid.NewGuid()}.png";

            // Save the file to the system
            await imageFileService.WriteImageFileAsync(file, bmp, qrCodeRenderingService.GetImageCodecInfo(), qrCodeRenderingService.GetEncoderParameters());

            // Add to the database to control access
            var created = new CreatedQrCode
            {
                Created   = DateTime.Now,
                Filename  = file,
                CreatedBy = apiKeyProvider.ApiKey
            };

            var result = await qrCodeRepository.CreateQrCodeAsync(created);

            await qrCodeRepository.SaveChangesAsync();

            return(result == null
                ? CreateQrCodeResult.Failed("Unable to save result")
                : CreateQrCodeResult.Success(result));
        }
Example #2
0
 /// <summary>
 /// Creates an object that represents a successfully created qr code.
 /// </summary>
 /// <param name="qrCode">
 ///     The CreatedQrCode object that wass created.
 ///     <see cref="CreatedQrCode"/>
 /// </param>
 /// <returns></returns>
 public static CreateQrCodeResult Success(CreatedQrCode qrCode)
 {
     return(new CreateQrCodeResult
     {
         Succeeded = true,
         CreatedQrCode = qrCode
     });
 }
        public async Task <CreatedQrCode> CreateQrCodeAsync(CreatedQrCode created)
        {
            var result = await context.CreatedQrCodes.AddAsync(created);

            return(result.Entity);
        }