Example #1
0
        /// <summary>
        /// Get not approved taxon names and common names that are not recommended.
        /// </summary>
        /// <param name="taxon">The taxon.</param>
        /// <param name="userContext">The user context.</param>
        /// <returns>Not approved taxon names and common names that are not recommended.</returns>
        public static List <ITaxonName> GetOtherNames(
            this ITaxon taxon,
            IUserContext userContext)
        {
            DateTime          today;
            List <ITaxonName> otherNames;

            otherNames = new List <ITaxonName>();
            today      = DateTime.Now;
            foreach (ITaxonName taxonName in taxon.GetTaxonNames(userContext))
            {
                if ((!taxonName.IsRecommended ||
                     (taxonName.ValidFromDate > today) ||
                     (today > taxonName.ValidToDate)) &&
                    (taxonName.Category.Id == (Int32)TaxonNameCategoryId.SwedishName))
                {
                    otherNames.Add(taxonName);
                }
                else
                {
                    if (taxonName.Status.Id != (Int32)TaxonNameStatusId.ApprovedNaming)
                    {
                        otherNames.Add(taxonName);
                    }
                }
            }
            return(otherNames);
        }
Example #2
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);
        }
        /// <summary>
        /// Get common names that are not recommended and not removed. And also
        /// scientific names that are not approved and not removed.
        /// </summary>
        /// <param name="taxon">The taxon.</param>
        /// <param name="userContext">The user context.</param>
        /// <returns>Common names that are not recommended and not removed. And also
        /// scientific names that are not approved and not removed.</returns>
        public static List <ITaxonName> GetNotRecommendedNames(this ITaxon taxon, IUserContext userContext)
        {
            // todo - fungerar den här inne i en revision?
            var      notRecommendedNames = new List <ITaxonName>();
            DateTime today = DateTime.Now;

            foreach (ITaxonName taxonName in taxon.GetTaxonNames(userContext))
            {
                if (taxonName.Category.Type.Id == (Int32)TaxonNameCategoryTypeId.CommonName &&
                    taxonName.IsRecommended == false &&
                    taxonName.ValidFromDate <= today &&
                    today <= taxonName.ValidToDate &&
                    taxonName.Status.Id != (int)TaxonNameStatusId.Removed)
                {
                    notRecommendedNames.Add(taxonName);
                }
                else if (taxonName.Category.Type.Id == (Int32)TaxonNameCategoryTypeId.ScientificName &&
                         taxonName.IsRecommended == false &&
                         taxonName.ValidFromDate <= today &&
                         today <= taxonName.ValidToDate &&
                         taxonName.Status.Id != (int)TaxonNameStatusId.Removed &&
                         taxonName.Status.Id != (int)TaxonNameStatusId.ApprovedNaming)
                {
                    notRecommendedNames.Add(taxonName);
                }
            }

            return(notRecommendedNames);
        }
