private ColumnValidationResult ValidateTaxonomyFields(LocalEntityViewModel localEntity)
        {
            ColumnValidationResult result = new ColumnValidationResult();

            result.EntityId = localEntity.Id;

            result = ValidationField("Id", localEntity.Id, "שדה קוד ישות הינו שדה חובה", result);

            return(result);
        }
        public ActionResult AddLocalEntity([DataSourceRequest] DataSourceRequest request, LocalEntityViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                using (var repository = GetRepository())
                {
                    var result = ValidateTaxonomyFields(model);

                    if (result.ValidationMessages.Count > 0)
                    {
                        return(new JsonHttpStatusResult(new { Message = result.ValidationMessages }, HttpStatusCode.InternalServerError));
                    }
                    if (!IsLocalEntityUniqueId(model.Id))
                    {
                        return(new JsonHttpStatusResult(new { Message = UserMessages.TAXSONOMY_IS_NOT_UNIQ_ID }, HttpStatusCode.InternalServerError));
                    }

                    var entity = new LocalEntityModel()
                    {
                        Description = model.Description,
                        Id          = model.Id
                    };

                    try
                    {
                        repository.LocalEntityRepository.Add(entity);
                    }
                    catch (Exception e)
                    {
                        GetLogger().LogException(e, string.Format("InsertLocalEntities({0})", model.Id));

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

                    repository.Commit();
                }
            }
            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
        public JsonResult DeleteLocalEntity([DataSourceRequest] DataSourceRequest request, LocalEntityViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(model.Id))
                {
                    return(new JsonHttpStatusResult(new { Message = UserMessages.TAXONOMYID_ERROR }, HttpStatusCode.InternalServerError));
                }

                using (var repository = GetRepository())
                {
                    var entity = repository.LocalEntityRepository.GetLocalEntityById(model.Id);

                    if (entity == null)
                    {
                        return(new JsonHttpStatusResult(new { Message = UserMessages.ROW_NOT_FOUND_ERROR }, HttpStatusCode.InternalServerError));
                    }

                    try
                    {
                        repository.LocalEntityRepository.Remove(entity);
                        repository.Commit();
                    }
                    catch (Exception e)
                    {
                        GetLogger().LogException(e, string.Format("DeleteLocalEntity({0})", model.Id));

                        return(new JsonHttpStatusResult(new { Message = UserMessages.UNKNOWN_ERROR }, HttpStatusCode.InternalServerError));
                    }
                }
            }
            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
        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));
        }