public void UpdateSpeciesFact(IUserContext loggedInUser, RevisionEditViewModel model, ITaxon taxon)
        {
            try
            {
                // Check logged in user
                if (loggedInUser.IsNotNull())
                {
                    SpeciesFactModelManager speciesModel = new SpeciesFactModelManager(taxon, loggedInUser);

                    // Create quality values
                    if (model.RevisionQualityId != 0)
                    {
                        speciesModel.QualityStatusId = model.RevisionQualityId;
                    }

                    if (model.RevisionQualityDescription.IsNotNull())
                    {
                        speciesModel.QualityDescription = model.RevisionQualityDescription;
                    }
                    // Now we update
                    speciesModel.UpdateDyntaxaSpeciesFacts();
                }
            }
            catch (Exception e)
            {
                Exception ex = new Exception(Resources.DyntaxaResource.SharedNotPossibleToUpdateSpeciesFactError, e);
                throw ex;
            }
        }
コード例 #2
0
        public void TestSpeciesFactsWithIncludeMissingSpeciesFacts()
        {
            IUserContext    userContext = GetUserContext();
            List <FactorId> factorIds   = new List <FactorId> {
                FactorId.SwedishOccurrence, FactorId.SwedishHistory
            };
            List <int> taxonIds = new List <int>();

            taxonIds.Add(237935);  //Amphora Veneta
            SpeciesFactList speciesFactList       = SpeciesFactModelManager.GetSpeciesFactListByTaxaAndFactors(userContext, factorIds, taxonIds, true);
            var             speciesFactDictionary = speciesFactList.ToDictionaryGroupedByTaxonIdThenFactorId();

            Assert.IsTrue(speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetStatusId().HasValue);
            Assert.IsFalse(speciesFactDictionary[237935][FactorId.SwedishHistory].GetStatusId().HasValue);

            var occurrenceStatusId    = speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetStatusId();
            var occurrenceQualityId   = speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetQualityId();
            var occurrenceReferenceId = speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetReferenceId();
            var occurrenceComment     = speciesFactDictionary[237935][FactorId.SwedishOccurrence].GetDescription();

            var historyStatusId    = speciesFactDictionary[237935][FactorId.SwedishHistory].GetStatusId();
            var historyQualityId   = speciesFactDictionary[237935][FactorId.SwedishHistory].GetQualityId();
            var historyReferenceId = speciesFactDictionary[237935][FactorId.SwedishHistory].GetReferenceId();
            var historyComment     = speciesFactDictionary[237935][FactorId.SwedishHistory].GetDescription();

            Assert.IsNotNull(speciesFactList);
        }
