/// <summary> /// Add references to current species fact data set scope. /// The species facts in the data set are updated /// to the new species fact data set scope. /// </summary> /// <param name="userContext"></param> /// <param name="selection"></param> public virtual void AddSelection(IUserContext userContext, ReferenceList selection) { ISpeciesFactDataSetSelection newSelection; newSelection = new SpeciesFactDataSetSelection(); newSelection.References.Merge(selection); AddSelection(userContext, newSelection); }
/// <summary> /// Create a species fact data set selection instance. /// </summary> public SpeciesFactDataSetSelection() { _factors = new FactorList(true); _hosts = new TaxonList(true); _individualCategories = new IndividualCategoryList(true); _periods = new PeriodList(true); _references = new ReferenceList(true); _taxa = new TaxonList(true); }
/// <summary> /// Default constructor /// </summary> public SpeciesFactSearchCriteria() { FactorDataTypes = new FactorDataTypeList(); Factors = new FactorList(); FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList(); Hosts = new TaxonList(); IndividualCategories = new IndividualCategoryList(); Periods = new PeriodList(); References = new ReferenceList(); Taxa = new TaxonList(); }
/// <summary> /// Set references for specified locale. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="loadedReferences">Loaded references.</param> /// <param name="locale">Currently used locale.</param> protected virtual void SetReferences(IUserContext userContext, ReferenceList loadedReferences, ILocale locale) { ReferenceList cachedReferences; if (userContext.Transaction.IsNull()) { cachedReferences = (ReferenceList)(References[locale.ISOCode]); cachedReferences.Merge(loadedReferences); } }
/// <summary> /// Create a species fact data set instance. /// </summary> public SpeciesFactDataSet() { Factors = new FactorList(true); Hosts = new TaxonList(true); IndividualCategories = new IndividualCategoryList(true); Periods = new PeriodList(true); References = new ReferenceList(true); _selection = new SpeciesFactDataSetSelection(); _selectionCopy = new SpeciesFactDataSetSelection(); SpeciesFacts = new SpeciesFactList(); Taxa = new TaxonList(true); }
/// <summary> /// Remove factors, hosts, individual categories, periods or /// taxa from current species fact data set scope. /// The species facts in the data set are updated /// to the new species fact data set scope. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="selection">Changed scope of the data set.</param> public virtual void RemoveSelection(IUserContext userContext, ISpeciesFactDataSetSelection selection) { FactorList factors; IndividualCategoryList individualCategories; PeriodList periods; ReferenceList references; TaxonList hosts, taxa; // Check arguments. selection.CheckNotNull("selection"); // Update selection with existing scope. factors = new FactorList(); factors.Merge(_selection.Factors); factors.Remove(selection.Factors); selection.Factors = factors; hosts = new TaxonList(); hosts.Merge(_selection.Hosts); hosts.Remove(selection.Hosts); selection.Hosts = hosts; individualCategories = new IndividualCategoryList(); individualCategories.Merge(_selection.IndividualCategories); individualCategories.Remove(selection.IndividualCategories); selection.IndividualCategories = individualCategories; periods = new PeriodList(); periods.Merge(_selection.Periods); periods.Remove(selection.Periods); selection.Periods = periods; references = new ReferenceList(); references.Merge(_selection.References); references.Remove(selection.References); selection.References = references; taxa = new TaxonList(); taxa.Merge(_selection.Taxa); taxa.Remove(selection.Taxa); selection.Taxa = taxa; // Update species fact data set. UpdateSelection(userContext, selection); }
/// <summary> /// Reset species fact data set to no species facts. /// This method is used when species fact data set selection /// does not contain both factors and taxa. /// </summary> /// <param name="selection"> /// Scope of the data set is defined by this /// species fact data set selection. /// </param> private void Reset(ISpeciesFactDataSetSelection selection) { Factors = new FactorList(true); Factors.Merge(selection.Factors); Hosts = new TaxonList(true); Hosts.Merge(selection.Hosts); IndividualCategories = new IndividualCategoryList(true); IndividualCategories.Merge(selection.IndividualCategories); Periods = new PeriodList(true); Periods.Merge(selection.Periods); References = new ReferenceList(true); References.Merge(selection.References); SpeciesFacts = new SpeciesFactList(true); Taxa = new TaxonList(); Taxa.Merge(selection.Taxa); // Save selection information. _selection = (ISpeciesFactDataSetSelection)(selection.Clone()); _selectionCopy = (ISpeciesFactDataSetSelection)(selection.Clone()); }
/// <summary> /// Get specified references. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="referenceIds">Reference ids.</param> /// <returns>Specified references.</returns> public override ReferenceList GetReferences(IUserContext userContext, List <Int32> referenceIds) { ReferenceList cachedReferences, loadedReferences, references; List <Int32> notCachedReferenceIds; cachedReferences = GetReferences(userContext, userContext.Locale); notCachedReferenceIds = new List <Int32>(); foreach (Int32 referenceId in referenceIds) { if (!cachedReferences.Contains(referenceId)) { notCachedReferenceIds.Add(referenceId); } } loadedReferences = new ReferenceList(); if (notCachedReferenceIds.IsNotEmpty()) { loadedReferences = base.GetReferences(userContext, notCachedReferenceIds); SetReferences(userContext, loadedReferences, userContext.Locale); } // Create output. references = new ReferenceList(); foreach (Int32 referenceId in referenceIds) { if (cachedReferences.Contains(referenceId)) { references.Add(cachedReferences.Get(referenceId)); } else { references.Add(loadedReferences.Get(referenceId)); } } return(references); }
/// <summary> /// Search for a reference. /// </summary> /// <param name="searchString"> /// </param> /// <returns> /// The <see cref="List"/>. /// </returns> public List <ReferenceViewModel> SearchReference(string searchString) { IReferenceSearchCriteria searchCriteria = new ReferenceSearchCriteria(); searchCriteria.LogicalOperator = LogicalOperator.Or; int year; if (int.TryParse(searchString, out year)) { searchCriteria.Years = new List <int>(); searchCriteria.Years.Add(year); } searchCriteria.NameSearchString = new StringSearchCriteria { SearchString = searchString, CompareOperators = new List <StringCompareOperator> { StringCompareOperator.Contains } }; searchCriteria.TitleSearchString = new StringSearchCriteria { SearchString = searchString, CompareOperators = new List <StringCompareOperator> { StringCompareOperator.Contains } }; ReferenceList list = CoreData.ReferenceManager.GetReferences(user, searchCriteria); List <ReferenceViewModel> references = new List <ReferenceViewModel>(); foreach (IReference reference in list) { // todo - handle Year null value references.Add(new ReferenceViewModel(reference.Id, reference.Name, reference.Year.GetValueOrDefault(), reference.Title)); } return(references); }
/// <summary> /// Get references for specified locale. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="locale">Currently used locale.</param> /// <returns>References for specified locale.</returns> protected virtual ReferenceList GetReferences(IUserContext userContext, ILocale locale) { ReferenceList references; if (userContext.Transaction.IsNull()) { if (References.ContainsKey(locale.ISOCode)) { references = (ReferenceList)(References[locale.ISOCode]); } else { references = new ReferenceList(); References[locale.ISOCode] = references; } } else { references = new ReferenceList(); } return(references); }
public static List <IReference> GetReferenceList(IUserContext userContext) { ReferenceList referenceList = CoreData.ReferenceManager.GetReferences(userContext); return(referenceList.ToList()); }
/// <summary> /// Update information about which factors, hosts, /// individual categories, periods, references and taxa /// that are used in the species facts. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="selection"> /// Scope of the data set is defined by this /// species fact data set selection. /// </param> /// <param name="speciesFacts">Species facts.</param> private void UpdateScope(IUserContext userContext, ISpeciesFactDataSetSelection selection, SpeciesFactList speciesFacts) { Factors = new FactorList(true); Factors.AddRange(selection.Factors); Hosts = new TaxonList(true); Hosts.AddRange(selection.Hosts); IndividualCategories = new IndividualCategoryList(true); IndividualCategories.AddRange(selection.IndividualCategories); Periods = new PeriodList(true); Periods.AddRange(selection.Periods); References = new ReferenceList(true); Taxa = new TaxonList(true); Taxa.AddRange(selection.Taxa); if (speciesFacts.IsNotEmpty()) { foreach (ISpeciesFact speciesFact in speciesFacts) { Factors.Merge(speciesFact.Factor); if (speciesFact.HasHost) { Hosts.Merge(speciesFact.Host); } IndividualCategories.Merge(speciesFact.IndividualCategory); if (speciesFact.HasPeriod) { Periods.Merge(speciesFact.Period); } if (speciesFact.HasReference) { References.Merge(speciesFact.Reference); } Taxa.Merge(speciesFact.Taxon); } } // Set default values if no values are entered. if (Hosts.IsEmpty()) { Hosts.Add(CoreData.TaxonManager.GetTaxon(userContext, TaxonId.Life)); } if (IndividualCategories.IsEmpty()) { IndividualCategories.Add(CoreData.FactorManager.GetDefaultIndividualCategory(userContext)); } if (Periods.IsEmpty()) { Periods.AddRange(CoreData.FactorManager.GetPeriods(userContext)); } // Sort all lists. Factors.Sort(); Hosts.Sort(); IndividualCategories.Sort(); Periods.Sort(); References.Sort(); Taxa.Sort(); }