/// <summary> /// Tries to parce a valid taxon from the route data. /// </summary> /// <param name="urlParams">The URL params.</param> /// <param name="taxon">The taxon.</param> /// <param name="pageIndex">Index of the page.</param> /// <returns></returns> public bool TryMatch(string[] urlParams, out ITaxon taxon, out int pageIndex) { taxon = null; pageIndex = 1; if (urlParams == null || urlParams.Length < 3) { return false; } string url = string.Join(@"/", urlParams); if (!this.taxonomyEvaluator.TryGetTaxonFromUrl(url, out taxon)) { return false; } if (!this.IsFlatTaxon(taxon)) { return true; } bool hasPageIndex = this.TryGetLastPageIndex(urlParams, out pageIndex); return this.CheckForValidFlatTaxonUrl(urlParams, hasPageIndex); }
public TaxonViewModel(ITaxon taxon, uint count) { this.Count = count; this.Title = taxon.Title; this.SubTaxa = new List<TaxonViewModel>(); }
private void SetControllerActionParams(RequestContext requestContext, ITaxon taxon, int pageIndex) { requestContext.RouteData.Values[UrlParamsMapperBase.ActionNameKey] = this.actionName; foreach (ParameterInfo paramInfo in this.actionMethod.GetParameters()) { if (paramInfo.ParameterType == typeof(ITaxon)) { requestContext.RouteData.Values[paramInfo.Name] = taxon; } else if (paramInfo.ParameterType == typeof(int?) && pageIndex > 0) { requestContext.RouteData.Values[paramInfo.Name] = pageIndex; } } }
/// <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); }
/// <summary> /// Creates a view model for use in list views. /// </summary> /// <param name="taxonFilter">The taxon filter.</param> /// <param name="page">The page.</param> /// <returns>A view model for use in list views.</returns> /// <exception cref="System.ArgumentException">'page' argument has to be at least 1.;page</exception> public virtual ContentListViewModel CreateListViewModel(ITaxon taxonFilter, int page) { if (page < 1) { throw new ArgumentException("'page' argument has to be at least 1.", "page"); } var viewModel = this.CreateListViewModelInstance(); viewModel.UrlKeyPrefix = this.UrlKeyPrefix; var query = this.GetItemsQuery(); if (query == null) { return(viewModel); } if (taxonFilter != null) { var taxonomy = taxonFilter.Taxonomy.RootTaxonomy ?? taxonFilter.Taxonomy; string taxonomyField; if (this.TryGetTaxonomyFieldName(taxonomy.Id, out taxonomyField)) { var filter = string.Format(CultureInfo.InvariantCulture, "{0}.Contains({{{1}}})", taxonomyField, taxonFilter.Id); query = query.Where(filter); } else { viewModel.Items = Enumerable.Empty <ItemViewModel>(); this.SetViewModelProperties(viewModel, page, null); return(viewModel); } } this.PopulateListViewModel(page, query, viewModel); return(viewModel); }
///// <summary> ///// Gets a picture from the pictureservice by using the pictureid ///// </summary> ///// <param name="pictureId"></param> ///// <param name="pictureHeight">Height of returned picture.</param> ///// <param name="pictureWidth">Width of returned picture.</param> ///// <param name="requestedPictureSize">Requested size of returned picture.</param> ///// <param name="isRequestedPictureSizeSpecified">Is requested size of returned picture specified.</param> ///// <param name="requestedFormat">Requested format of returned picture.</param> ///// <returns></returns> //public string GetPictureByPictureId(int pictureId, // int pictureHeight, // int pictureWidth, // long requestedPictureSize, // bool isRequestedPictureSizeSpecified, // string requestedFormat) //{ // IPicture picture; // try // { // picture = CoreData.PictureManager.GetPicture(mUserContext, // pictureId, // pictureHeight, // pictureWidth, // requestedPictureSize, // isRequestedPictureSizeSpecified, // requestedFormat); // } // catch (Exception ex) // { // throw new TaxonSpeciesFactManagerException(RedListResource.FailedToGetPictureFromPictureService, ex); // } // return picture == null ? null : picture.Image; //} ///// <summary> ///// Gets a picture by the given taxon id. ///// </summary> ///// <param name="taxon">The taxon to use to retrieve a recommended picture.</param> ///// <returns>The picture object.</returns> //public string GetPictureByTaxon(ITaxon taxon) //{ // long pictureId; // return GetPictureByTaxon(taxon, // AppSettings.Default.PictureXtraLargeHeight, // AppSettings.Default.PictureXtraLargeWidth, // 0, // false, // string.Empty, // out pictureId); //} /// <summary> /// Get picture by taxon and requested picture related properties. /// </summary> /// <param name="taxon">Taxon that expects to be related to picture.</param> /// <param name="pictureHeight">Height of returned picture.</param> /// <param name="pictureWidth">Width of returned picture.</param> /// <param name="requestedPictureSize">Requested size of returned picture.</param> /// <param name="isRequestedPictureSizeSpecified">Is requested size of returned picture specified.</param> /// <param name="requestedFormat">Requested format of returned picture.</param> /// <param name="pictureId">Id for uploded image. Will also be returned from this method.</param> /// <returns>Picture as binary string.</returns> public string GetPictureByTaxon( ITaxon taxon, int pictureHeight, int pictureWidth, long requestedPictureSize, bool isRequestedPictureSizeSpecified, string requestedFormat, out long pictureId) { IPictureRelationType pictureRelationType = CoreData.PictureManager.GetPictureRelationType(mUserContext, PictureRelationTypeIdentifier.TaxonRedList); PictureRelationList pictureRelations = CoreData.PictureManager.GetPictureRelations(mUserContext, taxon, pictureRelationType); pictureId = 0; if (pictureRelations.IsNotNull()) { IPictureRelation pictureRelation = pictureRelations.FirstOrDefault(r => r.IsRecommended); if (pictureRelation.IsNotNull()) { if (pictureRelation != null) { IPicture taxonPicture = CoreData.PictureManager.GetPicture( mUserContext, pictureRelation.PictureId, pictureHeight, pictureWidth, requestedPictureSize, isRequestedPictureSizeSpecified, requestedFormat); if (taxonPicture.IsNotNull()) { pictureId = taxonPicture.Id; } return(taxonPicture.Image); } } } return(null); }
/// <inheritdoc /> public override ContentListViewModel CreateListViewModel(ITaxon taxonFilter, int page) { if (page < 1) { throw new ArgumentException("'page' argument has to be at least 1.", "page"); } var query = this.GetItemsQuery(); if (query == null) { return(this.CreateListViewModelInstance()); } var viewModel = this.CreateListViewModelInstance(); viewModel.UrlKeyPrefix = this.UrlKeyPrefix; this.PopulateListViewModel(page, query, viewModel); foreach (var listModel in viewModel.Items.Cast <ListViewModel>()) { var listItemModel = new ListItemModel(listModel) { SortExpression = this.SortExpression, FilterExpression = this.FilterExpression, SerializedAdditionalFilters = this.SerializedAdditionalFilters, // We need only filter list items. SelectionMode = SelectionMode.FilteredItems, ProviderName = this.ProviderName, ItemsPerPage = null, UrlKeyPrefix = this.UrlKeyPrefix }; listModel.ListItemViewModel = listItemModel.CreateListViewModel(taxonFilter, page); } return(viewModel); }
public ActionResult List(string[] isNotOkForObs, string[] isRecommended) { ITaxon taxon = TaxonSearchManager.GetTaxonById(TaxonIdentifier.Id.Value); var model = new ListTaxonNameViewModel(taxon, this.TaxonRevision); //todo change revisionId ValidateTaxon(GetCurrentUser(), taxon.Id); TaxonNameList changedTaxonNames = model.GetChangedTaxonNames(isNotOkForObs, isRecommended); // Only usage: Accepted may have Recommended: Yes. foreach (ITaxonName taxonName in changedTaxonNames) { if (taxonName.IsRecommended && taxonName.NameUsage.Id != (int)TaxonNameUsageId.Accepted) { ModelState.AddModelError("", Resources.DyntaxaResource.TaxonNameListWrongNameUsage); break; } } if (ModelState.IsValid) { if (changedTaxonNames.Count > 0) { IUserContext loggedInUser = GetLoggedInUser(); using (ITransaction transaction = loggedInUser.StartTransaction()) { CoreData.TaxonManager.UpdateTaxonNames(loggedInUser, this.TaxonRevision, changedTaxonNames); transaction.Commit(); } } RedrawTree(); return(RedirectToAction("List")); } ViewBag.Taxon = taxon; return(View(model)); }
/// <summary> /// Get taxon information about specified taxon. /// Returned taxon has the same order id as the input taxon id. /// </summary> /// <param name="taxon">Taxon to get chached information on.</param> /// <returns>Taxon list information about specified taxa.</returns> public TaxonListInformation GetTaxonInformationFromCache(ITaxon taxon) { if (!mIsInitialized) { throw new Exception("TaxonListInformation cache is not initialized"); } TaxonListInformation tempTaxon = null; if (TaxonInformationCache.TaxonInformation.IsNotNull() && TaxonInformationCache.TaxonInformation.ContainsKey(taxon.Id) && taxon.IsNotNull()) { var taxa = new TaxonList { taxon }; // Check is performed on list therefore a temporary list is created with one item. CheckCachedInformation(taxa); tempTaxon = TaxonInformationCache.TaxonInformation[taxon.Id]; } return(tempTaxon); }
/// <summary> /// Renders appropriate list view depending on the <see cref="ListTemplateName" /> /// </summary> /// <param name="taxonFilter">The taxonomy filter.</param> /// <param name="page">The page.</param> /// <returns> /// The <see cref="ActionResult" />. /// </returns> public ActionResult ListByTaxon(ITaxon taxonFilter, int?page) { var fullTemplateName = this.listTemplateNamePrefix + this.ListTemplateName; this.ViewBag.CurrentPageUrl = this.GetCurrentPageUrl(); this.ViewBag.RedirectPageUrlTemplate = this.ViewBag.CurrentPageUrl + UrlHelpers.GetRedirectPagingUrl(taxonFilter); this.ViewBag.DetailsPageId = this.DetailsPageId; this.ViewBag.OpenInSamePage = this.OpenInSamePage; var viewModel = this.Model.CreateListViewModel(taxonFilter, page ?? 1); if (SystemManager.CurrentHttpContext != null) { this.AddCacheDependencies(this.Model.GetKeysOfDependentObjects(viewModel)); if (viewModel.ContentType != null) { this.AddCacheVariations(viewModel.ContentType, viewModel.ProviderName); } } return(this.View(fullTemplateName, viewModel)); }
public void NewsWidget_SelectByTagNewsFunctionalityAndLimits() { var newsController = new NewsController(); newsController.Model.DisplayMode = ListDisplayMode.Limit; newsController.Model.ItemsPerPage = 1; string tagTitle = "Tag1"; string newsTitle = "News "; try { Guid taxonId = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, tagTitle); Guid newsId0 = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 0); this.serverOperationsNews.AssignTaxonToNewsItem(newsId0, "Tags", taxonId); Guid newsId1 = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 1); this.serverOperationsNews.AssignTaxonToNewsItem(newsId1, "Tags", taxonId); ITaxon tagTaxonomy = TaxonomyManager.GetManager().GetTaxon(taxonId); var items = newsController.Model.CreateListViewModel(tagTaxonomy, 1).Items.ToArray(); Assert.IsTrue(items.Length.Equals(1), "The count of news items is not correct - limit applied"); Assert.IsTrue(items[0].Fields.Title.Equals(newsTitle + 1, StringComparison.CurrentCulture), "The news with this title was found!"); newsController.Model.DisplayMode = ListDisplayMode.Paging; newsController.Model.ItemsPerPage = 20; items = newsController.Model.CreateListViewModel(tagTaxonomy, 1).Items.ToArray(); Assert.IsTrue(items.Length.Equals(2), "The count of news items is not correct - all items"); Assert.IsTrue(items[0].Fields.Title.Equals(newsTitle + 1, StringComparison.CurrentCulture), "The news with this title was found!"); Assert.IsTrue(items[1].Fields.Title.Equals(newsTitle + 0, StringComparison.CurrentCulture), "The news with this title was found!"); } finally { this.serverOperationsTaxonomies.DeleteTags(tagTitle); } }
/// <summary> /// Creates a view model for Taxon Move Change names /// </summary> /// <param name="oldParentTaxonId"></param> /// <param name="newParentTaxonId"></param> /// <param name="selectedChildTaxaToMove"></param> /// <returns></returns> public TaxonMoveChangeNameViewModel CreateTaxonMoveChangeNameViewModel(int oldParentTaxonId, int newParentTaxonId, List <int> selectedChildTaxaToMove) { TaxonMoveChangeNameViewModel model = new TaxonMoveChangeNameViewModel(); var newParentTaxon = CoreData.TaxonManager.GetTaxon(_user, newParentTaxonId); var oldParentTaxon = CoreData.TaxonManager.GetTaxon(_user, oldParentTaxonId); model.SelectedChildTaxaToMove = selectedChildTaxaToMove; // MovedChildTaxons var dicItems = new Dictionary <ITaxon, List <ChangeNameItem> >(); model.MovedChildTaxons = new List <ChangeNameItem>(); foreach (int taxonId in selectedChildTaxaToMove) { ITaxon taxon = CoreData.TaxonManager.GetTaxon(_user, taxonId); dicItems.Add(taxon, new List <ChangeNameItem>()); ChangeNameItem parentItem = ChangeNameItem.CreateChangeNameItem(taxon, taxon, oldParentTaxon, newParentTaxon, _user); model.MovedChildTaxons.Add(parentItem); dicItems[taxon].Add(parentItem); foreach (var taxonRelation in taxon.GetChildTaxonRelations(_user, true, false)) { ChangeNameItem item = ChangeNameItem.CreateChangeNameItem(taxonRelation.ChildTaxon, taxon, oldParentTaxon, newParentTaxon, _user); model.MovedChildTaxons.Add(item); dicItems[taxon].Add(item); } } model.NewParentTaxonId = newParentTaxon.Id; model.OldParentTaxonId = oldParentTaxon.Id; // end constructor model.TaxonId = oldParentTaxon.Id; model.OldParentDescription = oldParentTaxon.ScientificName; model.NewParentDescription = newParentTaxon.ScientificName; model.MovedTaxonsDescription = dicItems.Keys.Select(taxon => taxon.ScientificName).ToList(); return(model); }
public void CountyMapFirstConstructorTest() { IUserContext userContext = LoginTestUser(); ITaxon taxon = CoreData.TaxonManager.GetTaxon(userContext, 101656); string shapeFileName = Path.Combine(AbsoluteResourceFolderPath, "Sverigekarta med län.shp"); Console.WriteLine("Reading file: {0}", shapeFileName); CountyOccurrenceMap.InitializeMap(shapeFileName); CountyOccurrenceMap countyOccurenceMap = new CountyOccurrenceMap(userContext, taxon); string image1Path = Path.Combine(AbsoluteTempFolderPath, "testMapWithLegend.png"); Console.WriteLine("Generating image: {0}", image1Path); countyOccurenceMap.Save(image1Path, System.Drawing.Imaging.ImageFormat.Png); countyOccurenceMap.Height = 200; string image2Path = Path.Combine(AbsoluteTempFolderPath, "testHeight200MapWithLegend.png"); Console.WriteLine("Generating image: {0}", image2Path); countyOccurenceMap.Save(image2Path, System.Drawing.Imaging.ImageFormat.Png); }
/// <summary> /// Renders appropriate list view depending on the <see cref="ListTemplateName" /> /// </summary> /// <param name="page">The page.</param> /// <returns> /// The <see cref="ActionResult" />. /// </returns> public ActionResult Index(int?page) { ITaxon taxonFilter = TaxonUrlEvaluator.GetTaxonFromQuery(this.HttpContext, this.Model.UrlKeyPrefix); var fullTemplateName = this.listTemplateNamePrefix + this.ListTemplateName; this.ViewBag.CurrentPageUrl = this.GetCurrentPageUrl(); this.ViewBag.RedirectPageUrlTemplate = this.ViewBag.CurrentPageUrl + "/{0}"; this.ViewBag.DetailsPageId = this.DetailsPageId; this.ViewBag.OpenInSamePage = this.OpenInSamePage; this.SetRedirectUrlQueryString(taxonFilter); var viewModel = this.Model.CreateListViewModel(taxonFilter: taxonFilter, page: page ?? 1); if (SystemManager.CurrentHttpContext != null) { this.AddCacheDependencies(this.Model.GetKeysOfDependentObjects(viewModel)); } return(this.View(fullTemplateName, viewModel)); }
/// <summary> /// Tries to parce a valid taxon from the route data. /// </summary> /// <param name="urlParams">The URL params.</param> /// <param name="urlKeyPrefix">The URL key prefix.</param> /// <param name="taxon">The taxon.</param> /// <param name="pageIndex">Index of the page.</param> /// <param name="requestContext">The reqy.</param> /// <returns></returns> public bool TryMatch(string[] urlParams, string urlKeyPrefix, out ITaxon taxon, out int pageIndex, RequestContext requestContext = null) { taxon = null; pageIndex = 1; if (urlParams == null || urlParams.Length < 3) { if (requestContext == null) { return(false); } taxon = TaxonUrlEvaluator.GetTaxonFromQuery(requestContext.HttpContext, null); if (urlParams != null && taxon != null) { this.TryGetPageIndex(urlParams, out pageIndex, taxon.Name); } return(taxon != null); } string url = string.Join(@"/", urlParams); if (!this.taxonomyEvaluator.TryGetTaxonFromUrl(url, urlKeyPrefix, out taxon)) { return(false); } bool hasPageIndex = this.TryGetPageIndex(urlParams, out pageIndex, taxon.Name); if (!this.IsFlatTaxon(taxon)) { return(true); } return(this.CheckForValidFlatTaxonUrl(urlParams, hasPageIndex)); }
public void NewsWidget_SelectByTagNewsFunctionality() { int newsCount = 2; Guid[] taxonId = new Guid[newsCount]; Guid[] newsId = new Guid[newsCount]; string newsTitle = "News "; string tagTitle = "Tag "; var newsController = new NewsController(); string[] tagTitles = new string[newsCount]; try { for (int i = 0; i < newsCount; i++) { taxonId[i] = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, tagTitle + i); tagTitles[i] = tagTitle + i; newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + i); this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Tags", taxonId[i]); } for (int i = 0; i < newsCount; i++) { ITaxon taxonomy = TaxonomyManager.GetManager().GetTaxon(taxonId[i]); var items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray(); for (int j = 0; j < items.Length; j++) { Assert.IsTrue(items[j].Fields.Title.Equals(newsTitle + i, StringComparison.CurrentCulture), "The news with this title was not found!"); } } } finally { this.serverOperationsTaxonomies.DeleteTags(tagTitles); } }
/// <summary> /// Renders appropriate list view depending on the <see cref="ListTemplateName" /> /// </summary> /// <param name="taxonFilter">The taxonomy filter.</param> /// <param name="page">The page.</param> /// <returns> /// The <see cref="ActionResult" />. /// </returns> public ActionResult ListByTaxon(ITaxon taxonFilter, int?page) { if (taxonFilter != null) { var redirectPageUrlTemplate = UrlHelpers.GetRedirectPagingUrl(taxonFilter); this.InitializeListViewBag(redirectPageUrlTemplate); } var viewModel = this.Model.CreateListViewModel(taxonFilter, page ?? 1); if (SystemManager.CurrentHttpContext != null) { this.AddCacheDependencies(this.Model.GetKeysOfDependentObjects(viewModel)); if (viewModel.ContentType != null) { this.AddCacheVariations(viewModel.ContentType, viewModel.ProviderName); } } var fullTemplateName = this.FullListTemplateName(); return(this.View(fullTemplateName, viewModel)); }
private async Task ReplyAddTaxonAsync(TaxonRankType rank, string taxonName, string description) { // Make sure that the taxon does not already exist before trying to add it. ITaxon taxon = (await Db.GetTaxaAsync(taxonName, rank)).FirstOrDefault(); if (taxon.IsValid()) { await ReplyWarningAsync($"The {rank.GetName()} **{taxon.GetName()}** already exists."); } else { taxon = new Common.Taxa.Taxon(rank, taxonName) { Name = taxonName, Description = description }; await Db.AddTaxonAsync(taxon); await ReplySuccessAsync($"Successfully created new {rank.GetName()}, **{taxon.GetName()}**."); } }
/// <summary> /// Get all taxon names for taxon. /// </summary> /// <param name="userContext">The user context.</param> /// <param name="taxon">The taxon.</param> /// <returns>All taxon names for taxon.</returns> public override TaxonNameList GetTaxonNames(IUserContext userContext, ITaxon taxon) { TaxonNameList taxonNames; if (userContext.CurrentRole.IsNotNull() && userContext.CurrentRole.Identifier.IsNotEmpty() && userContext.CurrentRole.Identifier.StartsWith(Settings.Default.DyntaxaRevisionRoleIdentifier)) { // Do not cache taxon names if user is in a revision. taxonNames = base.GetTaxonNames(userContext, taxon); } else { taxonNames = GetTaxonNames(taxon, userContext.Locale); if (taxonNames.IsNull()) { taxonNames = base.GetTaxonNames(userContext, taxon); SetTaxonNames(taxonNames, taxon, userContext.Locale); } } return(taxonNames); }
public ActionResult Subscriptions(string taxonId) { if (taxonId.IsNull()) { taxonId = this.TaxonIdentifier.Id.ToString(); } TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId)); } TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ITaxon taxon = searchResult.Taxon; ViewBag.Taxon = taxon; SubscriptionViewManager subscriptionViewManager = new SubscriptionViewManager(GetCurrentUser()); SubscriptionsViewModel model = subscriptionViewManager.CreateSubscriptionsViewModel(taxon); return(View(model)); }
/// <summary> /// Gets the common dyntaxa species facts. (SwedishOccurence, SwedishHistory, RedlistCategory) /// Get facts from cache (CommonSpeciesFacts) if they exists. /// </summary> /// <param name="userContext"> /// The user Context. /// </param> /// <param name="taxon"> /// The taxon. /// </param> /// <returns> /// The <see cref="Dictionary"/>. /// </returns> public static Dictionary <FactorId, SpeciesFact> GetCommonDyntaxaSpeciesFacts( IUserContext userContext, ITaxon taxon) { SpeciesFactList speciesFactList; IEnumerable <FactorId> factorIds = new[] { FactorId.SwedishOccurrence, FactorId.SwedishHistory, FactorId.RedlistCategory }; var speciesFactDictionary = GetCommonDyntaxaSpeciesFactsFromCache(taxon.Id); //if (!IsInRevision() && speciesFactDictionary.IsNotNull()) if (speciesFactDictionary.IsNotNull()) { return(speciesFactDictionary); } else { Dictionary <FactorId, SpeciesFact> dic = new Dictionary <FactorId, SpeciesFact>(); dic = GetSpeciesFacts(userContext, taxon, factorIds, out speciesFactList); // Add species facts to cache. AddCommonDyntaxaSpeciesFactsToCache(taxon.Id, dic); return(dic); } }
public TaxonNameCategoryViewModel(ITaxon taxon, ITaxonNameCategory taxonNameCategory, IEnumerable <ITaxonName> names) { this._taxonNameCategory = taxonNameCategory; this._names = new List <TaxonNameEditingViewModel>(); bool possibleToChangeRecommended = false; int noOfRecomended = names.Count(taxonName => taxonName.Status.Id == (Int32)TaxonNameStatusId.ApprovedNaming); if (noOfRecomended > 1 && taxonNameCategory.Id == (Int32)TaxonNameCategoryId.ScientificName) { possibleToChangeRecommended = true; } foreach (ITaxonName taxonName in names) { if (taxonNameCategory.Id != (Int32)TaxonNameCategoryId.ScientificName && taxonName.Status.Id == (Int32)TaxonNameStatusId.ApprovedNaming) { possibleToChangeRecommended = true; } this._names.Add(new TaxonNameEditingViewModel(taxonName, possibleToChangeRecommended)); } }
public TaxonRelationList GetTaxonRelations(IUserContext userContext, ITaxonRelationSearchCriteria searchCriteria) { ITaxon parentTaxon = GetReferenceParentTaxon(userContext, 5398); ITaxon taxon = new Taxon(); taxon.Id = 3897845; taxon.SortOrder = 4; taxon.Category = new TaxonCategory() { Id = 2 }; ITaxonRelation taxonRel = new TaxonRelation() { ParentTaxon = parentTaxon, ValidFromDate = DateTime.Now, ValidToDate = new DateTime(2022, 1, 30), IsMainRelation = true, ReplacedInTaxonRevisionEventId = null, ChildTaxon = taxon, }; TaxonRelationList list = new TaxonRelationList(); list.Add(taxonRel); return(list); }
/// <summary> /// Renders appropriate list view depending on the <see cref="ListTemplateName" /> /// </summary> /// <param name="page">The page.</param> /// <returns> /// The <see cref="ActionResult" />. /// </returns> public ActionResult Index(int? page) { var fullTemplateName = this.listTemplateNamePrefix + this.ListTemplateName; this.ViewBag.CurrentPageUrl = this.GetPageUrl(); this.ViewBag.RedirectPageUrlTemplate = this.ViewBag.CurrentPageUrl + UrlHelpers.GetRedirectPagingUrl(); if (!this.IsEmpty) { ITaxon taxonFilter = TaxonUrlEvaluator.GetTaxonFromQuery(this.HttpContext, this.Model.UrlKeyPrefix); var viewModel = this.Model.CreateListViewModel(taxonFilter: taxonFilter, page: page ?? 1); if (SystemManager.CurrentHttpContext != null) { this.AddCacheDependencies(this.Model.GetKeysOfDependentObjects(viewModel)); if (viewModel.ContentType != null) this.AddCacheVariations(viewModel.ContentType, viewModel.ProviderName); } return this.View(fullTemplateName, viewModel); } return new EmptyResult(); }
public ActionResult Delete(int nameId) { ValidateTaxon(GetCurrentUser(), this.TaxonIdentifier.Id.Value); // Can't delete if the name is scientific and recommended if (!_taxonNameViewManager.CanDeleteName(this.TaxonIdentifier.Id.Value, nameId)) { string errorMsg = Resources.DyntaxaResource.TaxonNameDeleteNotPossibleToDeleteErrorText; ModelState.AddModelError("", errorMsg); } if (ModelState.IsValid) { _taxonNameViewManager.DeleteName(this.TaxonIdentifier.Id.Value, this.TaxonRevision, nameId); return(RedirectToAction("List", new { @taxonId = this.TaxonIdentifier.Id.Value })); } else { ITaxon taxon = CoreData.TaxonManager.GetTaxon(GetCurrentUser(), this.TaxonIdentifier.Id.Value); var model = _taxonNameViewManager.GetViewModel(taxon, nameId); return(View(model)); } }
public static async Task UpdateTaxonAsync(this SQLiteDatabase database, ITaxon taxon) { string tableName = GetTableNameForRank(taxon.GetRank()); if (!string.IsNullOrEmpty(tableName)) { string parentColumnName = GetFieldNameForRank(taxon.GetParentRank()); string updateParentColumnStr = string.Empty; if (!string.IsNullOrEmpty(parentColumnName) && taxon.ParentId.HasValue) { updateParentColumnStr = string.Format(", {0}=$parent_id", parentColumnName); } using (SQLiteCommand cmd = new SQLiteCommand(string.Format("UPDATE {0} SET name = $name, description = $description, pics = $pics{1}, common_name = $common_name WHERE id = $id", tableName, updateParentColumnStr))) { cmd.Parameters.AddWithValue("$id", taxon.Id); cmd.Parameters.AddWithValue("$name", taxon.Name.ToLowerInvariant()); cmd.Parameters.AddWithValue("$description", taxon.Description); cmd.Parameters.AddWithValue("$pics", taxon.GetPictureUrl()); // Because this field was added in a database update, it's possible for it to be null rather than the empty string. cmd.Parameters.AddWithValue("$common_name", string.IsNullOrEmpty(taxon.GetCommonName()) ? "" : taxon.GetCommonName().ToLowerInvariant()); if (!string.IsNullOrEmpty(parentColumnName) && taxon.ParentId.HasValue) { cmd.Parameters.AddWithValue("$parent_column_name", parentColumnName); cmd.Parameters.AddWithValue("$parent_id", taxon.ParentId); } await database.ExecuteNonQueryAsync(cmd); } } }
/// <summary> /// Split taxa /// </summary> /// <param name="loggedInUser"></param> /// <param name="splitTaxonId"></param> /// <param name="taxonRevision"></param> /// <param name="ctrReplaceTaxonIdList"></param> public void SplitTaxon(IUserContext loggedInUser, int?splitTaxonId, ITaxonRevision taxonRevision, List <int?> ctrReplaceTaxonIdList) { ITaxon splitTaxon = null; if (splitTaxonId.IsNotNull()) { splitTaxon = CoreData.TaxonManager.GetTaxon(loggedInUser, (int)splitTaxonId); } TaxonList replacingTaxa = new TaxonList(); foreach (var taxonId in ctrReplaceTaxonIdList) { if (taxonId.IsNotNull()) { replacingTaxa.Add(CoreData.TaxonManager.GetTaxon(loggedInUser, (int)taxonId)); } } using (ITransaction transaction = loggedInUser.StartTransaction()) { CoreData.TaxonManager.SplitTaxon(loggedInUser, splitTaxon, replacingTaxa, taxonRevision); transaction.Commit(); } }
public async Task SetGenus(string genusName, string speciesName, string newGenusName) { // Get the specified species. ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName); if (species.IsValid()) { // Get the specified genus. ITaxon genus = await GetTaxonOrReplyAsync(TaxonRankType.Genus, newGenusName); if (genus.IsValid()) { // Update the species. species.Genus = genus; await Db.UpdateSpeciesAsync(species); await ReplySuccessAsync($"**{species.GetShortName()}** has successfully been assigned to the genus **{genus.GetName().ToTitle()}**."); } } }
public static async Task <ITaxon> GetTaxonAsync(this SQLiteDatabase database, long?id, TaxonRankType rank) { string tableName = GetTableNameForRank(rank); if (string.IsNullOrEmpty(tableName) || !id.HasValue) { return(null); } ITaxon taxon = null; using (SQLiteCommand cmd = new SQLiteCommand(string.Format("SELECT * FROM {0} WHERE id = $id", tableName))) { cmd.Parameters.AddWithValue("$id", id); DataRow row = await database.GetRowAsync(cmd); if (row != null) { taxon = await database.CreateTaxonFromDataRowAsync(row, rank); } } return(taxon); }
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 ActionResult Add(TaxonNameDetailsViewModel model) { ITaxon taxon = CoreData.TaxonManager.GetTaxon(GetCurrentUser(), model.TaxonId); ITaxonName taxonName = new TaxonName(); ITaxonRevision taxonRevision = this.TaxonRevision; _taxonNameViewManager.InitTaxonNameDetails(model, taxon); // 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); } if (!ModelState.IsValid) { return(View("Add", model)); } IUserContext loggedInUser = GetLoggedInUser(); // Creation of taxon name using (ITransaction transaction = loggedInUser.StartTransaction()) { taxonName = _taxonNameViewManager.AddTaxonName(model, TaxonIdentifier.Id.Value, this.TaxonRevision); // Must set default reference, set from Revision.. ReferenceRelationList referencesToAdd = ReferenceHelper.GetDefaultReferences(GetCurrentUser(), taxonName, taxonRevision, null); var referencesToRemove = new ReferenceRelationList(); CoreData.ReferenceManager.CreateDeleteReferenceRelations(GetCurrentUser(), referencesToAdd, referencesToRemove); transaction.Commit(); } return(RedirectToAction("Edit", new { @taxonId = model.TaxonId, @nameId = taxonName.Version })); }
/// <summary> /// The get validity description. /// </summary> /// <param name="taxon"> /// The taxon. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> private static string GetValidityDescription(ITaxon taxon) { string text; if (taxon.IsValid) { if (taxon.Category.IsTaxonomic) { text = DyntaxaResource.TaxonSummaryValitityValueAccepted; } else { text = DyntaxaResource.TaxonSummaryValitityValuePragmatic; } } else { text = DyntaxaResource.TaxonSummaryValitityValueNotValid; var validToInformation = string.Format("{0} ({1})", taxon.ValidToDate.ToShortDateString(), taxon.ModifiedByPerson); text = text + ". " + DyntaxaResource.TaxonSummaryValidToLabel + " " + validToInformation; } return(text); }
public ITaxonName AddTaxonName(TaxonNameDetailsViewModel model, int taxonId, ITaxonRevision taxonRevision) { ITaxon taxon = CoreData.TaxonManager.GetTaxon(_user, taxonId); var taxonName = new ArtDatabanken.Data.TaxonName(); taxonName.DataContext = new DataContext(_user); taxonName.Name = model.Name; taxonName.Author = model.Author; taxonName.Category = CoreData.TaxonManager.GetTaxonNameCategory(_user, model.SelectedCategoryId); taxonName.Status = CoreData.TaxonManager.GetTaxonNameStatus(CoreData.UserManager.GetCurrentUser(), model.SelectedTaxonNameStatusId); taxonName.NameUsage = CoreData.TaxonManager.GetTaxonNameUsage(CoreData.UserManager.GetCurrentUser(), model.SelectedTaxonNameUsageId); // Todo Not set in GUI only Changed in list taxonName.IsRecommended = model.IsRecommended; taxonName.Description = model.Comment; // taxonName.Taxon = CoreData.TaxonManager.GetTaxon(_user, model.TaxonId); taxonName.IsOkForSpeciesObservation = !model.IsNotOkForObsSystem; taxonName.IsOriginalName = model.IsOriginal; taxonName.Taxon = taxon; CoreData.TaxonManager.CreateTaxonName(_user, taxonRevision, taxonName); //CoreData.TaxonManager.AddTaxonName(_user, taxon, revision, taxonName); return(taxonName); }
/// <summary> /// Gets the taxon URL. /// </summary> /// <param name="taxon">The taxon.</param> /// <returns></returns> public override string GetTaxonUrl(ITaxon taxon) { return ((HierarchicalTaxon)taxon).FullUrl; }
/// <summary> /// Gets the taxon URL. /// </summary> /// <param name="taxon">The taxon.</param> /// <returns></returns> public override string GetTaxonUrl(ITaxon taxon) { return taxon.UrlName.Value; }
/// <summary> /// Determines whether [is flat taxon] [the specified taxon]. /// </summary> /// <param name="taxon">The taxon.</param> /// <returns></returns> private bool IsFlatTaxon(ITaxon taxon) { return taxon is FlatTaxon; }
/// <summary> /// Lists the by taxon. /// </summary> /// <param name="taxonFilter">The taxon filter.</param> /// <param name="page">The page.</param> /// <returns></returns> public ActionResult ListByTaxon(ITaxon taxonFilter, int? page) { var fullTemplateName = this.GetFullListTemplateName(); this.ViewBag.CurrentPageUrl = this.GetCurrentPageUrl(); this.ViewBag.RedirectPageUrlTemplate = this.ViewBag.CurrentPageUrl + "/" + taxonFilter.UrlName + "/{0}"; this.ViewBag.DetailsPageId = this.DetailsPageId; this.ViewBag.OpenInSamePage = this.OpenInSamePage; var viewModel = this.Model.CreateListViewModel(taxonFilter, page ?? 1); if (SystemManager.CurrentHttpContext != null) this.AddCacheDependencies(this.Model.GetKeysOfDependentObjects(viewModel)); return this.View(fullTemplateName, viewModel); }
public bool TryGetTaxonFromUrl(string url, out ITaxon taxon) { taxon = this.matchFunc(url); return taxon != null; }
public bool TryGetTaxonFromUrl(string url, out ITaxon taxon) { taxon = this.GetTaxonFromUrl(url, UrlEvaluationMode.UrlPath); return taxon != null; }
/// <summary> /// Sets the redirect URL query string. /// </summary> /// <param name="taxon">The taxon.</param> private void SetRedirectUrlQueryString(ITaxon taxon) { if (taxon == null || this.HttpContext == null) { return; } this.ViewBag.RedirectPageUrlTemplate = this.ViewBag.RedirectPageUrlTemplate + this.HttpContext.Request.QueryString.ToQueryString(); }
/// <summary> /// Renders appropriate list view depending on the <see cref="ListTemplateName" /> /// </summary> /// <param name="taxonFilter">The taxonomy filter.</param> /// <param name="page">The page.</param> /// <returns> /// The <see cref="ActionResult" />. /// </returns> public ActionResult ListByTaxon(ITaxon taxonFilter, int? page) { if (taxonFilter != null) this.InitializeListViewBag("/" + taxonFilter.UrlName + "/{0}"); var viewModel = this.Model.CreateListViewModel(taxonFilter, page ?? 1); if (SystemManager.CurrentHttpContext != null) this.AddCacheDependencies(this.Model.GetKeysOfDependentObjects(viewModel)); var fullTemplateName = this.listTemplateNamePrefix + this.ListTemplateName; return this.View(fullTemplateName, viewModel); }
public ViewResult ListByTaxon(ITaxon taxon, int? page) { return new ViewResult(); }
public ActionResult ListByTaxon(ITaxon taxonFilter, int? page) { return null; }