public IActionResult Details(int?templateId) { TemplateVM vm = service.GetTemplateById(templateId); ViewBag.IsNewTemplate = false; return(View(vm)); }
private TemplateVM MapEntityToVM(PublicationTemplate entity, bool includeFields) { TemplateVM res = new TemplateVM { CreationDate = entity.CreationDate, Description = entity.Description, ModifiedDate = entity.ModifiedDate, Name = entity.Name, TemplateId = entity.PublicationTemplateId, IsActive = entity.IsActive, PublicationsCount = entity.Publications.Count() }; if (includeFields) { foreach (FieldTemplate field in entity.FieldsTemplates) { res.Fields.Add(new FieldVM { AttachId = field.FieldTemplateId, FieldId = field.FieldId, Type = field.Field.Type, Name = field.Field?.Name }); } } return(res); }
static async System.Threading.Tasks.Task Main(string[] args) { var httpClient = new HttpClient(); httpClient.BaseAddress = new Uri("https://fastreport.cloud"); httpClient.DefaultRequestHeaders.Authorization = new FastReportCloudApiKeyHeader(ApiKey); var subscriptions = new SubscriptionsClient(httpClient); var rpClientTemplates = new TemplatesClient(httpClient); var rpClientExports = new ExportsClient(httpClient); var downloadClient = new DownloadClient(httpClient); var subscription = (await subscriptions.GetSubscriptionsAsync(0, 10)).Subscriptions.First(); var templateFolder = subscription.TemplatesFolder.FolderId; var exportFolder = subscription.ExportsFolder.FolderId; TemplateCreateVM templateCreateVM = new TemplateCreateVM() { Name = "box.frx", Content = TestData.BoxReport }; TemplateVM uploadedFile = await rpClientTemplates.UploadFileAsync(templateFolder, templateCreateVM); ExportTemplateTaskVM export = new ExportTemplateTaskVM() { FileName = "box.pdf", FolderId = exportFolder, Format = ExportTemplateTaskVMFormat.Pdf }; ExportVM exportedFile = await rpClientTemplates.ExportAsync(uploadedFile.Id, export) as ExportVM; string fileId = exportedFile.Id; int attempts = 3; exportedFile = rpClientExports.GetFile(fileId); while (exportedFile.Status != ExportVMStatus.Success && attempts >= 0) { await Task.Delay(1000); exportedFile = rpClientExports.GetFile(fileId); attempts--; } using (var file = await downloadClient.GetExportAsync(fileId)) { using (var pdf = File.Open("report.pdf", FileMode.Create)) { file.Stream.CopyTo(pdf); } } }
public TemplateVM CopyTemplate(int id) { TemplateVM res = GetTemplateById(id); res.TemplateId = -1; res.PublicationsCount = 0; foreach (var field in res.Fields) { field.AttachId = -1; } return(res); }
public async Task DOCX(string filepath, long?userId) { var rpClientTemplates = new TemplatesClient(httpClient); var rpClientExports = new ExportsClient(httpClient); var downloadClient = new DownloadClient(httpClient); var templateFolder = subscription.TemplatesFolder.FolderId; var exportFolder = subscription.ExportsFolder.FolderId; TemplateCreateVM templateCreateVM = new TemplateCreateVM() { Name = "box.frx", Content = Convert.ToBase64String(File.ReadAllBytes(filepath)) }; TemplateVM uploadedFile = await rpClientTemplates.UploadFileAsync(templateFolder, templateCreateVM); ExportTemplateTaskVM export = new ExportTemplateTaskVM() { FileName = "box.docx", FolderId = exportFolder, Format = ExportTemplateTaskVMFormat.Docx }; ExportVM exportedFile = await rpClientTemplates.ExportAsync(uploadedFile.Id, export) as ExportVM; string fileId = exportedFile.Id; int attempts = 3; exportedFile = rpClientExports.GetFile(fileId); while (exportedFile.Status != ExportVMStatus.Success && attempts >= 0) { await Task.Delay(1000); exportedFile = rpClientExports.GetFile(fileId); attempts--; } using (var file = await downloadClient.GetExportAsync(fileId)) { using (var pdf = File.Open("report.docx", FileMode.Create)) { file.Stream.CopyTo(pdf); } using (var stream = File.Open("report.docx", FileMode.Open)) { await Program.tgBot.SendDocumentAsync(userId, new InputOnlineFile(stream, "report.docx")); } } //await Program.tgBot.SendDocumentAsync(userId, name); }
private async Task <TemplateVM> SendTemplateToCloud(string folderId) { if (ReportTemplate == null) { TemplateCreateVM tCreateVM = new() { Name = "pricelist.frx", Content = BarcodeReport }; ReportTemplate = await templatesClient.UploadFileAsync(folderId, tCreateVM); } return(ReportTemplate); } }
private async Task <TemplateVM> SendTemplateToCloud(string folderId) { if (ReportTemplate == null) { TemplateCreateVM tCreateVM = new() { Name = "pricelist.frx", Content = Convert.ToBase64String(System.IO.File.ReadAllBytes(Directory.GetCurrentDirectory() + @"/Resources/PriceList.frx")) }; ReportTemplate = await templatesClient.UploadFileAsync(folderId, tCreateVM); } return(ReportTemplate); } #endregion }
public TemplateVM GetTemplateById(int?id) { TemplateVM res = new TemplateVM(); if (id.HasValue) { PublicationTemplate templateEntity = context.PublicationTemplates .Include(t => t.Publications) .Include(t => t.FieldsTemplates) .ThenInclude(ft => ft.Field) .FirstOrDefault(t => t.PublicationTemplateId == id.Value); if (templateEntity != null) { res = MapEntityToVM(templateEntity, true); } } return(res); }
public ActionResult SaveTemplate(TemplateVM model, string returnUrl) { var template = TemplateMgr.GetTemplate(model.TemplateID); template.TemplateCode = model.TemplateCode; template.TemplateName = model.TemplateName; template.CategoryID = model.CategoryID; template.LastUpdateTime = DateTime.UtcNow; TemplateMgr.SaveTemplate(template); if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("EditTemplate", "Home", new { Area = ReportingGlobal.AreaName, TemplateID = model.TemplateID })); } }
public ActionResult Create(TemplateVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoAdd(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGrid()); } } }
public ActionResult Edit(TemplateVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoEdit(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID)); } } }
// GET: Template public ActionResult Index() { TemplateViewModel templateViewModel = new TemplateViewModel { PageId = "Template" }; TemplateManager templateManager = new TemplateManager(); templateViewModel.Templates = new List <TemplateVM>(); foreach (var template in templateManager.Read(null)) { Stream stream = new MemoryStream(template.File.Content); TemplateVM templateVm = new TemplateVM { Name = template.File.Name, Content = getSampleLetter(stream), Id = template.Id }; templateViewModel.Templates.Add(templateVm); } return(View(templateViewModel)); }
public TemplateWindow(TemplateType type) { InitializeComponent(); DataContext = new TemplateVM(type); }