コード例 #1
0
        public void WhenTemplateIsMergedToRow_ThenOutputContainsBoth()
        {
            var result = TemplateUtils.MergeBaseTemplatingWithRows(JObject.FromObject(new { Prop1 = 1 }), JObject.FromObject(new { Prop2 = 2 }));

            result["Prop1"].Value <int>().Should().Be(1);
            result["Prop2"].Value <int>().Should().Be(2);
        }
コード例 #2
0
        public ActionResult <IEnumerable <NewPdfResponse> > AddNewPdf([Required][FromRoute] string groupId, [FromBody] NewPdfRequest request)
        {
            if (!request.RowData.Any())
            {
                return(BadRequest("Expected to get atleast one 'rowData' element, but got none."));
            }

            var responses = request.RowData.Select(row =>
            {
                var entity = _context.PdfFiles.Add(new PdfEntity(groupId, PdfType.Pdf)
                {
                    Options = request.Options
                }).Entity;
                var templatedRow = TemplateUtils.MergeBaseTemplatingWithRows(request.BaseData, row);
                PersistParsedHtmlTemplateOfPdfDocument(entity, request.Html, templatedRow);

                _context.SaveChanges();

                entity.HangfireJobId =
                    _backgroundJobs.Enqueue <IPdfQueue>(que => que.CreatePdf(entity.Id));

                _context.SaveChanges();

                var pdfUri  = _uris.PdfUri(groupId, entity.FileId);
                var htmlUri = _uris.HtmlUri(groupId, entity.FileId);

                return(new NewPdfResponse(entity.FileId, entity.GroupId, pdfUri, htmlUri, row));
            });

            return(Accepted(responses.ToList()));
        }
コード例 #3
0
        public void WhenDataIsMerged_ReturnCopyInsteadOfModifyingExisting()
        {
            var inputJObject = JObject.FromObject(new { Prop1 = 1 });
            var result       = TemplateUtils.MergeBaseTemplatingWithRows(inputJObject, JObject.FromObject(new { Prop1 = 2 }));

            result["Prop1"].Value <int>().Should().Be(2);
            inputJObject["Prop1"].Value <int>().Should().Be(1);
        }