Example #4
0
        public void InitTaxonNameDetails(TaxonNameDetailsViewModel model, ITaxon taxon)
        {
            model.CategoryList = new List <TaxonDropDownModelHelper>();
            TaxonNameCategoryList nameList = CoreData.TaxonManager.GetTaxonNameCategories(_user);

            foreach (TaxonNameCategory nameCategory in nameList)
            {
                model.CategoryList.Add(new TaxonDropDownModelHelper(nameCategory.Id, nameCategory.Name));
            }
            model.TaxonNameStatusList = new List <TaxonDropDownModelHelper>();
            TaxonNameStatusList nameStatusList = CoreData.TaxonManager.GetTaxonNameStatuses(_user);

            foreach (ITaxonNameStatus nameStatus in nameStatusList.OrderBy(t => t.SortOrder()))
            {
                model.TaxonNameStatusList.Add(new TaxonDropDownModelHelper(nameStatus.Id, nameStatus.Name));
            }
            model.TaxonNameUsageList = new List <TaxonDropDownModelHelper>();
            TaxonNameUsageList nameUsageList = CoreData.TaxonManager.GetTaxonNameUsages(_user);

            foreach (ITaxonNameUsage nameUsage in nameUsageList)
            {
                model.TaxonNameUsageList.Add(new TaxonDropDownModelHelper(nameUsage.Id, nameUsage.Name));
            }
            model.ExistingNames = new List <TaxonNameDetailsViewModel>();
            TaxonNameList taxonNames = taxon.GetTaxonNames(_user);

            for (int i = 0; i < taxonNames.Count; i++)
            {
                ITaxonName taxonName = taxonNames[i];
                model.ExistingNames.Add(TaxonNameDetailsViewModel.Create(_user, taxonName));
            }
            model.ExistingNames = (from name in model.ExistingNames orderby name.CategoryName select name).ToList();
            for (int i = 0; i < model.ExistingNames.Count; i++)
            {
                if (model.ExistingNames[i].Id == model.Id)
                {
                    model.ExistingNamesCurrentIndex = i;
                    break;
                }
            }

            // Check name category if Scentific and recommended it is not possible to change status.
            // Unselcet as recommended first and the it is possible to change name usage
            if (model.IsRecommended && (model.SelectedCategoryId == (Int32)TaxonNameCategoryId.ScientificName))
            {
                model.IsPossibleToChangeUsage = false;
            }
            else
            {
                model.IsPossibleToChangeUsage = true;
            }
        }
        /// <summary>
        /// Get taxon names where taxon name category type
        /// equals IDENTIFIER.
        /// </summary>
        /// <param name="taxon">The taxon.</param>
        /// <param name="userContext">The user context.</param>
        /// <returns>
        /// Taxon names where taxon name category type
        /// equals IDENTIFIER.
        /// </returns>
        public static List <ITaxonName> GetAllIdentifiers(this ITaxon taxon, IUserContext userContext)
        {
            var identifiers = new List <ITaxonName>();

            foreach (ITaxonName taxonName in taxon.GetTaxonNames(userContext))
            {
                if (taxonName.Category.Type.Id == (Int32)TaxonNameCategoryTypeId.Identifier)
                {
                    identifiers.Add(taxonName);
                }
            }

            return(identifiers);
        }
        /// <summary>
        /// Gets the taxon anamorph name or null if it doesn't exist.
        /// </summary>
        /// <param name="taxon">The taxon.</param>
        /// <returns>The taxon anamorph name or null if it doesn't exist.</returns>
        public static ITaxonName GetAnamorphName(this ITaxon taxon)
        {
            ITaxonName name = null;

            foreach (ITaxonName taxonName in taxon.GetTaxonNames(CoreData.UserManager.GetCurrentUser()))
            {
                if (taxonName.Category.Id == (Int32)TaxonNameCategoryId.AnamorphName)
                {
                    name = taxonName;
                    if (name.IsRecommended)
                    {
                        break;
                    }
                }
            }

            return(name);
        }
        /// <summary>
        /// Get common names that are recommended and approved, but not swedish.
        /// </summary>
        /// <param name="taxon">The taxon.</param>
        /// <param name="userContext">The user context.</param>
        /// <returns>Common names that are recommended and approved, but not swedish.</returns>
        public static List <ITaxonName> GetOtherLanguagesNames(this ITaxon taxon, IUserContext userContext)
        {
            // todo - fungerar den här inne i en revision?
            var      otherLanguagesNames = new List <ITaxonName>();
            DateTime today = DateTime.Now;

            foreach (ITaxonName taxonName in taxon.GetTaxonNames(userContext))
            {
                if (taxonName.Category.Type.Id == (Int32)TaxonNameCategoryTypeId.CommonName &&
                    taxonName.IsRecommended &&
                    taxonName.Status.Id == (int)TaxonNameStatusId.ApprovedNaming &&
                    taxonName.ValidFromDate <= today &&
                    today <= taxonName.ValidToDate &&
                    taxonName.Category.Id != (Int32)TaxonNameCategoryId.SwedishName)
                {
                    otherLanguagesNames.Add(taxonName);
                }
            }

            return(otherLanguagesNames);
        }
Example #8
0
        //public int RevisionId { get { return _revisionId; } }

        /// <summary>
        /// Constructor
        /// </summary>
        public ListTaxonNameViewModel(ITaxon taxon, ITaxonRevision taxonRevision)
        {
            this._taxonRevision = taxonRevision;
            this._taxon         = taxon;

            Dictionary <ITaxonNameCategory, List <ITaxonName> > dicNames = GetTaxonNamesByCategory(taxon.GetTaxonNames(CoreData.UserManager.GetCurrentUser()));

            var nameCategories = new List <TaxonNameCategoryViewModel>();

            foreach (ITaxonNameCategory nameCategory in dicNames.Keys)
            {
                nameCategories.Add(new TaxonNameCategoryViewModel(taxon, nameCategory, dicNames[nameCategory]));
            }

            NameCategories = nameCategories;
        }