Пример #1
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));
        }