/// <summary> /// Remove old source reference for taxon. /// </summary> /// <param name="taxonRevision"></param> /// <param name="replacingTaxon"></param> /// <returns></returns> public static ReferenceRelationList RemoveTaxonSourceReferences(IUserContext userContext, ITaxonRevision taxonRevision, ITaxon replacingTaxon) { // Must remove old source reference though ReferenceRelationList referencesToRemove = new ReferenceRelationList(); foreach (IReferenceRelation oldReferenceRelation in replacingTaxon.GetReferenceRelations(userContext)) { if (oldReferenceRelation.Type.Id == (int)ReferenceRelationTypeId.Source) { referencesToRemove.Add(oldReferenceRelation); } } return(referencesToRemove); }
/// <summary> /// Creates view model for Editing factor data ie EditFactorItem.ascx /// </summary> /// <param name="user"></param> /// <param name="taxon"></param> /// <param name="factorData"></param> /// <param name="factorDataType"></param> /// <param name="model"></param> /// <returns></returns> public FactorViewModel CreateFactorViewData(IUserContext user, ITaxon taxon, DyntaxaSpeciesFact factorData, int factorDataType, int dataTypeId, FactorViewModel model, IList <DyntaxaIndividualCategory> allIndividualCategories, string referenceId, bool isHost) { model.FactorDataTypeId = factorDataType; model.DataTypeId = dataTypeId; model.FactorName = factorData.Label; if (isHost) { model.FactorName = factorData.HostName; } model.IndividualCategoryName = factorData.IndividualCatgory.Label; model.QualityId = factorData.Quality.QualityId; model.QualityValueList = new List <SpeciesFactDropDownModelHelper>(); foreach (KeyValuePair <int, string> quality in factorData.Quality.Qualities) { model.QualityValueList.Add(new SpeciesFactDropDownModelHelper(quality.Key, quality.Value)); } model.FactorFieldComment = factorData.Comments; model.FactorFieldEnumLabel = factorData.FactorEnumLabel; model.FactorFieldEnumValueList = new List <SpeciesFactDropDownModelHelper>(); foreach (KeyValuePair <int, string> factorFieldEnum in factorData.FactorEnumValueList) { // Only add 0 and positiv values for Substrate and Biotope. if ((factorFieldEnum.Key >= 0 && factorDataType == (int)DyntaxaFactorDataType.AF_BIOTOPE) || (factorFieldEnum.Key >= 0 && factorDataType == (int)DyntaxaFactorDataType.AF_SUBSTRATE) || factorDataType == (int)DyntaxaFactorDataType.AF_INFLUENCE) { model.FactorFieldEnumValueList.Add(new SpeciesFactDropDownModelHelper(factorFieldEnum.Key, factorFieldEnum.Value)); } } model.FactorFieldEnumValue = factorData.FactorEnumValue; model.FactorFieldEnumValueList2 = new List <SpeciesFactDropDownModelHelper>(); foreach (KeyValuePair <int, string> factorFieldEnum2 in factorData.FactorEnumValueList2) { // Only add 0 and positiv values for Substrate and Biotope. if (factorDataType == (int)DyntaxaFactorDataType.AF_SUBSTRATE || factorDataType == (int)DyntaxaFactorDataType.AF_INFLUENCE) { model.FactorFieldEnumValueList2.Add(new SpeciesFactDropDownModelHelper(factorFieldEnum2.Key, factorFieldEnum2.Value)); } } model.FactorFieldEnumValueList2.Add(new SpeciesFactDropDownModelHelper(SpeciesFactModelManager.SpeciesFactNoValueSet, DyntaxaResource.SpeciesFactNoValueSet)); model.FactorFieldEnumValue2 = factorData.FactorEnumValue2; model.FactorFieldEnumLabel2 = factorData.FactorEnumLabel2; model.FaktorReferenceList = new List <SpeciesFactDropDownModelHelper>(); bool isReferenceSet = false; int dyntaxaReferenceId = 0; int userReferenceId = 0; if (referenceId.IsNotEmpty()) { isReferenceSet = true; var referenceList = ReferenceHelper.GetReferenceList(user); foreach (IReference reference in referenceList) { if (reference.Id == Convert.ToInt32(referenceId)) { model.FaktorReferenceList.Add(new SpeciesFactDropDownModelHelper(reference.Id, reference.Name + " " + reference.Year)); userReferenceId = reference.Id; model.FactorReferenceId = reference.Id; } } if (factorData.ReferenceName.IsNotEmpty()) { model.FactorReferenceOld = factorData.ReferenceName; } else { model.FactorReferenceOld = "-"; } } if (factorData.DyntaxaFactorReference.IsNotNull()) { if (!isReferenceSet) { isReferenceSet = true; model.FactorReferenceId = factorData.DyntaxaFactorReference.GetReference(user).Id; } dyntaxaReferenceId = factorData.DyntaxaFactorReference.GetReference(user).Id; IReference reference = factorData.DyntaxaFactorReference.GetReference(user); Int32 year = reference.Year.HasValue ? reference.Year.Value : -1; model.FaktorReferenceList.Add(new SpeciesFactDropDownModelHelper(reference.Id, reference.Name + " " + year)); } // Here we get the dyntaxa references... foreach (IReferenceRelation referenceRelation in taxon.GetReferenceRelations(user)) { IReference reference = referenceRelation.GetReference(user); Int32 year = reference.Year.HasValue ? reference.Year.Value : -1; if (reference.Id != dyntaxaReferenceId && reference.Id != userReferenceId) { model.FaktorReferenceList.Add( new SpeciesFactDropDownModelHelper( reference.Id, reference.Name + " " + year)); } if (!isReferenceSet) { isReferenceSet = true; model.FactorReferenceId = reference.Id; } } model.IndividualCategoryId = factorData.IndividualCatgory.Id; model.IndividualCategoryName = factorData.IndividualCatgory.Label; model.IndividualCategoryList = new List <SpeciesFactDropDownModelHelper>(); // Add all individual categories that exist List <DyntaxaIndividualCategory> exitingCategories = factorData.IndividualCategoryList as List <DyntaxaIndividualCategory>; foreach (DyntaxaIndividualCategory category in allIndividualCategories) { model.IndividualCategoryList.Add(new SpeciesFactDropDownModelHelper(category.Id, category.Label)); } model.ExistingEvaluations = factorData.ExistingEvaluations; string message = Resources.DyntaxaResource.SpeciesFactLatestUpdateByText.Replace("[UpdateDate]", factorData.UpdateDate.ToShortDateString()); message = message.Replace("[UpdateUserFullName]", factorData.UpdateUserFullName); model.UpdateUserData = message; return(model); }