Пример #1
0
        public static Dictionary <string, object> SetComplexValue(object value, ColumnSchema attribute, ObjectId tenantId, ObjectId userId,
                                                                  string roleCode, IDynamicRepository dynamicRepository, IDynamicService <DynamicRecord> dynamicService, ISchemaService schemaService)
        {
            var complexAttributeView   = schemaService.GetView(attribute.DataType, ViewCategory.Create, tenantId, roleCode); //TODO: gutierfe.  I think it should be .Catalog.
            var complexAttributeSchema = complexAttributeView.Schemas[attribute.DataType];
            var isValid = true;
            //Create complex field value
            var fieldValue = new Dictionary <string, object>()
            {
                { complexAttributeSchema.UniqueIndex.Count() == 1 ? complexAttributeSchema.UniqueIndex.First() : attribute.ComplexFieldName, value }
            };                                                                                                                                                                                            //assumming it has only one unique index, otherwise, use complex value field
            var dynamicRecordValue = new DynamicRecord().Initialize <DynamicRecord>(fieldValue as Dictionary <string, object>, null, ViewCategory.Catalog);

            ThrowExceptionIfViewIsNull(complexAttributeView);
            var id = ControllerHelper.FindExisting(dynamicRecordValue, complexAttributeView, tenantId, userId, dynamicService, out isValid);

            if (id != ObjectId.Empty)
            {
                dynamicRecordValue = dynamicRepository.Get <DynamicRecord>(attribute.DataType, id, tenantId);
            }
            return(dynamicRecordValue.Values());
        }
Пример #2
0
        public ActionResult Get(string pdfCode, [FromQuery(Name = "ids")] List <string> formMapCollectionsIds)
        {
            PdfFormMap pdfFormMap;

            try
            {
                pdfFormMap = _pdfFormRepository.Get(pdfCode);
            }
            catch (EntityNotFoundException)
            {
                return(NotFound($"pdfCode={pdfCode}"));
            }

            if (pdfFormMap == null)
            {
                return(NotFound($"pdfCode={pdfCode}"));
            }
            if (pdfFormMap.Collections?.Count != formMapCollectionsIds?.Count)
            {
                return(BadRequest("ids not of expected size"));
            }

            var collectionsValues = new Dictionary <string, dynamic>();

            if (pdfFormMap.Collections != null)
            {
                for (int i = 0; i < pdfFormMap.Collections.Count; i++)
                {
                    _dynamicRepository.SetContext(pdfFormMap.Collections[i]);
                    try
                    {
                        var value = _dynamicRepository.Get(formMapCollectionsIds[i]);
                        collectionsValues.Add(pdfFormMap.Collections[i], value);
                    }
                    catch (EntityNotFoundException)
                    {
                        return(NotFound($"ids[{i}]={formMapCollectionsIds[i]}"));
                    }
                }
            }

            var templateFilePath = $"{pdfFormMap.PdfCode}.pdf";

            if (!string.IsNullOrEmpty(_pdfFilesOptions.TemplatePath))
            {
                templateFilePath = $"{_pdfFilesOptions.TemplatePath}{Path.DirectorySeparatorChar}{templateFilePath}";
            }

            var generatedFileName = $"{pdfFormMap.PdfCode}-filled-{DateTimeOffset.Now.ToString("yyyyMMddHHmmss")}.pdf";
            var generatedFilePath = generatedFileName;

            if (!string.IsNullOrEmpty(_pdfFilesOptions.GeneratedPath))
            {
                generatedFilePath = $"{_pdfFilesOptions.GeneratedPath}{Path.DirectorySeparatorChar}{generatedFilePath}";
            }

            FillPdfForm(templateFilePath, generatedFilePath, pdfFormMap, collectionsValues);

            //var stream = new FileStream(@"path\to\file", FileMode.Open);
            //return File(stream, "application/pdf", "FileDownloadName.ext");
            var stream = new FileStream(generatedFilePath, FileMode.Open);

            return(File(stream, "application/pdf", generatedFileName));
        }