public ActionResult SaveReorderedIndicators(FormCollection fc, int?currentDomainId, string indicatorOrder)
        {
            if (currentDomainId.HasValue)
            {
                var indicatorSpecifierStrings = indicatorOrder.Split('¬').ToList();
                indicatorSpecifierStrings.RemoveAt(indicatorSpecifierStrings.Count - 1);
                var sequenceNumber = 1;

                var areaTypeId = Convert.ToInt32(fc["AreaType"]);

                var indicatorSpecifiers = IndicatorSpecifierParser.Parse(indicatorSpecifierStrings);
                foreach (var indicatorSpecifier in indicatorSpecifiers)
                {
                    var groupings = _reader.GetGroupingsByGroupIdAreaTypeIdIndicatorIdAndSexId(currentDomainId.Value,
                                                                                               areaTypeId, indicatorSpecifier.IndicatorId, indicatorSpecifier.SexId);

                    foreach (var grouping in groupings)
                    {
                        grouping.Sequence = sequenceNumber;
                    }

                    _writer.UpdateGroupingList(groupings);

                    sequenceNumber++;
                }
            }

            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }

            return(View("ProfilesAndIndicators"));
        }
        public ActionResult ConfirmMoveIndicators(MoveIndicatorsModel mim, string selectedProfileId,
                                                  List <int> selectedDomainId, int selectedAreaTypeId, string indicatorTransferDetails)
        {
            var groupId    = GetSelectedGroupIdUsingProfileKeyDomainAndAreaTypeId(mim.UrlKey, mim.DomainId, mim.AreaTypeId);
            var modelCount = 0;

            //There are indicators to delete (move to the archive domain)
            var indicatorSpecifierStrings = indicatorTransferDetails.Split(',').ToList();
            var indicatorSpecifiers       = IndicatorSpecifierParser.Parse(indicatorSpecifierStrings);

            foreach (var indicatorSpecifier in indicatorSpecifiers)
            {
                var indicatorId = indicatorSpecifier.IndicatorId;
                var sexId       = indicatorSpecifier.SexId;
                var ageId       = indicatorSpecifier.AgeId;

                //Don't move if identical indicator already exists in destination.
                if (!_profileRepository.IndicatorGroupingsExist(indicatorId,
                                                                Convert.ToInt32(selectedDomainId[0]), mim.AreaTypeId, ageId,
                                                                sexId))
                {
                    var currentIndicator = mim.IndicatorsToTransfer[modelCount];

                    _profileRepository.MoveIndicatorToDomain(indicatorId, groupId, mim.AreaTypeId,
                                                             currentIndicator.SexId, currentIndicator.AgeId,
                                                             selectedDomainId[0], selectedAreaTypeId, sexId, ageId);

                    _profileRepository.LogAuditChange("Indicator " + indicatorId + " moved from [" + mim.DomainName +
                                                      " (Area: " + mim.AreaTypeId + ", SexId:" + currentIndicator.SexId +
                                                      ", AgeId:" + currentIndicator.AgeId + " )] Into [" +
                                                      _reader.GetGroupingMetadataList(selectedDomainId)[0].GroupName +
                                                      " (Area: " + selectedAreaTypeId + ", SexId:" + sexId + ", AgeId:" + ageId + " )]",
                                                      indicatorId, null, _userName, DateTime.Now, CommonUtilities.AuditType.Move.ToString());

                    var indicatorMetadata = _reader.GetIndicatorMetadata(indicatorId);
                    if (indicatorMetadata.OwnerProfileId == mim.Profile.Id)
                    {
                        // Indicator is being moved out of owner profile so owner must change
                        var newOwnerProfileId = _reader.GetProfileDetails(selectedProfileId).Id;
                        new IndicatorOwnerChanger(_reader, _profileRepository)
                        .AssignIndicatorToProfile(indicatorId, newOwnerProfileId);
                    }
                }
                modelCount++;
            }

            _profileRepository.Dispose();

            _writer.ReorderIndicatorSequence(groupId, mim.AreaTypeId);

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
        public ActionResult MoveIndicators(IEnumerable <string> jdata, string selectedProfileUrlkey, string selectedProfileName,
                                           int selectedDomainId, string selectedDomainName, int selectedAreaTypeId)
        {
            var model = new MoveIndicatorsModel
            {
                UrlKey      = selectedProfileUrlkey,
                Profile     = GetProfile(selectedProfileUrlkey, selectedDomainId, selectedAreaTypeId),
                DomainName  = selectedDomainName,
                DomainId    = selectedDomainId,
                ProfileName = selectedProfileName,
                AreaTypeId  = selectedAreaTypeId,
                IndicatorsThatCantBeTransferred = null,
            };

            var listOfProfiles = GetOrderedListOfProfilesForCurrentUser(model);

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

            defaultProfile.Selected = true;

            model.ListOfDomains = CommonUtilities.GetOrderedListOfDomainsWithGroupId(domains, defaultProfile, _profileRepository);

            var userPermissions = CommonUtilities.GetUserGroupPermissionsByUserId(_reader.GetUserByUserName(_userName).Id);

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

            var indicatorSpecifiers = IndicatorSpecifierParser.Parse(jdata.ToArray());

            model.IndicatorsToTransfer = GetSpecifiedIndicatorNames(indicatorSpecifiers,
                                                                    model.Profile.IndicatorNames);

            ViewBag.SexList = _lookUpsRepository.GetSexes();

            ViewBag.AgeList = _lookUpsRepository.GetAges();


            if (Request.IsAjaxRequest())
            {
                return(PartialView("_MoveSelectedIndicators", model));
            }

            return(View("ProfilesAndIndicators"));
        }
Пример #4
0
        public ActionResult ConfirmCopyIndicators(CopyIndicatorsModel cim, List <int> selectedDomainId,
                                                  int selectedAreaTypeId, string indicatorTransferDetails)
        {
            var groupId    = GetSelectedGroupIdUsingProfileKeyDomainAndAreaTypeId(cim.UrlKey, cim.DomainId, cim.AreaTypeId);
            var modelCount = 0;

            var indicatorSpecifierStrings = indicatorTransferDetails.Split(',').ToList();
            var indicatorSpecifiers       = IndicatorSpecifierParser.Parse(indicatorSpecifierStrings);

            foreach (var indicatorSpecifier in indicatorSpecifiers)
            {
                var indicatorId = indicatorSpecifier.IndicatorId;
                var sexId       = indicatorSpecifier.SexId;
                var ageId       = indicatorSpecifier.AgeId;

                // Don't copy if identical indicator (including age and sex Id) already exists in destination.
                if (!_dataAccess.IndicatorGroupingsExist(indicatorId, Convert.ToInt32(selectedDomainId[0]),
                                                         selectedAreaTypeId, Convert.ToInt32(ageId), Convert.ToInt32(sexId)))
                {
                    var currentIndicator = cim.IndicatorsToTransfer[modelCount];

                    _dataAccess.CopyIndicatorToDomain(indicatorId, groupId, cim.AreaTypeId,
                                                      currentIndicator.SexId, currentIndicator.AgeId,
                                                      Convert.ToInt32(selectedDomainId[0]), selectedAreaTypeId, sexId,
                                                      ageId);

                    _dataAccess.LogAuditChange("Indicator " + indicatorId + " copied from [" +
                                               cim.DomainName + " (Area: " + cim.AreaTypeId + ", SexId:" + currentIndicator.SexId +
                                               ", AgeId:" + currentIndicator.AgeId + " )] Into " +
                                               "[" + _reader.GetGroupingMetadataList(selectedDomainId)[0].GroupName +
                                               " (Area: " + selectedAreaTypeId + ", SexId:" + sexId + ", AgeId:" + ageId + " )]",
                                               indicatorId, null, _userName, DateTime.Now, CommonUtilities.AuditType.Copy.ToString());
                }
                modelCount++;
            }

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
Пример #5
0
        public ActionResult SaveReorderedIndicators(FormCollection fc, int?currentDomainId, string indicatorOrder)
        {
            var indicatorSpecifierStrings = indicatorOrder.Split('¬').ToList();

            indicatorSpecifierStrings.RemoveAt(indicatorSpecifierStrings.Count - 1);
            var sequenceNumber = 1;

            var indicatorSpecifiers = IndicatorSpecifierParser.Parse(indicatorSpecifierStrings);

            foreach (var indicatorSpecifier in indicatorSpecifiers)
            {
                _dataAccess.UpdateIndicatorGroupingSequence(indicatorSpecifier.IndicatorId, sequenceNumber,
                                                            currentDomainId, Convert.ToInt32(fc["AreaType"]), indicatorSpecifier.SexId);
                sequenceNumber++;
            }

            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }

            return(View("ProfilesAndIndicators"));
        }
        public ActionResult ConfirmDeleteIndicators(DeleteIndicatorsModel indicatorsModel, string indicatorDeleteDetails)
        {
            if (indicatorDeleteDetails != string.Empty)
            {
                var areaTypeId = indicatorsModel.SelectedAreaTypeId;
                var groupId    = GetSelectedGroupIdUsingProfileKeyDomainAndAreaTypeId(
                    indicatorsModel.UrlKey, indicatorsModel.DomainId, areaTypeId);

                var indicatorSpecifierStrings = indicatorDeleteDetails.Split(',').ToList();
                var indicatorSpecifiers       = IndicatorSpecifierParser.Parse(indicatorSpecifierStrings);

                foreach (var indicatorSpecifier in indicatorSpecifiers)
                {
                    var indicatorId = indicatorSpecifier.IndicatorId;
                    var sexId       = indicatorSpecifier.SexId;
                    var ageId       = indicatorSpecifier.AgeId;
                    var profileId   = indicatorsModel.Profile.Id;

                    var indicatorMetadata = _reader.GetIndicatorMetadata(indicatorId);

                    if (indicatorMetadata.OwnerProfileId == profileId)
                    {
                        // Indicator owned by profile

                        var groupings = GetGroupingsForIndicatorInProfile(profileId, indicatorId);

                        var distinctGroupingsForProfile =
                            GetDistinctGroupingsByGroupIdAndAreaTypeId(groupings);

                        if (distinctGroupingsForProfile.Count > 1)
                        {
                            //This isn't the last occurance of this indicator in this profile so it doesn't need to be archived and can simply be deleted from the grouping table
                            DeleteFromGrouping(groupId, indicatorId, areaTypeId, sexId, ageId);
                        }
                        else
                        {
                            //Indicator is owned by the profile so archive it
                            _profileRepository.ArchiveIndicatorFromGrouping(groupId, indicatorId,
                                                                            areaTypeId, sexId, ageId);

                            //Set the indicator ownership to the archive profile
                            new IndicatorOwnerChanger(_reader, _profileRepository)
                            .AssignIndicatorToProfile(indicatorId, ProfileIds.ArchivedIndicators);

                            _profileRepository.LogAuditChange("Indicator " + indicatorId +
                                                              " (Area: " + areaTypeId + ", SexId:" + sexId +
                                                              ", AgeId:" + ageId + " )  has been archived.",
                                                              indicatorId, null, _userName, DateTime.Now,
                                                              CommonUtilities.AuditType.Delete.ToString());
                        }
                    }
                    else
                    {
                        // Indicator not owned by profile
                        DeleteFromGrouping(groupId, indicatorId, areaTypeId, sexId, ageId);
                    }
                }

                _profileRepository.Dispose();

                _writer.ReorderIndicatorSequence(groupId, areaTypeId);
            }

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
        public ActionResult ConfirmCopyIndicators(CopyIndicatorsModel cim, List <int> selectedDomainId,
                                                  int selectedAreaTypeId, string indicatorTransferDetails, bool copyMetadataOption, string targetProfile)
        {
            var groupId    = GetSelectedGroupIdUsingProfileKeyDomainAndAreaTypeId(cim.UrlKey, cim.DomainId, cim.AreaTypeId);
            var modelCount = 0;

            var indicatorSpecifierStrings = indicatorTransferDetails.Split(',').ToList();
            var indicatorSpecifiers       = IndicatorSpecifierParser.Parse(indicatorSpecifierStrings);


            string targetProfileId = string.Empty;
            int    targetDomain = 0, targetAreaTypeId = 0;

            if (copyMetadataOption)
            {
                var targetProfileData = targetProfile.Split('~');
                targetProfileId  = targetProfileData[0];
                targetDomain     = Convert.ToInt32(targetProfileData[1]);
                targetAreaTypeId = Convert.ToInt32(targetProfileData[2]);
            }

            foreach (var indicatorSpecifier in indicatorSpecifiers)
            {
                var indicatorId = indicatorSpecifier.IndicatorId;
                var sexId       = indicatorSpecifier.SexId;
                var ageId       = indicatorSpecifier.AgeId;

                // Don't copy if identical indicator (including age and sex Id) already exists in destination.
                if (!_profileRepository.IndicatorGroupingsExist(indicatorId, Convert.ToInt32(selectedDomainId[0]),
                                                                selectedAreaTypeId, Convert.ToInt32(ageId), Convert.ToInt32(sexId)))
                {
                    var currentIndicator = cim.IndicatorsToTransfer[modelCount];

                    _profileRepository.CopyIndicatorToDomain(indicatorId, groupId, cim.AreaTypeId,
                                                             currentIndicator.SexId, currentIndicator.AgeId,
                                                             Convert.ToInt32(selectedDomainId[0]), selectedAreaTypeId, sexId,
                                                             ageId);

                    // Copy indicator meta data
                    if (copyMetadataOption)
                    {
                        var targetProfileDetails       = CommonUtilities.GetProfile(targetProfileId, targetDomain, targetAreaTypeId, _profileRepository);
                        var indicatorMetadataTextValue = _reader.GetMetadataTextValueForAnIndicatorById(indicatorId, cim.Profile.Id);
                        if (indicatorMetadataTextValue != null)
                        {
                            var indicatorMetadataTextValuesCopy = new IndicatorMetadataTextValue
                            {
                                IndicatorId     = indicatorId,
                                ProfileId       = targetProfileDetails.Id,
                                Name            = indicatorMetadataTextValue.Name,
                                NameLong        = indicatorMetadataTextValue.NameLong,
                                Definition      = indicatorMetadataTextValue.Definition,
                                Rationale       = indicatorMetadataTextValue.Rationale,
                                Policy          = indicatorMetadataTextValue.Policy,
                                DataSource      = indicatorMetadataTextValue.DataSource,
                                Producer        = indicatorMetadataTextValue.Producer,
                                IndMethod       = indicatorMetadataTextValue.IndMethod,
                                StandardPop     = indicatorMetadataTextValue.StandardPop,
                                CIMethod        = indicatorMetadataTextValue.CIMethod,
                                CountSource     = indicatorMetadataTextValue.CountSource,
                                CountDefinition = indicatorMetadataTextValue.CountDefinition,
                                DenomSource     = indicatorMetadataTextValue.DenomSource,
                                DenomDefinition = indicatorMetadataTextValue.DenomDefinition,
                                DiscControl     = indicatorMetadataTextValue.DiscControl,
                                Caveats         = indicatorMetadataTextValue.Caveats,
                                Copyright       = indicatorMetadataTextValue.Copyright,
                                Reuse           = indicatorMetadataTextValue.Reuse,
                                Links           = indicatorMetadataTextValue.Links,
                                RefNum          = indicatorMetadataTextValue.RefNum,
                                Notes           = indicatorMetadataTextValue.Notes,
                                Frequency       = indicatorMetadataTextValue.Frequency,
                                Rounding        = indicatorMetadataTextValue.Rounding,
                                DataQuality     = indicatorMetadataTextValue.DataQuality
                            };

                            _writer.NewIndicatorMetadataTextValue(indicatorMetadataTextValuesCopy);
                        }
                    }

                    _profileRepository.LogAuditChange("Indicator " + indicatorId + " copied from [" +
                                                      cim.DomainName + " (Area: " + cim.AreaTypeId + ", SexId:" + currentIndicator.SexId +
                                                      ", AgeId:" + currentIndicator.AgeId + " )] Into " +
                                                      "[" + _reader.GetGroupingMetadataList(selectedDomainId)[0].GroupName +
                                                      " (Area: " + selectedAreaTypeId + ", SexId:" + sexId + ", AgeId:" + ageId + " )]",
                                                      indicatorId, null, _userName, DateTime.Now, CommonUtilities.AuditType.Copy.ToString());
                }
                modelCount++;
            }

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
        /// <summary>
        /// Remove indicators from a profile
        /// </summary>
        public ActionResult DeleteIndicators(IEnumerable <string> jdata, string selectedProfileUrlkey,
                                             string selectedProfileName, int selectedDomainId, string selectedDomainName, int selectedAreaTypeId)
        {
            var model = new DeleteIndicatorsModel
            {
                UrlKey                      = selectedProfileUrlkey,
                Profile                     = GetProfile(selectedProfileUrlkey, selectedDomainId, selectedAreaTypeId),
                DomainName                  = selectedDomainName,
                DomainId                    = selectedDomainId,
                ProfileName                 = selectedProfileName,
                SelectedAreaTypeId          = selectedAreaTypeId,
                IndicatorsThatCantBeRemoved = null,
            };

            var userPermissions = CommonUtilities.GetUserGroupPermissionsByUserId(_reader.GetUserByUserName(_userName).Id);

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

            var indicatorSpecifiers = IndicatorSpecifierParser.Parse(jdata.ToArray());
            var indicatorList       = GetSpecifiedIndicatorNames(indicatorSpecifiers, model.Profile.IndicatorNames);

            var cannotRemove = new List <GroupingPlusName>();
            var canRemove    = new List <GroupingPlusName>();

            foreach (var indicator in indicatorList)
            {
                model.IndicatorMetadata = new IndicatorMetadata {
                    OwnerProfileId = _reader.GetIndicatorMetadata(indicator.IndicatorId).OwnerProfileId
                };

                //check to see if the indicator is being used in more than one domain
                var indicatorGrouping = _reader.DoesIndicatorExistInMoreThanOneGroup(indicator.IndicatorId, indicator.AgeId, indicator.SexId);

                if (indicatorGrouping.GroupBy(x => x.GroupId).Count() > 1)
                {
                    if (model.DoesProfileOwnIndicator())
                    {
                        //If the profile owns the indicator, check to see if this is the last occurance within this profile that is being deleted
                        var groupIds        = _reader.GetGroupingIds(model.Profile.Id);
                        var indicatorGroups = _reader.GetGroupingByIndicatorId(new List <int> {
                            indicator.IndicatorId
                        });

                        var uniqueIndicatorGroups = new List <Grouping>();
                        foreach (Grouping @group in indicatorGroups.Where(group => groupIds.Contains(@group.GroupId)).Where(@group => uniqueIndicatorGroups.All(x => x.AreaTypeId != @group.AreaTypeId)))
                        {
                            uniqueIndicatorGroups.Add(@group);
                        }

                        var lastIndicatorOccuranceInProfile = uniqueIndicatorGroups.Count == 1;

                        if (!lastIndicatorOccuranceInProfile)
                        {
                            canRemove.Add(indicator);
                        }
                        else
                        {
                            cannotRemove.Add(indicator);
                        }
                    }
                    else
                    {
                        //Indicator Can Be Deleted because it is being used elsewhere and we ARE NOT trying to delete the owner
                        canRemove.Add(indicator);
                    }
                }
                else
                {
                    //Indicator Can Be Deleted because it is NOT being used elsewhere
                    canRemove.Add(indicator);
                }
            }

            model.IndicatorsThatCantBeRemoved = cannotRemove;
            model.IndicatorsToDelete          = canRemove;

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_DeleteSelectedIndicators", model));
            }

            return(View("ProfilesAndIndicators"));
        }
Пример #9
0
        public ActionResult ConfirmDeleteIndicators(DeleteIndicatorsModel dim, string indicatorDeleteDetails)
        {
            if (indicatorDeleteDetails != string.Empty)
            {
                var areaTypeId = dim.SelectedAreaTypeId;
                var groupId    = GetSelectedGroupIdUsingProfileKeyDomainAndAreaTypeId(dim.UrlKey, dim.DomainId, areaTypeId);

                var indicatorSpecifierStrings = indicatorDeleteDetails.Split(',').ToList();
                var indicatorSpecifiers       = IndicatorSpecifierParser.Parse(indicatorSpecifierStrings);

                foreach (var indicatorSpecifier in indicatorSpecifiers)
                {
                    var indicatorId = indicatorSpecifier.IndicatorId;
                    var sexId       = indicatorSpecifier.SexId;
                    var ageId       = indicatorSpecifier.AgeId;

                    var indicatorMetadata = _reader.GetIndicatorMetadata(indicatorId);

                    if (indicatorMetadata.OwnerProfileId == dim.Profile.Id)
                    {
                        //If the profile owns the indicator, check to see if this is the last occurance within this profile that is being deleted
                        var groupIds      = _reader.GetProfileDetailsByProfileId(dim.Profile.Id).GroupIds;
                        var indicatorList = _reader.GetGroupingByIndicatorId(new List <int> {
                            indicatorId
                        });

                        var indicatorGroups = new List <Grouping>();
                        foreach (Grouping @group in indicatorList.Where(group => groupIds.Contains(@group.GroupId)).Where(@group => indicatorGroups.All(x => x.AreaTypeId != @group.AreaTypeId)))
                        {
                            indicatorGroups.Add(@group);
                        }

                        var lastIndicatorOccuranceInProfile = indicatorGroups.Count == 1;

                        if (!lastIndicatorOccuranceInProfile)
                        {
                            //This isn't the last occurance of this indicator in this profile so it doesn't need to be archived and can simply be deleted from the grouping table
                            DeleteFromGrouping(groupId, indicatorId, areaTypeId, sexId, ageId);
                        }
                        else
                        {
                            //Indicator is owned by the profile so archive it
                            _dataAccess.ArchiveIndicatorFromGrouping(groupId, indicatorId,
                                                                     areaTypeId, sexId, ageId);

                            //Set the indicator ownership to the archive profile
                            _dataAccess.UpdateIndicatorOwnership(CommonUtilities.ArchiveProfileId,
                                                                 indicatorId);

                            _dataAccess.LogAuditChange("Indicator " + indicatorId +
                                                       " (Area: " + areaTypeId + ", SexId:" + sexId +
                                                       ", AgeId:" + ageId + " )  has been archived.",
                                                       indicatorId, null, _userName, DateTime.Now,
                                                       CommonUtilities.AuditType.Delete.ToString());
                        }
                    }
                    else
                    {
                        DeleteFromGrouping(groupId, indicatorId, areaTypeId, sexId, ageId);
                    }
                }

                _writer.ResetSequences(groupId, areaTypeId);
            }

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }