public ActionResult IndicatorNew()
        {
            // Get text properties of selected indicator
            var properties = _reader.GetIndicatorMetadataTextProperties();

            var userId        = _reader.GetUserByUserName(UserDetails.CurrentUser().Name).Id;
            var permissionIds = _reader.GetUserGroupPermissionsByUserId(userId).Select(x => x.ProfileId);
            var model         = new ProfileIndex {
                Profiles =
                    _reader.GetProfiles()
                    .OrderBy(x => x.Name)
                    .Where(x => permissionIds.Contains(x.Id))
            };

            var listOfProfiles = CommonUtilities.GetOrderedListOfProfiles(model.Profiles);

            ViewBag.listOfProfiles = listOfProfiles;

            var domains        = new ProfileMembers();
            var defaultProfile = listOfProfiles.FirstOrDefault();

            ViewBag.listOfDomains = CommonUtilities.GetOrderedListOfDomainsWithGroupId(domains, defaultProfile, _profileRepository);

            ViewBag.selectedSex = new SelectList(_lookUpsRepository.GetSexes(), "SexID", "Description");

            ViewBag.selectedAge = new SelectList(_lookUpsRepository.GetAges(), "AgeID", "Description");

            var comparatorOptions = CommonUtilities.GetListOfComparators(ComparatorIds.NationalAndSubnational);

            ViewBag.selectedComparator = new SelectList(comparatorOptions, "Value", "Text");

            ViewBag.selectedComparatorMethod = new SelectList(_reader.GetAllComparatorMethods(), "Id", "Name");

            ViewBag.selectedYearType = new SelectList(_lookUpsRepository.GetYearTypes(), "Id", "Label");

            ViewBag.selectedValueType = new SelectList(_lookUpsRepository.GetIndicatorValueTypes(), "Id", "Label");

            ViewBag.selectedCIMethodType = new SelectList(_lookUpsRepository.GetConfidenceIntervalMethods(), "Id", "Name");

            ViewBag.selectedUnitType = new SelectList(_lookUpsRepository.GetUnits(), "Id", "Label");

            ViewBag.selectedDenominatorType = new SelectList(_lookUpsRepository.GetDenominatorTypes(), "Id", "Name");

            return(View(properties));
        }
Ejemplo n.º 2
0
        public ActionResult IndicatorEdit(string urlKey, int areaType, int selectedDomainNumber, int indicatorId, int ageId, int sexId)
        {
            Profile profile = GetProfile(urlKey, selectedDomainNumber, areaType);

            // Get text properties of selected indicator
            IList <IndicatorMetadataTextProperty> properties = _reader.GetIndicatorMetadataTextProperties();
            int groupId = profile.GetSelectedGroupingMetadata(selectedDomainNumber).GroupId;

            // Assemble model
            var model = new IndicatorEdit
            {
                SelectedIndicatorId = indicatorId,
                UrlKey     = urlKey,
                Profile    = profile,
                TextValues = _reader.GetIndicatorTextValues(indicatorId, properties, profile.Id).ToList()
            };

            // Prev/Next
            if (profile.IndicatorNames.Count > 0)
            {
                int index = -1;
                IList <GroupingPlusName> names = profile.IndicatorNames;
                for (int i = 0; i < names.Count(); i++)
                {
                    if (names[i].IndicatorId == indicatorId)
                    {
                        index = i;
                        break;
                    }
                }

                int prevIndex = index > 0 ? index - 1 : names.Count - 1;
                int nextIndex = index == names.Count - 1 ? 0 : index + 1;
                model.IndicatorIdNext     = names[nextIndex].IndicatorId;
                model.IndicatorIdPrevious = names[prevIndex].IndicatorId;
            }

            //Get the indicatore meta data
            IndicatorMetadata indicatorMetaData = _reader.GetIndicatorMetadata(indicatorId);

            model.IndicatorMetadata = indicatorMetaData;

            IList <Grouping>       groupList          = _reader.GetGroupings(groupId);
            IEnumerable <Grouping> indicatorGroupData =
                groupList.Where(
                    g =>
                    g.IndicatorId == indicatorId &&
                    g.GroupId == groupId &&
                    g.AreaTypeId == areaType &&
                    g.AgeId == ageId &&
                    g.SexId == sexId);

            Grouping[] groupData = indicatorGroupData as Grouping[] ?? indicatorGroupData.ToArray();
            model.Grouping = groupData.FirstOrDefault();

            //Set the comparator Id if this is a multiple comparator grouping record
            if (groupData.Count() > 1)
            {
                //There are multiple comparator indicators
                if (model.Grouping != null)
                {
                    model.Grouping.ComparatorId = ComparatorIds.NationalAndSubnational;
                }
            }

            model.urlKey = urlKey;

            var listOfProfiles = CommonUtilities.GetOrderedListOfProfilesForCurrentUser(urlKey);

            ViewBag.listOfProfiles = listOfProfiles;

            var domains = new ProfileMembers();

            var defaultProfile = listOfProfiles.FirstOrDefault(x => x.Selected) ?? listOfProfiles.FirstOrDefault();

            if (defaultProfile != null)
            {
                defaultProfile.Selected = true;
            }

            ViewBag.listOfDomains = CommonUtilities.GetOrderedListOfDomainsWithGroupId(domains, defaultProfile, _profileRepository);

            IEnumerable <UserGroupPermissions> userPermissions =
                CommonUtilities.GetUserGroupPermissionsByUserId(_reader.GetUserByUserName(_userName).Id);

            model.UserGroupPermissions =
                userPermissions.FirstOrDefault(x => x.ProfileId == _reader.GetProfileDetails(model.UrlKey).Id);

            if (HttpContext.Request.UrlReferrer != null)
            {
                model.ReturnUrl = HttpContext.Request.UrlReferrer.ToString();
            }

            ViewBag.SexId = new SelectList(_lookUpsRepository.GetSexes(), "SexID", "Description");

            ViewBag.AgeId = new SelectList(_lookUpsRepository.GetAges(), "AgeID", "Description");

            ViewBag.YearTypeId = new SelectList(_lookUpsRepository.GetYearTypes(), "Id", "Label");

            ViewBag.ValueTypeId = new SelectList(_lookUpsRepository.GetIndicatorValueTypes(), "Id", "Label");

            ViewBag.CIMethodId = new SelectList(_lookUpsRepository.GetConfidenceIntervalMethods(), "Id", "Name");

            var unitList = new SelectList(_lookUpsRepository.GetUnits(), "Id", "Label");

            ViewBag.UnitId = unitList;

            ViewBag.DenominatorTypeId = new SelectList(_lookUpsRepository.GetDenominatorTypes(), "Id", "Name");

            return(View("IndicatorEdit", model));
        }