コード例 #3
0
        public void TestSpeciesFactsWithExcludeMissingSpeciesFacts()
        {
            IUserContext    userContext = GetUserContext();
            List <FactorId> factorIds   = new List <FactorId> {
                FactorId.SwedishOccurrence, FactorId.SwedishHistory
            };
            List <int> taxonIds = new List <int>();

            taxonIds.Add(237935);  //Amphora Veneta
            SpeciesFactList speciesFactList       = SpeciesFactModelManager.GetSpeciesFactListByTaxaAndFactors(userContext, factorIds, taxonIds, false);
            var             speciesFactDictionary = speciesFactList.ToDictionaryGroupedByTaxonIdThenFactorId();

            Assert.IsTrue(speciesFactDictionary.ContainsKey(237935));
            Assert.IsTrue(speciesFactDictionary[237935].ContainsKey(FactorId.SwedishOccurrence));
            Assert.IsFalse(speciesFactDictionary[237935].ContainsKey(FactorId.SwedishHistory));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="loggedInUser"></param>
        /// <param name="dyntaxaApplicationUserContext"></param>
        /// <param name="taxonRevision"></param>
        /// <param name="isTaxonInRevision"></param>
        /// <param name="revisionUsers"></param>
        /// <param name="allUsers"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public RevisionEditViewModel GetRevisionEditViewModel(
            IUserContext loggedInUser,
            IUserContext dyntaxaApplicationUserContext,
            ITaxonRevision taxonRevision,
            ITaxon taxon,
            bool isTaxonInRevision,
            IList <RevisionUserItemModelHelper> revisionUsers,
            IList <RevisionUserItemModelHelper> allUsers,
            int roleId)
        {
            RevisionEditViewModel model = new RevisionEditViewModel();

            if (loggedInUser.IsNotNull() && dyntaxaApplicationUserContext.IsNotNull())
            {
                // Set locale to logged in user.
                dyntaxaApplicationUserContext.Locale = loggedInUser.Locale;

                if (taxonRevision.IsNotNull())
                {
                    if (taxon.IsNotNull())
                    {
                        model.ExpectedStartDate             = taxonRevision.ExpectedStartDate;
                        model.ExpectedPublishingDate        = taxonRevision.ExpectedEndDate;
                        model.IsSpeciesFactPublished        = taxonRevision.IsSpeciesFactPublished;
                        model.IsReferenceRelationsPublished = taxonRevision.IsReferenceRelationsPublished;
                        model.GUID = taxonRevision.Guid;
                        model.RevisionReferencesList = new List <int>();
                        model.NoOfRevisionReferences = 0;
                        foreach (ReferenceRelation referenceRelation in taxonRevision.GetReferences(loggedInUser))
                        {
                            model.RevisionReferencesList.Add(referenceRelation.Id);
                            model.NoOfRevisionReferences++;
                        }

                        model.SelectedUserList = new List <RevisionUserItemModelHelper>();
                        model.UserList         = new List <RevisionUserItemModelHelper>();
                        foreach (RevisionUserItemModelHelper user in allUsers)
                        {
                            bool userAssigedToRevision = false;
                            foreach (RevisionUserItemModelHelper revisionUser in revisionUsers)
                            {
                                if (user.Id == revisionUser.Id)
                                {
                                    //We found a alreday assigned user
                                    userAssigedToRevision = true;
                                    break;
                                }
                            }

                            if (userAssigedToRevision)
                            {
                                model.SelectedUserList.Add(user);
                            }
                            else
                            {
                                model.UserList.Add(user);
                            }
                        }
                        string url = Resources.DyntaxaResource.SharedRevisionUserAdminLinkText;
                        model.RoleId        = roleId.ToString();
                        model.UserAdminLink = new LinkItem(LinkType.Url, LinkQuality.Automatic, url, userAdminRoleLink);

                        model.RevisionDescription = taxonRevision.Description;

                        // Get specices fact information
                        try
                        {
                            SpeciesFactModelManager speciesModel = new SpeciesFactModelManager(taxon, loggedInUser);
                            try
                            {
                                if (speciesModel.QualityStatus.IsNotNull())
                                {
                                    model.RevisionQualityId = speciesModel.QualityStatus.Id;
                                }
                                else if (speciesModel.QualityStatusList.IsNotNull() && speciesModel.QualityStatusList.Count > 1)
                                {
                                    model.RevisionQualityId = speciesModel.QualityStatusList.ElementAt(0).Id;
                                }
                                else
                                {
                                    model.RevisionQualityId = 0;
                                }

                                model.RevisionQualityList = new List <TaxonDropDownModelHelper>();
                                foreach (var status in speciesModel.QualityStatusList)
                                {
                                    model.RevisionQualityList.Add(new TaxonDropDownModelHelper(status.Id, status.Label));
                                }
                                model.RevisionQualityDescription = speciesModel.QualityDescription;
                            }
                            catch (Exception)
                            {
                                model.ErrorMessage = Resources.DyntaxaResource.SharedNotPossibleToReadSpeciesFactError;
                            }
                        }
                        catch (Exception)
                        {
                            model.ErrorMessage = Resources.DyntaxaResource.SharedNotPossibleToReadSpeciesFactError;
                        }

                        model.RevisionTaxonInfoViewModel = new RevisionTaxonInfoViewModel();

                        model.RevisionTaxonInfoViewModel.Id                = taxonRevision.Id.ToString();
                        model.RevisionTaxonInfoViewModel.CommonName        = taxon.CommonName.IsNotEmpty() ? taxon.CommonName : string.Empty;
                        model.RevisionTaxonInfoViewModel.ScientificName    = taxon.ScientificName;
                        model.RevisionTaxonInfoViewModel.Category          = taxon.Category.Name;
                        model.RevisionTaxonInfoViewModel.CategorySortOrder = taxon.Category.SortOrder;

                        model.RevisionTaxonInfoViewModel.RevisionText   = Resources.DyntaxaResource.SharedRevisionIdLabelText;
                        model.RevisionTaxonInfoViewModel.MainHeaderText = Resources.DyntaxaResource.RevisionEditMainHeaderFullText;

                        model.RevisionId          = taxonRevision.Id.ToString();
                        model.ShowFinalizeButton  = false;
                        model.ShowInitalizeButton = false;
                        model.ShowDeleteButton    = false;
                        ITaxon revisionTaxon = taxonRevision.RootTaxon;
                        int    state         = taxonRevision.State.Id;
                        if (state == (int)TaxonRevisionStateId.Created)
                        {
                            model.RevisionStatus      = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusCreatedText;
                            model.ShowInitalizeButton = true;
                            model.IsTaxonInRevision   = revisionTaxon.IsInRevision;
                            model.ShowDeleteButton    = true;
                        }
                        else if (state == (int)TaxonRevisionStateId.Ongoing)
                        {
                            model.RevisionStatus     = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusOngoingText;
                            model.ShowFinalizeButton = true;
                        }
                        else if (state == (int)TaxonRevisionStateId.Closed)
                        {
                            model.RevisionStatus = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusClosedText;
                            model.ShowUpdateSpeciesFactButton        = !taxonRevision.IsSpeciesFactPublished;
                            model.ShowUpdateReferenceRelationsButton = !taxonRevision.IsReferenceRelationsPublished;
                        }
                        model.RevisionTaxonId = revisionTaxon.Id.ToString();

                        return(model);
                    }
                    else
                    {
                        model.ErrorMessage = Resources.DyntaxaResource.RevisonAddInvalidTaxonErrorText;
                    }
                }
                else
                {
                    model.ErrorMessage = Resources.DyntaxaResource.RevisionSharedNoValidRevisionIdErrorText + taxonRevision.Id + ".";
                }
            }
            else
            {
                model.ErrorMessage = Resources.DyntaxaResource.SharedInvalidUserContext + " " + Resources.DyntaxaResource.SharedInvalidApplicationUserContext;
            }
            return(model);
        }
        public RevisionEditViewModel ReloadRevisionEditViewModel(
            IUserContext userContext,
            IUserContext dyntaxaApplicationUserContext,
            ITaxon taxon,
            ITaxonRevision taxonRevision,
            RevisionEditViewModel model,
            IList <RevisionUserItemModelHelper> revisionUsers,
            IList <RevisionUserItemModelHelper> allUsers)
        {
            IUserContext loggedInUser = userContext;

            model.RevisionQualityList        = new List <TaxonDropDownModelHelper>();
            model.SelectedUserList           = new List <RevisionUserItemModelHelper>();
            model.UserList                   = new List <RevisionUserItemModelHelper>();
            model.RevisionReferencesList     = new List <int>();
            model.RevisionTaxonInfoViewModel = new RevisionTaxonInfoViewModel();
            if (loggedInUser.IsNotNull() && dyntaxaApplicationUserContext.IsNotNull())
            {
                if (taxonRevision.IsNotNull())
                {
                    foreach (ReferenceRelation referenceRelation in taxonRevision.GetReferences(userContext))
                    {
                        model.RevisionReferencesList.Add(referenceRelation.Id);
                    }
                }

                foreach (RevisionUserItemModelHelper user in allUsers)
                {
                    bool userAssigedToRevision = false;
                    if (revisionUsers.IsNotNull())
                    {
                        foreach (RevisionUserItemModelHelper revisionUser in revisionUsers)
                        {
                            if (user.Id == revisionUser.Id)
                            {
                                //We found a alreday assigned user
                                userAssigedToRevision = true;
                                break;
                            }
                        }
                    }
                    if (userAssigedToRevision)
                    {
                        model.SelectedUserList.Add(user);
                    }
                    else
                    {
                        model.UserList.Add(user);
                    }
                }

                if (taxon.IsNotNull())
                {
                    SpeciesFactModelManager speciesModel = new SpeciesFactModelManager(taxon, loggedInUser);
                    foreach (var status in speciesModel.QualityStatusList)
                    {
                        model.RevisionQualityList.Add(new TaxonDropDownModelHelper(status.Id, status.Label));
                    }
                }
                if (taxon.IsNotNull() && taxonRevision.IsNotNull())
                {
                    model.RevisionTaxonInfoViewModel = new RevisionTaxonInfoViewModel();

                    model.RevisionTaxonInfoViewModel.Id                = taxonRevision.Id.ToString();
                    model.RevisionTaxonInfoViewModel.CommonName        = taxon.CommonName.IsNotEmpty() ? taxon.CommonName : string.Empty;
                    model.RevisionTaxonInfoViewModel.ScientificName    = taxon.ScientificName;
                    model.RevisionTaxonInfoViewModel.Category          = taxon.Category.Name;
                    model.RevisionTaxonInfoViewModel.CategorySortOrder = taxon.Category.SortOrder;

                    model.RevisionTaxonInfoViewModel.RevisionText   = Resources.DyntaxaResource.SharedRevisionIdLabelText;
                    model.RevisionTaxonInfoViewModel.MainHeaderText = Resources.DyntaxaResource.RevisionEditMainHeaderFullText;
                }

                string url = Resources.DyntaxaResource.SharedRevisionUserAdminLinkText;
                model.UserAdminLink = new LinkItem(LinkType.Url, LinkQuality.Automatic, url, userAdminRoleLink);
            }
            else
            {
                model.ErrorMessage = Resources.DyntaxaResource.SharedInvalidUserContext + " " + Resources.DyntaxaResource.SharedInvalidApplicationUserContext;
            }
            return(model);
        }
