Beispiel #1
0
        public void GetChildTaxonRelation_InRevision()
        {
            // Arrange
            ITaxon taxon = CoreData.TaxonManager.GetTaxon(GetRevisionUserContext(), 3000303);

            // Act
            IList <ITaxonRelation> t = taxon.GetChildTaxonRelations(GetRevisionUserContext(), true, false, true);

            // Assert
            Assert.IsTrue(t.Count == 3);
            foreach (var taxonRelation in t)
            {
                Assert.IsFalse(taxonRelation.ReplacedInTaxonRevisionEventId.HasValue);
            }
        }
        /// <summary>
        /// Creates a view model for Taxon Move Change names
        /// </summary>
        /// <param name="oldParentTaxonId"></param>
        /// <param name="newParentTaxonId"></param>
        /// <param name="selectedChildTaxaToMove"></param>
        /// <returns></returns>
        public TaxonMoveChangeNameViewModel CreateTaxonMoveChangeNameViewModel(int oldParentTaxonId, int newParentTaxonId, List <int> selectedChildTaxaToMove)
        {
            TaxonMoveChangeNameViewModel model = new TaxonMoveChangeNameViewModel();

            var newParentTaxon = CoreData.TaxonManager.GetTaxon(_user, newParentTaxonId);
            var oldParentTaxon = CoreData.TaxonManager.GetTaxon(_user, oldParentTaxonId);

            model.SelectedChildTaxaToMove = selectedChildTaxaToMove;

            // MovedChildTaxons
            var dicItems = new Dictionary <ITaxon, List <ChangeNameItem> >();

            model.MovedChildTaxons = new List <ChangeNameItem>();
            foreach (int taxonId in selectedChildTaxaToMove)
            {
                ITaxon taxon = CoreData.TaxonManager.GetTaxon(_user, taxonId);
                dicItems.Add(taxon, new List <ChangeNameItem>());
                ChangeNameItem parentItem = ChangeNameItem.CreateChangeNameItem(taxon, taxon, oldParentTaxon, newParentTaxon, _user);
                model.MovedChildTaxons.Add(parentItem);
                dicItems[taxon].Add(parentItem);
                foreach (var taxonRelation in taxon.GetChildTaxonRelations(_user, true, false))
                {
                    ChangeNameItem item = ChangeNameItem.CreateChangeNameItem(taxonRelation.ChildTaxon, taxon, oldParentTaxon, newParentTaxon, _user);
                    model.MovedChildTaxons.Add(item);
                    dicItems[taxon].Add(item);
                }
            }

            model.NewParentTaxonId = newParentTaxon.Id;
            model.OldParentTaxonId = oldParentTaxon.Id;
            // end constructor

            model.TaxonId = oldParentTaxon.Id;
            model.OldParentDescription   = oldParentTaxon.ScientificName;
            model.NewParentDescription   = newParentTaxon.ScientificName;
            model.MovedTaxonsDescription = dicItems.Keys.Select(taxon => taxon.ScientificName).ToList();

            return(model);
        }