Beispiel #1
0
        public ActionResult View(int indicatorId, int siteId)
        {
            using (Entity context = new Entity())
            {
                t_indicator indicator = context.t_indicator.Find(indicatorId);
                if (indicator == null)
                {
                    throw new ArgumentException("Invalid indicatorId: " + indicatorId.ToString());
                }

                t_activity      activity = indicator.aim.activity;
                t_activity_site site     = activity.sites.Where(e => e.site_id == siteId).First();
                if (site == null)
                {
                    throw new ArgumentException(String.Format("Site {0} is not attached to Indicator {1} (Activity {2}).", siteId, indicatorId, activity.activity_id));
                }

                byte languageId = IidCulture.CurrentLanguageId;

                IndicatorSiteObservations model = new IndicatorSiteObservations()
                {
                    ActivityId           = activity.activity_id,
                    ActivityName         = activity.get_name_translated(languageId),
                    IndicatorId          = indicatorId,
                    IndicatorType        = Enumerations.Parse <IndicatorType>(indicator.indicator_type.value),
                    IndicatorTypeFieldId = indicator.indicator_type_fieldid,
                    SiteId                = siteId,
                    IndicatorName         = indicator.get_name_translated(languageId),
                    IndicatorDefinition   = indicator.get_definition_translated(languageId),
                    NumeratorName         = indicator.get_numerator_name_translated(languageId),
                    NumeratorDefinition   = indicator.get_numerator_definition_translated(languageId),
                    DenominatorName       = indicator.get_denominator_name_translated(languageId),
                    DenominatorDefinition = indicator.get_denominator_definition_translated(languageId),
                    DisaggregateByAge     = indicator.disaggregate_by_age,
                    DisaggregateBySex     = indicator.disaggregate_by_sex
                };

                AccessPass = SecurityGuard(CurrentUser, activity.country_id, activity.activity_id, siteId);
                if (AccessPass == BusinessLayer.Identity.UserSecurityAccess.NoAccess)
                {
                    return(RedirectToAction("NoAccess", "Home"));
                }
                ViewBag.AccessRights = AccessPass;

                return(View(model));
            }
        }
Beispiel #2
0
        private void SetProperties(t_indicator entity, bool loadChildren, bool loadParent, bool translate)
        {
            ActivityId   = entity.aim?.activity_id ?? -1; // Refactor as nullable int when possible.
            AimId        = entity.aim_id;
            IndicatorId  = entity.indicator_id;
            TypeFieldId  = entity.indicator_type_fieldid;
            TypeValue    = entity.indicator_type?.value;
            GroupFieldId = entity.group_fieldid;
            GroupValue   = entity.indicator_group?.value;
            DataCollectionFrequencyFieldId = entity.data_collection_frequency_fieldid;
            DataCollectionFrequencyValue   = entity.data_collection_frequency?.value;
            SamplingFieldId    = entity.sampling_fieldid;
            ReportClassFieldId = entity.report_class_fieldid;
            ReportClassValue   = entity.report_class?.value;
            SamplingValue      = entity.sampling?.value;
            ChangeVariable     = entity.change_variable;
            DisaggregateBySex  = entity.disaggregate_by_sex;
            DisaggregateByAge  = entity.disaggregate_by_age;
            if (DisaggregateByAge)
            {
                AgeRanges =
                    entity.indicator_age_ranges
                    .OrderBy(e => e.indicator_age_range_id)
                    .ToDictionary(e => Convert.ToString(e.indicator_age_range_id), e => e.age_range);
            }
            else
            {
                AgeRanges = new Dictionary <string, string>();
            }
            TargetPerformance        = entity.target_performance;
            ThresholdGoodPerformance = entity.threshold_good_performance;
            ThresholdPoorPerformance = entity.threshold_poor_performance;
            IncreaseIsGood           = entity.increase_is_good;
            RatePerFieldId           = entity.rate_per_fieldid;
            RatePerValue             = entity.rate_per?.value;
            Active = entity.active;
            Sort   = entity.sort;

            if (translate)
            {
                Definition            = entity.get_definition_translated(CurrentLanguageId);
                Name                  = entity.get_name_translated(CurrentLanguageId);
                NumeratorName         = entity.get_numerator_name_translated(CurrentLanguageId);
                NumeratorDefinition   = entity.get_numerator_definition_translated(CurrentLanguageId);
                NumeratorSource       = entity.get_numerator_source_translated(CurrentLanguageId);
                DenominatorName       = entity.get_denominator_name_translated(CurrentLanguageId);
                DenominatorDefinition = entity.get_denominator_definition_translated(CurrentLanguageId);
                DenominatorSource     = entity.get_denominator_source_translated(CurrentLanguageId);
                //

                DataCollectionFrequencyValue = entity.get_data_frequency_translated(CurrentLanguageId, DataCollectionFrequencyValue);
            }
            else
            {
                Definition            = entity.definition;
                Name                  = entity.name;
                NumeratorName         = entity.numerator_name;
                NumeratorDefinition   = entity.numerator_definition;
                NumeratorSource       = entity.numerator_source;
                DenominatorName       = entity.denominator_name;
                DenominatorDefinition = entity.denominator_definition;
                DenominatorSource     = entity.denominator_source;
            }

            if (loadParent)
            {
                Aim = new Aim(AimId, false);
            }

            if (loadChildren)
            {
                ActivityAims =
                    UserAssignedObjects.GetAims(entity.aim.activity.aims, CurrentUser)
                    .Select(e => new Tuple <int?, string>(e.aim_id, e.get_name_translated(CurrentLanguageId)))
                    .ToList();
                Sites =
                    entity.aim.activity.sites
                    .Select(e => new ActivitySite(e))
                    .ToList();
                HasObservations = entity.observations?.Any() ?? false;
                OtherIndicators =
                    UserAssignedObjects.GetIndicators(entity.aim.indicators, CurrentUser)
                    .Where(e => e.indicator_id != IndicatorId)
                    .Select(e => new Indicator(e, false, true))
                    .ToList();
            }
        }