Ejemplo n.º 1
0
        public JsonResult GetTaxonomyReportsByTaxonomyId([DataSourceRequest] DataSourceRequest request, string taxonomyId)
        {
            if (string.IsNullOrWhiteSpace(taxonomyId))
            {
                GetLogger().LogError(string.Format("GetTaxonomyReportsByTaxonomyId fail : taxonomyId Is Null Or WhiteSpace"));

                return(new JsonHttpStatusResult(new { Message = UserMessages.TAXONOMYID_ERROR },
                                                HttpStatusCode.InternalServerError));
            }

            TaxonomyReportModel[] taxonomyReports;
            PeriodTypeModel[]     periodTypes;
            var models = new List <TaxonomyReportViewModel>();

            try
            {
                using (var repository = GetRepository())
                {
                    taxonomyReports = repository.TaxonomyReportRepository.GetTaxonomyReportsByTaxonomyId(taxonomyId);

                    periodTypes = repository.PeriodTypeRepository.GetPeriodTypes();
                }

                foreach (var entity in taxonomyReports)
                {
                    var periodTypeModel = PeriodTypeViewModelHelper.PeriodTypeToViewModel(entity.PeriodType, periodTypes);

                    models.Add(new TaxonomyReportViewModel()
                    {
                        Currency         = entity.Currency,
                        Decimals         = entity.Decimals,
                        DecimalDecimals  = entity.DecimalDecimals,
                        Description      = entity.Description,
                        EntityIdentifire = entity.EntityIdentifier,
                        EntitySchema     = entity.EntitySchema,
                        EntryUri         = entity.EntryUri,
                        FileName         = entity.FileName,
                        Id = entity.Id,
                        IntegerDecimals  = entity.IntegerDecimals,
                        MonetaryDecimals = entity.MonetaryDecimals,
                        PeriodType       = periodTypeModel,
                        PureDecimals     = entity.PureDecimals,
                        SharesDecimals   = entity.SharesDecimals,
                        TaxonomyId       = entity.TaxonomyId,
                        TnProcessorId    = entity.TnProcessorId,
                        TnRevisionId     = entity.TnRevisionId,
                    });
                }
            }
            catch (Exception e)
            {
                GetLogger().LogException(e, string.Format("GetTaxonomyReportsByTaxonomyId({0})", taxonomyId));

                return(new JsonHttpStatusResult(new { Message = UserMessages.UNKNOWN_ERROR }, HttpStatusCode.InternalServerError));
            }

            return(Json(models.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetLocalReportsByTaxonomyId(string taxonomyId, [DataSourceRequest] DataSourceRequest request)
        {
            if (string.IsNullOrWhiteSpace(taxonomyId))
            {
                GetLogger().LogError(string.Format("GetLocalReportsByTaxonomyId fail : taxonomyId Is Null Or WhiteSpace"));

                return(new JsonHttpStatusResult(new { Message = UserMessages.TAXONOMYID_ERROR }, HttpStatusCode.InternalServerError));
            }

            LocalReportModel[] LocalReports;
            PeriodTypeModel[]  periodTypes;
            LocalEntityModel[] entitiesIdentifier;
            TaxonomyReportIdAndDescription[] sourceIds;
            var models = new List <LocalReportViewModel>();

            try
            {
                using (var repository = GetRepository())
                {
                    LocalReports       = repository.LocalReportRepository.GetLocalReportsByTaxonomyId(taxonomyId);
                    periodTypes        = repository.PeriodTypeRepository.GetPeriodTypes();
                    entitiesIdentifier = repository.LocalEntityRepository.GetLocalEntities();
                    sourceIds          = repository.TaxonomyReportRepository.GetShortTaxonomyReportsByTaxonomyId(taxonomyId);
                }

                foreach (var entity in LocalReports)
                {
                    var periodTypeModel = PeriodTypeViewModelHelper.PeriodTypeToViewModel(entity.PeriodType, periodTypes);

                    if (periodTypeModel != null)
                    {
                        periodTypeModel.Description = periodTypeModel.Description != null ? periodTypeModel.Description : "";
                        periodTypeModel.PeriodType  = periodTypeModel.PeriodType != null ? periodTypeModel.PeriodType : null;
                    }
                    else
                    {
                        periodTypeModel.PeriodType  = null;
                        periodTypeModel.Description = "";
                    }

                    var entitiesIdentifierModel = new LocalEntityViewModel();

                    var entityIden = entitiesIdentifier.Where(x => x.Id == entity.EntityIdentifier).FirstOrDefault();

                    if (entityIden != null)
                    {
                        entitiesIdentifierModel.Id          = entityIden.Id;
                        entitiesIdentifierModel.Description = entityIden.Description;
                    }
                    else
                    {
                        entitiesIdentifierModel.Id          = "";
                        entitiesIdentifierModel.Description = "";
                    }

                    var sourceId = sourceIds.Where(x => x.Id == entity.SourceId).FirstOrDefault();

                    if (sourceId == null)
                    {
                        sourceId.Description = "";
                        sourceId.Id          = "";
                    }

                    var sourceIdModel = new SourceIdViewModel()
                    {
                        Description = sourceId.Id + " - " + sourceId.Description,
                        Id          = sourceId.Id
                    };

                    models.Add(new LocalReportViewModel()
                    {
                        Currency         = entity.Currency,
                        Decimals         = entity.Decimals,
                        DecimalDecimals  = entity.DecimalDecimals,
                        Description      = entity.Description,
                        EntityIdentifire = entitiesIdentifierModel,
                        EntitySchema     = entity.EntitySchema,
                        EntryUri         = entity.EntryUri,
                        FileName         = entity.FileName,
                        Id = entity.Id,
                        IntegerDecimals  = entity.IntegerDecimals,
                        MonetaryDecimals = entity.MonetaryDecimals,
                        PeriodType       = periodTypeModel,
                        PureDecimals     = entity.PureDecimals,
                        SharesDecimals   = entity.SharesDecimals,
                        TaxonomyId       = entity.TaxonomyId,
                        TnProcessorId    = entity.TnProcessorId,
                        TnRevisionId     = entity.TnRevisionId,
                        SourceId         = sourceIdModel
                    });
                }
            }
            catch (Exception e)
            {
                GetLogger().LogException(e, string.Format("GetLocalReportsByTaxonomyId({0})", taxonomyId));

                return(new JsonHttpStatusResult(new { Message = UserMessages.UNKNOWN_ERROR }, HttpStatusCode.InternalServerError));
            }

            return(Json(models.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }