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)); }