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