コード例 #6
0
        //private static IPerson GetCreatedByPerson(IUserContext userContext, int createdBy)
        //{
        //    IPerson person;
        //    IUser user;

        //    try
        //    {
        //        user = CoreData.UserManager.GetUser(userContext, createdBy);
        //    }
        //    catch (Exception)
        //    {
        //        // user does not exist in UserAdmin system
        //        user = null;
        //    }

        //    if ((user.IsNotNull()) &&
        //        (user.Type == UserType.Person) &&
        //        (user.PersonId.HasValue))
        //    {
        //        person = CoreData.UserManager.GetPerson(userContext, user.PersonId.Value);
        //    }
        //    else
        //    {
        //        person = null;
        //    }
        //    return person;
        //}

        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="userContext">
        /// The user context.
        /// </param>
        /// <param name="taxon">
        /// The taxon.
        /// </param>
        /// <param name="revisionId">
        /// The revision id.
        /// </param>
        /// <returns>
        /// The <see cref="TaxonSummaryViewModel"/>.
        /// </returns>
        public static TaxonSummaryViewModel Create(IUserContext userContext, ITaxon taxon, int?revisionId)
        {
            var     model = new TaxonSummaryViewModel();
            IPerson person;
            bool    isInRevision      = DyntaxaHelper.IsInRevision(userContext, revisionId);
            bool    isUserTaxonEditor = userContext.IsTaxonEditor();

            model.Id                = taxon.Id.ToString();
            model.Guid              = taxon.Guid ?? string.Empty;
            model.CategoryId        = taxon.Category != null ? taxon.Category.Id : 0;
            model.Category          = taxon.Category != null ? taxon.Category.Name : string.Empty;
            model.IsMicrospecies    = taxon.IsMicrospecies;
            model.CategorySortOrder = taxon.Category != null ? taxon.Category.SortOrder : 0;
            model.ConceptDefinition = taxon.GetConceptDefinition(userContext) ?? "-";
            model.AlertStatus       = (TaxonAlertStatusId)taxon.AlertStatus.Id;
            model.AlertImageUrl     = GetAlertImageUrl(model.AlertStatus);
            person = taxon.GetModifiedByPerson(userContext);
            //IPerson createdByPerson = GetCreatedByPerson(userContext, taxon.CreatedBy);
            //string createdFullName = createdByPerson.FullName;
            if (person.IsNull())
            {
                model.UpdateInformation = string.Format("{0} ({1})", taxon.ModifiedDate.ToShortDateString(), String.Empty);
            }
            else
            {
                model.UpdateInformation = string.Format("{0} ({1})", taxon.ModifiedDate.ToShortDateString(), person.FullName);
            }

            model.ValidToInformation = string.Format("{0} ({1})", taxon.ValidToDate.ToShortDateString(), taxon.ModifiedByPerson);
            model.CreatedInformation = string.Format("{0} ({1})", taxon.CreatedDate.ToShortDateString(), taxon.ModifiedByPerson);
            model.Validity           = GetValidityDescription(taxon);

            if (taxon.ScientificName.IsNotEmpty())
            {
                model.ScientificName = new TaxonNameAuthorViewModel(taxon.ScientificName, taxon.Author);
            }

            if (taxon.CommonName.IsNotEmpty())
            {
                model.CommonName = new TaxonNameAuthorViewModel(taxon.CommonName, string.Empty);
            }

            // Synonyms
            //model.Synonyms = new List<TaxonNameViewModel>();
            //var synonyms = taxon.GetSynonyms(userContext, true);
            //if (synonyms != null)
            //{
            //    foreach (ITaxonName taxonName in synonyms)
            //    {
            //        model.Synonyms.Add(new TaxonNameViewModel(taxonName, taxon));
            //    }
            //}

            model.Synonyms         = taxon.GetSynonymsViewModel(isInRevision, isUserTaxonEditor, false);
            model.ProParteSynonyms = taxon.GetProParteSynonymsViewModel(isInRevision, isUserTaxonEditor);
            model.MisappliedNames  = taxon.GetMisappliedNamesViewModel(isInRevision, isUserTaxonEditor);

            // Other valid common names
            // todo - change implementation?
            //model.OtherValidCommonNames = new List<string>();
            //if (!taxon.CommonName.IsEmpty())
            //{
            //    model.OtherValidCommonNames.AddRange(
            //        from taxonName in taxon.GetTaxonNames(userContext)
            //        where
            //            taxonName.Category.Id == (int)TaxonNameCategoryId.SwedishName &&
            //            taxonName.Version != taxon.GetCommonName(userContext).Version
            //        select taxonName.Name);

            //    // todo - även ha med att namnet är gilitigt. Hur ser man det???
            //}

            model.OtherValidCommonNames = taxon.GetNotRecommendedSwedishNamesViewModel(isInRevision, isUserTaxonEditor);

            // Remove other valid common names from synonyms
            if (model.OtherValidCommonNames.IsNotEmpty())
            {
                List <TaxonNameViewModel> newSynonymList = new List <TaxonNameViewModel>();

                foreach (TaxonNameViewModel synonym in model.Synonyms)
                {
                    if (model.OtherValidCommonNames.All(x => x.Id != synonym.Id))
                    {
                        newSynonymList.Add(synonym);
                    }
                }

                model.Synonyms = newSynonymList;
            }

            // Classification
            var allParentTaxa      = taxon.GetAllParentTaxonRelations(userContext, null, isInRevision, false, true);
            var distinctParentTaxa = allParentTaxa.GroupBy(x => x.ParentTaxon.Id).Select(x => x.First().ParentTaxon).ToList();

            model.Classification = new List <RelatedTaxonViewModel>();
            foreach (ITaxon relatedTaxon in distinctParentTaxa)
            {
                if (relatedTaxon.Category.IsTaxonomic)
                {
                    model.Classification.Add(new RelatedTaxonViewModel(relatedTaxon, relatedTaxon.Category, null));
                }
            }

            // Species fact
            try
            {
                // Dictionary<FactorId, SpeciesFact> dicSpeciesFacts = SpeciesFactHelper.GetSpeciesFacts(taxon, new [] {FactorId.SwedishOccurence, FactorId.SwedishHistory});
                Dictionary <FactorId, SpeciesFact> dicSpeciesFacts = SpeciesFactHelper.GetCommonDyntaxaSpeciesFacts(userContext, taxon);
                model.SwedishHistory    = SpeciesFactHelper.GetFactorValue(dicSpeciesFacts, FactorId.SwedishHistory);
                model.SwedishOccurrence = SpeciesFactHelper.GetFactorValue(dicSpeciesFacts, FactorId.SwedishOccurrence);

                // If swedish occurrence or swedish history is changed in the current revision, then show those values instead.
                if (DyntaxaHelper.IsInRevision(userContext, revisionId))
                {
                    DyntaxaInternalTaxonServiceManager internalTaxonServiceManager =
                        new DyntaxaInternalTaxonServiceManager();

                    // Check if Swedish occurrence is stored in Taxon database in this revision.
                    DyntaxaRevisionSpeciesFact swedishOccurrenceRevisionSpeciesFact =
                        internalTaxonServiceManager.GetDyntaxaRevisionSpeciesFact(
                            userContext,
                            (Int32)FactorId.SwedishOccurrence,
                            taxon.Id,
                            revisionId.Value);
                    if (swedishOccurrenceRevisionSpeciesFact != null)
                    {
                        SpeciesFactModelManager speciesFactModel = new SpeciesFactModelManager(taxon, userContext);
                        TaxonModelManager.UpdateOldSpeciesFactModelWithDyntaxaRevisionSpeciesFactValues(userContext, speciesFactModel.SwedishOccurrenceSpeciesFact, swedishOccurrenceRevisionSpeciesFact);
                        model.SwedishOccurrence = speciesFactModel.SwedishOccurrenceSpeciesFact.GetStatusOriginalLabel();
                    }

                    // Check if Swedish history is stored in Taxon database in this revision.
                    DyntaxaRevisionSpeciesFact swedishHistoryRevisionSpeciesFact =
                        internalTaxonServiceManager.GetDyntaxaRevisionSpeciesFact(
                            userContext,
                            (Int32)FactorId.SwedishHistory,
                            taxon.Id,
                            revisionId.Value);
                    if (swedishHistoryRevisionSpeciesFact != null)
                    {
                        if (swedishHistoryRevisionSpeciesFact.StatusId.HasValue)
                        {
                            SpeciesFactModelManager speciesFactModel = new SpeciesFactModelManager(taxon, userContext);
                            TaxonModelManager.UpdateOldSpeciesFactModelWithDyntaxaRevisionSpeciesFactValues(userContext, speciesFactModel.SwedishHistorySpeciesFact, swedishHistoryRevisionSpeciesFact);
                            model.SwedishHistory = speciesFactModel.SwedishHistorySpeciesFact.GetStatusOriginalLabel();
                        }
                        else // swedish history is deleted in this revision
                        {
                            model.SwedishHistory = "";
                        }
                    }
                }
            }
            catch (Exception)
            {
                // the taxon did not exist in Artfakta
            }

            return(model);
        }
        /// <summary>
        /// Creates a swedish occurrence summary view model.
        /// </summary>
        /// <param name="taxon">The taxon.</param>
        /// <returns></returns>
        public SwedishOccurrenceSummaryViewModel CreateSwedishOccurrenceSummaryViewModel(ITaxon taxon)
        {
            var model        = new SwedishOccurrenceSummaryViewModel();
            int?redListValue = null;

            // Species fact
            try
            {
                Dictionary <ArtDatabanken.Data.FactorId, ArtDatabanken.Data.SpeciesFact> dicSpeciesFacts = SpeciesFactHelper.GetCommonDyntaxaSpeciesFacts(this._userContext, taxon);
                if (dicSpeciesFacts.ContainsKey(FactorId.SwedishHistory))
                {
                    model.SwedishHistory     = SpeciesFactHelper.GetFactorValue(dicSpeciesFacts, ArtDatabanken.Data.FactorId.SwedishHistory);
                    model.SwedishHistoryFact = dicSpeciesFacts[FactorId.SwedishHistory];
                }

                if (dicSpeciesFacts.ContainsKey(FactorId.SwedishOccurrence))
                {
                    //CoreData.SpeciesFactManager.GetSpeciesFact()
                    model.SwedishOccurrence     = SpeciesFactHelper.GetFactorValue(dicSpeciesFacts, ArtDatabanken.Data.FactorId.SwedishOccurrence);
                    model.SwedishOccurrenceFact = dicSpeciesFacts[FactorId.SwedishOccurrence];
                }

                if (dicSpeciesFacts.ContainsKey(FactorId.RedlistCategory))
                {
                    model.RedListInfo = GetRedListCategory(dicSpeciesFacts[ArtDatabanken.Data.FactorId.RedlistCategory]);
                    redListValue      = GetRedListCategoryValue(dicSpeciesFacts[ArtDatabanken.Data.FactorId.RedlistCategory]);
                }

                // If swedish occurrence or swedish history is changed in the current revision, then show those values instead.
                if (DyntaxaHelper.IsInRevision(_userContext, _taxonRevision))
                {
                    DyntaxaInternalTaxonServiceManager internalTaxonServiceManager =
                        new DyntaxaInternalTaxonServiceManager();

                    // Check if Swedish occurrence is stored in Taxon database in this revision.
                    DyntaxaRevisionSpeciesFact swedishOccurrenceRevisionSpeciesFact =
                        internalTaxonServiceManager.GetDyntaxaRevisionSpeciesFact(
                            _userContext,
                            (Int32)FactorId.SwedishOccurrence,
                            taxon.Id,
                            _taxonRevision.Id);
                    if (swedishOccurrenceRevisionSpeciesFact != null)
                    {
                        SpeciesFactModelManager speciesFactModel = new SpeciesFactModelManager(taxon, _userContext);
                        TaxonModelManager.UpdateOldSpeciesFactModelWithDyntaxaRevisionSpeciesFactValues(_userContext, speciesFactModel.SwedishOccurrenceSpeciesFact, swedishOccurrenceRevisionSpeciesFact);
                        model.SwedishOccurrence     = speciesFactModel.SwedishOccurrenceSpeciesFact.GetStatusOriginalLabel();
                        model.SwedishOccurrenceFact = speciesFactModel.SwedishOccurrenceSpeciesFact;
                    }

                    // Check if Swedish history is stored in Taxon database in this revision.
                    DyntaxaRevisionSpeciesFact swedishHistoryRevisionSpeciesFact =
                        internalTaxonServiceManager.GetDyntaxaRevisionSpeciesFact(
                            _userContext,
                            (Int32)FactorId.SwedishHistory,
                            taxon.Id,
                            _taxonRevision.Id);
                    if (swedishHistoryRevisionSpeciesFact != null)
                    {
                        if (swedishHistoryRevisionSpeciesFact.StatusId.HasValue)
                        {
                            SpeciesFactModelManager speciesFactModel = new SpeciesFactModelManager(taxon, _userContext);
                            TaxonModelManager.UpdateOldSpeciesFactModelWithDyntaxaRevisionSpeciesFactValues(_userContext, speciesFactModel.SwedishHistorySpeciesFact, swedishHistoryRevisionSpeciesFact);
                            model.SwedishHistory     = speciesFactModel.SwedishHistorySpeciesFact.GetStatusOriginalLabel();
                            model.SwedishHistoryFact = speciesFactModel.SwedishHistorySpeciesFact;
                        }
                        else // swedish history is deleted in this revision
                        {
                            model.SwedishHistory     = null;
                            model.SwedishHistoryFact = null;
                        }
                    }
                }
            }
            catch (Exception)
            {
                // the taxon did not exist in Artfakta
            }

            const int noRedListValue = 6;

            if (!string.IsNullOrEmpty(model.RedListInfo) && redListValue.GetValueOrDefault(0) < noRedListValue)
            {
                var    linkManager = new LinkManager();
                string url         = linkManager.GetUrlToRedlist(taxon.Id.ToString());
                if (url != "")
                {
                    var item = new LinkItem(
                        LinkType.Url,
                        LinkQuality.ApprovedByExpert,
                        Resources.DyntaxaResource.LinkToSwedishRedlistLabel,
                        url);
                    model.RedListLink = item;
                }
            }

            return(model);
        }