/// <summary> /// Returns the <see cref="CultureInfo"/> based on <see cref="GenerateMarkupArguments"/>. /// Throws an exception if not one of the supported cultures in the provided <see cref="TenantInfo"/> /// </summary> public static CultureInfo GetCulture(GenerateMarkupArguments args, TenantInfo tenantInfo) { // Some validation if (args.Culture != null && tenantInfo.PrimaryLanguageId != args.Culture && tenantInfo.SecondaryLanguageId != args.Culture && tenantInfo.TernaryLanguageId != args.Culture) { throw new BadRequestException($"Culture {args.Culture} is not supported in this company"); } var culture = CultureInfo.CurrentUICulture; if (!string.IsNullOrWhiteSpace(args.Culture)) { try { culture = new CultureInfo(args.Culture, false); } catch (CultureNotFoundException) { throw new BadRequestException($"Culture {args.Culture} does not exist"); } } return(culture); }
public async Task <ActionResult <MarkupPreviewResponse> > Preview([FromBody] MarkupPreviewTemplate entity, [FromQuery] GenerateMarkupArguments args, CancellationToken cancellation) { return(await ControllerUtilities.InvokeActionImpl(async() => { var(body, downloadName) = await _service.Preview(entity, args, cancellation); // Prepare and return the response var response = new MarkupPreviewResponse { Body = body, DownloadName = downloadName }; return Ok(response); }, _logger)); }
public async Task <(string Body, string DownloadName)> Preview(MarkupPreviewTemplate entity, GenerateMarkupArguments args, CancellationToken cancellation) { // Everything to input in the template service var templates = new (string, string)[] { (entity.DownloadName, MimeTypes.Text), (entity.Body, entity.MarkupLanguage) };
public async Task <(byte[] FileBytes, string FileName)> PrintById(TKey id, int templateId, [FromQuery] GenerateMarkupArguments args, CancellationToken cancellation) { var collection = ControllerUtilities.GetCollectionName(typeof(TEntity)); var defId = DefinitionId; var repo = GetRepository(); var template = await repo.Query <MarkupTemplate>().FilterByIds(new int[] { templateId }).FirstOrDefaultAsync(cancellation); if (template == null) { // Shouldn't happen in theory cause of previous check, but just to be extra safe throw new BadRequestException($"The template with Id {templateId} does not exist"); } if (!(template.IsDeployed ?? false)) { // A proper UI will only allow the user to use supported template throw new BadRequestException($"The template with Id {templateId} is not deployed"); } // The errors below should be prevented through SQL validation, but just to be safe if (template.Usage != MarkupTemplateConst.QueryById) { throw new BadRequestException($"The template with Id {templateId} does not have the proper usage"); } if (template.MarkupLanguage != MimeTypes.Html) { throw new BadRequestException($"The template with Id {templateId} is not an HTML template"); } if (template.Collection != collection) { throw new BadRequestException($"The template with Id {templateId} does not have Collection = '{collection}'"); } if (template.DefinitionId != null && template.DefinitionId != defId) { throw new BadRequestException($"The template with Id {templateId} does not have DefinitionId = '{defId}'"); } // Onto the printing itself var templates = new (string, string)[] {