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); }
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); }
private void AddSearchResults(IList <ITaxonName> taxonNames) { for (int i = 0; i < taxonNames.Count; i++) { ITaxonName taxonName = taxonNames[i]; Add(TaxonSearchResultItem.CreateTaxonSearchResultItem(taxonName, taxonName.Taxon)); } }
public void GetTaxonNameById() { //Int32 taxonNameId = 114601; // Omocestus ventralis Int32 taxonNameId = 70397; // Omocestus ventralis ITaxonName taxonName = GetTaxonDataSource(true).GetTaxonName(GetUserContext(), taxonNameId); Assert.IsNotNull(taxonName.Taxon); Assert.IsNotNull(taxonName.Taxon.Id); }
/// <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(); } } }
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); }
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(); } }
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; } }
public TaxonNameViewModel(ITaxonName taxonName, ITaxon taxon) { this.Version = taxonName.Version; this.TaxonCategorySortOrder = taxon.Category.SortOrder; this.GUID = taxonName.Guid; this.Name = taxonName.Name; this.Author = taxonName.Author ?? ""; this.CategoryName = taxonName.Category.Name; this.NameStatus = taxonName.Status.Name; this.IsOriginal = taxonName.IsOriginalName; this.IsRecommended = taxonName.IsRecommended; this.CategoryId = taxonName.Category.Id; }
/// <summary> /// Creates a search result item from an ITaxonName. /// </summary> /// <param name="taxonName">Taxon name object.</param> /// <returns></returns> public static TaxonSearchResultItemViewModel CreateFromTaxonName(ITaxonName taxonName) { var model = new TaxonSearchResultItemViewModel(); ITaxon taxon = taxonName.Taxon; model.NameCategory = taxonName.Category.Name; model.Author = taxon.Author.IsNotEmpty() ? taxon.Author : ""; model.TaxonId = taxonName.Taxon.Id; model.SearchMatchName = taxonName.Name; model.ScientificName = taxon.ScientificName.IsNotEmpty() ? taxon.ScientificName : ""; model.CommonName = taxon.CommonName.IsNotEmpty() ? taxon.CommonName : ""; model.Category = taxon.Category != null ? taxon.Category.Name : ""; model.TaxonStatus = (TaxonAlertStatusId)taxon.AlertStatus.Id; return(model); }
public static TaxonSearchResultItem CreateTaxonSearchResultItem(ITaxonName taxonName, ITaxon taxon) { var model = new TaxonSearchResultItem(); model.NameCategory = taxonName.Category.Name; model.Author = taxon.Author.IsNotEmpty() ? taxon.Author : ""; model.TaxonId = taxonName.Taxon.Id; model.SearchMatchName = taxonName.Name; model.SearchMatchAuthor = taxonName.Author; model.ScientificName = taxon.ScientificName.IsNotEmpty() ? taxon.ScientificName : ""; model.CommonName = taxon.CommonName.IsNotEmpty() ? taxon.CommonName : ""; model.Category = taxon.Category != null ? taxon.Category.Name : ""; model.StatusImageUrl = GetStatusImageUrl(taxon); return(model); }
/// <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); }
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); }
public TaxonNameEditingViewModel(ITaxonName taxonName, bool isPossibleToChangeToRecomended) { this.taxonName = taxonName; this.IsRecommended = taxonName.IsRecommended; this.IsPossibleToChangeRecomended = isPossibleToChangeToRecomended; if (taxonName.Status.Id != (Int32)TaxonNameStatusId.ApprovedNaming) { this.IsPossibleToChangeRecomended = false; } this.IsOkForObsSystems = taxonName.IsOkForSpeciesObservation; this.taxonNameKey = new TaxonNameKey(this.CategoryId, this.Version); this.IsRemoved = false; if (taxonName.Status.Id == (Int32)TaxonNameStatusId.Removed) { this.IsRemoved = true; } }
/// <summary> /// Determines whether the specified taxon name is ok to show to the user on the Info page. /// </summary> /// <param name="taxonName">Taxon name.</param> /// <param name="isInRevision">if set to <c>true</c> the session is in revision mode.</param> /// <param name="isEditorUser">if set to <c>true</c> the user is taxon editor.</param> /// <returns><c>true</c> if the name is ok to show; otherwise <c>false</c>.</returns> private static bool IsNameOkToShow(ITaxonName taxonName, bool isInRevision, bool isEditorUser) { // Name with status [Removed] is only visible inside revisions. // if (!isInRevision && taxonName.Status.Id == (int)TaxonNameStatusId.Removed) if (taxonName.Status.Id == (int)TaxonNameStatusId.Removed) { return(false); } // Name with status [Preliminary] is only visible inside revisions or for logged in taxon editor. if (!isInRevision && !isEditorUser && taxonName.Status.Id == (int)TaxonNameStatusId.PreliminarySuggestion) { return(false); } return(true); }
public TaxonNameInfoViewModel GetInfoViewModel(string guid) { var model = new TaxonNameInfoViewModel(); ITaxonName taxonName = CoreData.TaxonManager.GetTaxonName(_user, guid); model.GUID = taxonName.Guid; model.Comment = taxonName.Description; model.Name = taxonName.Name; model.NameCategory = taxonName.Category.Name; // DyntaxaCachedSettings.Instance.GetTaxonNameCategoryById(_user, taxonName.NameCategory.) model.NameUsage = taxonName.NameUsage.Name; model.NameStatus = taxonName.Status.Name; model.IsOriginal = taxonName.IsOriginalName; model.IsRecommended = taxonName.IsRecommended; model.IsOkForSpeciesObservation = taxonName.IsOkForSpeciesObservation; model.IsUnique = taxonName.IsUnique; model.Modified = taxonName.ModifiedDate.ToShortDateString() + " (" + taxonName.ModifiedByPerson + ")"; model.Author = taxonName.Author; return(model); }
public static ExportName Create(ITaxonName taxonName, ITaxon taxon) { var model = new ExportName(); model.IsChecked = false; model.Name = taxonName.Name; model.Author = taxonName.Author; model.NameTypeId = taxonName.Category.Id; model.NameType = taxonName.Category.Name; model.NameUseId = taxonName.Status.Id; model.NameUse = taxonName.Status.Name; model.IsRecommended = taxonName.IsRecommended; model.NameTaxonCategory = taxon.Category.Name; model.TaxonId = taxonName.Taxon.Id; model.RecommendedScientificName = taxon.ScientificName; model.RecommendedAuthor = taxon.Author; model.RecommendedCommonName = taxon.GetCommonNameOrDefault(""); model.TaxonCategory = taxon.Category.Name; model.TaxonCategoryId = taxon.Category.Id; return(model); }
public ActionResult Edit(TaxonNameDetailsViewModel model) { int taxonId = this.TaxonIdentifier.Id.Value; ITaxon taxon = CoreData.TaxonManager.GetTaxon(GetCurrentUser(), model.TaxonId); _taxonNameViewManager.InitTaxonNameDetails(model, taxon); ValidateTaxon(GetCurrentUser(), taxonId); // Only Nomenclature: Correct, Provisional, PreliminarySuggestion or Informal names may have usage: Accepted. if (model.SelectedTaxonNameUsageId == (int)TaxonNameUsageId.Accepted && !(model.SelectedTaxonNameStatusId == (int)TaxonNameStatusId.ApprovedNaming || model.SelectedTaxonNameStatusId == (int)TaxonNameStatusId.Provisional || model.SelectedTaxonNameStatusId == (int)TaxonNameStatusId.PreliminarySuggestion || model.SelectedTaxonNameStatusId == (int)TaxonNameStatusId.Informal)) { ModelState.AddModelError("", Resources.DyntaxaResource.TaxonNameAddEditIncorrectNomencalture); } //// Only usage: Accepted may have Recommended: Yes. //if (!model.IsRecommended && model.SelectedTaxonNameUsageId == (int)TaxonNameUsageId.Accepted) //{ // ModelState.AddModelError("", "Only usage: Accepted may have Recommended: Yes."); //} if (ModelState.IsValid) { ITaxonName taxonName = _taxonNameViewManager.SaveTaxonNameDetailsChanges(model, taxonId, this.TaxonRevision); this.RedrawTree(); // Must set new value since taxon name is updated for every save... return(RedirectToAction("Edit", new { @taxonId = model.TaxonId, @nameId = taxonName.Version.ToString() })); } else { return(View("Edit", model)); } }
public SynonymName(ITaxonName taxonName, ITaxon taxon) : base(taxonName, taxon) { }
public static TaxonNameDetailsViewModel Create(IUserContext userContext, ITaxonName taxonName) { var model = new TaxonNameDetailsViewModel(); model.TaxonId = taxonName.Taxon.Id; if (taxonName.Id == 0) { model.Id = taxonName.Version; } else { model.Id = taxonName.Id; } model.Name = taxonName.Name; model.Comment = taxonName.Description; model.Author = taxonName.Author; model.SelectedCategoryId = taxonName.Category.Id; model.SelectedTaxonNameStatusId = taxonName.Status.Id; model.SelectedTaxonNameUsageId = taxonName.NameUsage.Id; model.NameStatusText = taxonName.Status.Name; model.NameUsageText = taxonName.NameUsage.Name; model.IsRecommended = taxonName.IsRecommended; model.IsNotOkForObsSystem = !taxonName.IsOkForSpeciesObservation; model.Version = taxonName.Version.ToString(); model.IsOriginal = taxonName.IsOriginalName; model.CategoryName = taxonName.Category.Name; model.LastUpdated = taxonName.ModifiedDate; //// Set "modified by user". CoreData.UserManager.GetUser is a slow operation, so we store each entry in a dictionary. //IUser modifiedByUser; //if (dicLoadedUsers == null) //{ // dicLoadedUsers = new Dictionary<int, IUser>(); //} //if (!dicLoadedUsers.ContainsKey(taxonName.ModifiedBy)) //{ // modifiedByUser = CoreData.UserManager.GetUser(CoreData.UserManager.GetCurrentUser(), taxonName.ModifiedBy); // dicLoadedUsers.Add(taxonName.ModifiedBy, modifiedByUser); //} //else //{ // modifiedByUser = dicLoadedUsers[taxonName.ModifiedBy]; //} model.UpdatedBy = taxonName.ModifiedByPerson; if (taxonName.Guid.IsNotNull()) { model.TaxonNameGuid = taxonName.Guid; } model.TaxonNameReferencesList = new List <int>(); model.NoOfTaxonNameReferences = 0; if (taxonName.GetReferences(userContext).IsNotEmpty()) { foreach (ReferenceRelation referenceRelation in taxonName.GetReferences(userContext)) { model.NoOfTaxonNameReferences++; } } return(model); }
public void CreateTaxonName(IUserContext userContext, ITaxonName taxonName) { taxonName.Id = DyntaxaTestSettings.Default.TestTaxonNameId; return; }
private static string GetTaxonNameDescription(ITaxonName taxonName) { return(taxonName == null ? "" : taxonName.Name); }