public ActionResult CopyIndicators(IEnumerable <string> jdata, string selectedProfileUrlkey, string selectedProfileName, int selectedDomainId, string selectedDomainName, int selectedAreaTypeId)
        {
            var model = new CopyIndicatorsModel
            {
                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);
            model.GroupId       = Convert.ToInt32(model.ListOfDomains.FirstOrDefault(x => x.Selected).Value);

            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("_CopySelectedIndicators", model));
            }

            return(View("ProfilesAndIndicators"));
        }
예제 #2
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));
        }
        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));
        }