/// <summary>
 /// Create a new TaxonSpeciesFactViewModel, from a taxon.
 /// </summary>
 /// <param name="user">The user context.</param>
 /// <param name="taxon">The taxon.</param>
 public TaxonSpeciesFactViewModel(IUserContext user, ITaxon taxon)
 {
     Author         = taxon.Author ?? string.Empty;
     CommonName     = taxon.GetCommonName(user).IsNotNull() ? taxon.GetCommonName(user).Name : string.Empty;
     ParentTaxa     = GetParentTaxa(user, taxon);
     ScientificName = taxon.GetScientificName(user).IsNotNull() ? taxon.GetScientificName(user).Name : string.Empty;
     TaxonId        = taxon.Id;
     Category       = taxon.Category.Name;
     //Synonyms = taxon.GetSynonymsViewModel(user);
     RedListCategoryTaxa = new Dictionary <RedListCategory, List <int> >();
 }
        /// <summary>
        /// Save name changes to db
        /// </summary>
        /// <param name="nameItems"></param>
        /// <param name="taxonRevision"></param>
        public void SaveNameChanges(List <ChangeNameItem> nameItems, ITaxonRevision taxonRevision)
        {
            IUserContext userContext = CoreData.UserManager.GetCurrentUser();

            var taxa = new Dictionary <int, ITaxon>();
            //var dic = new Dictionary<ITaxon, IList<ITaxonName>>();
            TaxonNameList taxonNames = new TaxonNameList();

            foreach (ChangeNameItem changeNameItem in nameItems)
            {
                if (!taxa.ContainsKey(changeNameItem.TaxonId))
                {
                    taxa.Add(changeNameItem.TaxonId, CoreData.TaxonManager.GetTaxon(userContext, changeNameItem.TaxonId));
                }

                ITaxon taxon = taxa[changeNameItem.TaxonId];
                if (changeNameItem.NameId.GetValueOrDefault(-1) == -1) // new name is entered
                {
                    ITaxonName taxonName = taxon.GetScientificName(CoreData.UserManager.GetCurrentUser());
                    if (taxonName == null)
                    {
                        continue;
                    }

                    if (taxonName.Name == changeNameItem.Name && taxonName.Author == changeNameItem.Author)
                    {
                        continue;
                    }

                    // Create new recommended scientific name
                    AddScientificRecommendedTaxonName(changeNameItem.Name, changeNameItem.Author, taxon, taxonRevision);
                }
                else // synonym is selected
                {
                    ITaxonName taxonName = taxon.GetTaxonNameByVersion(CoreData.UserManager.GetCurrentUser(), changeNameItem.NameId.Value);
                    if (taxonName == null)
                    {
                        continue;
                    }

                    taxonName.IsRecommended = true;
                    taxonNames.Add(taxonName);
                }
            }

            if (taxonNames.IsNotEmpty())
            {
                using (ITransaction transaction = _user.StartTransaction())
                {
                    CoreData.TaxonManager.UpdateTaxonNames(userContext, taxonRevision, taxonNames);

                    transaction.Commit();
                }
            }
        }