示例#1
0
        public ITaxonName SaveTaxonNameDetailsChanges(TaxonNameDetailsViewModel model, int taxonId, ITaxonRevision taxonRevision)
        {
            ITaxon     taxon     = CoreData.TaxonManager.GetTaxon(_user, taxonId);
            ITaxonName taxonName = taxon.GetTaxonNameByVersion(_user, Int32.Parse(model.Version));

            taxonName.Name      = model.Name;
            taxonName.Author    = model.Author;
            taxonName.Category  = CoreData.TaxonManager.GetTaxonNameCategory(_user, model.SelectedCategoryId);
            taxonName.Status    = CoreData.TaxonManager.GetTaxonNameStatus(_user, model.SelectedTaxonNameStatusId);
            taxonName.NameUsage = CoreData.TaxonManager.GetTaxonNameUsage(_user, model.SelectedTaxonNameUsageId);
            //taxonName.IsRecommended = model.IsRecommended;
            taxonName.Description = model.Comment;
            taxonName.Taxon       = CoreData.TaxonManager.GetTaxon(_user, model.TaxonId);
            taxonName.IsOkForSpeciesObservation = !model.IsNotOkForObsSystem;
            taxonName.IsOriginalName            = model.IsOriginal;

            // at least one scientific name must be recommended
            if (taxonName.Category.Id == (Int32)TaxonNameCategoryId.ScientificName && taxonName.IsRecommended == false)
            {
                var  scientificNames  = taxon.GetTaxonNames(_user).Where(name => name.Category.Id == (Int32)TaxonNameCategoryId.ScientificName).ToList();
                bool isAnyRecommended = scientificNames.Any(scientificName => scientificName.IsRecommended);
                if (!isAnyRecommended)
                {
                    taxonName.IsRecommended = true;
                }
            }

            using (ITransaction transaction = _user.StartTransaction())
            {
                CoreData.TaxonManager.UpdateTaxonName(_user, taxonRevision, taxonName);

                transaction.Commit();
            }
            return(taxonName);
        }
示例#2
0
        public TaxonNameDetailsViewModel GetTaxonNameDetailsViewModel(ITaxon taxon, string nameId)
        {
            ITaxonName taxonName = taxon.GetTaxonNameByVersion(_user, Int32.Parse(nameId));
            var        model     = TaxonNameDetailsViewModel.Create(_user, taxonName);

            InitTaxonNameDetails(model, taxon);
            return(model);
        }
        /// <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();
                }
            }
        }
示例#4
0
        public void DeleteName(int taxonId, ITaxonRevision taxonRevision, int nameId)
        {
            IUserContext userContext = CoreData.UserManager.GetCurrentUser();
            ITaxon       taxon       = CoreData.TaxonManager.GetTaxon(userContext, taxonId);
            ITaxonName   taxonName   = taxon.GetTaxonNameByVersion(CoreData.UserManager.GetCurrentUser(), nameId);

            using (ITransaction transaction = userContext.StartTransaction())
            {
                CoreData.TaxonManager.DeleteTaxonName(userContext, taxonRevision, taxonName);
                transaction.Commit();
            }
        }
示例#5
0
        public bool CanDeleteName(int taxonId, int nameId)
        {
            ITaxon     taxon     = CoreData.TaxonManager.GetTaxon(_user, taxonId);
            ITaxonName taxonName = taxon.GetTaxonNameByVersion(CoreData.UserManager.GetCurrentUser(), nameId);

            if (taxonName != null && taxonName.Category.Id == (Int32)TaxonNameCategoryId.ScientificName && taxonName.IsRecommended)
            {
                return(false);
            }

            return(true);
        }
示例#6
0
        public TaxonNameDeleteViewModel GetViewModel(ITaxon taxon, int nameId)
        {
            ITaxonName taxonName = taxon.GetTaxonNameByVersion(CoreData.UserManager.GetCurrentUser(), nameId);

            TaxonNameDeleteViewModel model = new TaxonNameDeleteViewModel();

            model.TaxonId       = taxon.Id;
            model.Version       = taxonName.Version;
            model.Name          = taxonName.Name;
            model.Comment       = taxonName.Description;
            model.Author        = taxonName.Author ?? "";
            model.Category      = taxonName.Category.Name;
            model.NameUsage     = taxonName.NameUsage.Name;
            model.NameStatus    = taxonName.Status.Name;
            model.IsRecommended = taxonName.IsRecommended;

            return(model);
        }