public ActionResult Index(int profileId = -1 /*this is currently ignored but one for the future*/)
        {
            var model = new IndicatorGridModel
            {
                SortBy           = "Sequence",
                SortAscending    = true,
                CurrentPageIndex = 1,
                PageSize         = 200
            };

            GetProfiles(model);
            GetDomains(model, null);

            Profile profile        = null;
            var     firstOrDefault = model.DomainList.FirstOrDefault();

            if (firstOrDefault != null)
            {
                profile = GetProfile(model.ProfileKey, Convert.ToInt32(firstOrDefault.Value), -1);
            }

            if (profile != null)
            {
                IQueryable <GroupingPlusName> indicators = profile.IndicatorNames.AsQueryable();

                model.Profile = profile;
                model.UrlKey  = model.ProfileKey;

                var profileContact = _reader.GetUserByUserId(profile.ContactUserId);
                model.ContactUserName = profileContact.DisplayName;
                model.EmailAddress    = profileContact.EmailAddress;

                AssignAreaTypeData(model, profile);

                var userPermissions = GetUserGroupPermissions();

                model.UserHasAssignedPermissions = userPermissions.Any();

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

                indicators = indicators.Where(i => i.AreaTypeId == profile.SelectedAreaType);

                model.TotalRecordCount = indicators.Count();

                model.IndicatorNamesGrid = indicators
                                           .Distinct()
                                           .OrderBy(model.SortExpression)
                                           .Skip((model.CurrentPageIndex - 1) * model.PageSize)
                                           .Take(model.PageSize);
            }

            return(View(ProfilesAndIndicators, model));
        }
        private int SaveUserMTVChanges(string selectedProfileId, string selectedDomain, int selectedAreaType,
                                       int selectedSex, int selectedAge, int selectedComparator, int selectedComparatorMethod,
                                       double selectedComparatorConfidence, int selectedYearType, int selectedYearRange, int selectedValueType,
                                       int selectedCiMethodType, double selectedCiConfidenceLevel, int selectedPolarityType, int selectedUnitType,
                                       int selectedDenominatorType, string userMTVChanges, int startYear, int endYear,
                                       int startQuarterRange, int endQuarterRange, int startMonthRange, int endMonthRange, int?selectedDecimalPlaces, int?selectedTargetId)
        {
            var properties = _reader.GetIndicatorMetadataTextProperties();

            var nextIndicatorId = _profileRepository.GetNextIndicatorId() + 1;

            if (string.IsNullOrWhiteSpace(userMTVChanges) == false)
            {
                CommonUtilities.CreateNewIndicatorTextValues(selectedDomain, userMTVChanges, properties, nextIndicatorId, _userName, _profileRepository);

                _profileRepository.CreateGroupingAndMetaData(_reader.GetProfileDetails(selectedProfileId).Id, Convert.ToInt32(selectedDomain),
                                                             nextIndicatorId, selectedAreaType, selectedSex, selectedAge, selectedComparator, selectedComparatorMethod,
                                                             selectedComparatorConfidence, selectedYearType, selectedYearRange, selectedValueType, selectedCiMethodType,
                                                             selectedCiConfidenceLevel, selectedPolarityType, selectedUnitType, selectedDenominatorType, startYear, endYear,
                                                             startQuarterRange, endQuarterRange, startMonthRange, endMonthRange, selectedDecimalPlaces,
                                                             selectedTargetId);
            }

            return(nextIndicatorId);
        }
示例#3
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));
        }