public ActionResult Add(string taxonId, int?nameCategoryId) { TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId)); //todo change revisionId } this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ITaxon taxon = searchResult.Taxon; ViewBag.Taxon = taxon; //this.NavigateData = new NavigateData("TaxonName", "List"); TaxonNameDetailsViewModel model = _taxonNameViewManager.GetTaxonNameDetailsViewModel(taxon); if (nameCategoryId.HasValue) { model.SelectedCategoryId = nameCategoryId.Value; } // Since taxonAdd and edit uses the same view we have to set no of references to 1, otherwise // client validation will not pass for TaxonName Add. TODO refactor Taxon name add and edit into two viewmodels model.NoOfTaxonNameReferences++; return(View("Add", model)); }
public ActionResult List(string taxonId) { int revisionId = this.RevisionId.Value; if (taxonId.IsNull()) { taxonId = this.TaxonIdentifier.Id.ToString(); } TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId, new { revisionId = revisionId })); } this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ITaxon taxon = searchResult.Taxon; ViewBag.Taxon = taxon; //this.NavigateData = new NavigateData("TaxonName", "List"); var model = new ListTaxonNameViewModel(taxon, this.TaxonRevision); return(View("List", model)); }
public ActionResult Edit(string taxonId, string nameId) { int revisionId = this.RevisionId.Value; int taxonNameId = 0; if (nameId.IsNotNull()) { taxonNameId = Int32.Parse(nameId); } TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId, new { revisionId = revisionId, nameId = taxonNameId })); //todo change revisionId } this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ITaxon taxon = searchResult.Taxon; ViewBag.Taxon = taxon; //this.NavigateData = new NavigateData("TaxonName", "List"); var model = _taxonNameViewManager.GetTaxonNameDetailsViewModel(taxon, nameId); return(View("Edit", model)); }
public ActionResult DefaultStraightFile(string taxonId) { TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId)); } ITaxon taxon = searchResult.Taxon; this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ViewBag.Taxon = taxon; var model = ExportViewModel.Create(GetCurrentUser(), taxon, false); var manager = new ExportManager(model, GetCurrentUser()); manager.CreateExportItems(); ExcelFileFormat fileFormat = ExcelFileFormat.OpenXml; var fileDownloadName = GetValidFileName(taxon.ScientificName) + ExcelFileFormatHelper.GetExtension(fileFormat); MemoryStream excelFileStream = manager.CreateExcelFile(fileFormat); var fileStreamResult = new FileStreamResult(excelFileStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); fileStreamResult.FileDownloadName = fileDownloadName; return(fileStreamResult); }
public ActionResult DatabaseNew(string taxonId) { TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId)); } ITaxon taxon = searchResult.Taxon; this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ViewBag.Taxon = taxon; var model = ExportDatabaseViewModel.Create(GetCurrentUser(), taxon); model.ClipBoard = this.TaxonIdentifier.Id.Value.ToString(); // RowDelimiter Dropbox var rowDelimiters = from MatchTaxonRowDelimiter rd in Enum.GetValues(typeof(MatchTaxonRowDelimiter)) select new { value = (int)rd, text = rd.GetLocalizedDescription() }; ViewData["RowDelimiter"] = new SelectList(rowDelimiters, "value", "text", model.RowDelimiter.ToString()); ModelState.Remove("TaxonId"); return(View(model)); }
public void DropParentGetTest() { using (ShimsContext.Create()) { // Arrange LoginApplicationUserAndSetSessionVariables(); TaxonController controller = new TaxonController(); string controllerName = "Taxon"; string actionName = "DropParent"; controller.ControllerContext = GetShimControllerContext(actionName, controllerName); ITaxonRevision refTaxonRevision = TaxonDataSourceTestRepositoryData.GetReferenceRevision(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId, TaxonRevisionStateId.Ongoing.ToString()); ITaxon refTaxon = TaxonDataSourceTestRepositoryData.GetReferenceTaxon(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId); TaxonIdTuple taxonIdentifier = TaxonIdTuple.Create(refTaxon.ScientificName, refTaxon.Id); SessionRevision = refTaxonRevision; SessionRevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId; SessionTaxonId = taxonIdentifier; // Mock Controller // builder.InitializeController(controller); // Test 1: // Act var dropParentResult = controller.DropParent(DyntaxaTestSettings.Default.TestTaxonId.ToString()) as ViewResult; var dropParentViewModel = dropParentResult.ViewData.Model as TaxonDropParentViewModel; // Assert Assert.IsNotNull(dropParentResult); Assert.IsNotNull(dropParentViewModel); // Test that correct view is returned. Assert.AreEqual("DropParent", dropParentResult.ViewName); // Test model values // TODO test more model values.... Assert.IsNull(dropParentViewModel.SelectedTaxonList); Assert.AreEqual(1, dropParentViewModel.TaxonList.Count); Assert.AreEqual(refTaxon.Id.ToString(), dropParentViewModel.TaxonId); Assert.IsFalse(dropParentViewModel.EnableSaveDeleteParentTaxonButton); Assert.AreEqual(refTaxonRevision.Id.ToString(), dropParentViewModel.RevisionId); foreach (TaxonParentViewModelHelper helper in dropParentViewModel.TaxonList) { Assert.IsNotNull(helper.Category); Assert.IsNotNull(helper.CommonName); Assert.IsNotNull(helper.SortOrder); Assert.IsNotNull(helper.TaxonId); Assert.IsNotNull(helper.ScientificName); } } }
public JsonResult TaxonId(string taxonId) { TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(Json("No or ambigous result", JsonRequestBehavior.AllowGet)); } ITaxon taxon = searchResult.Taxon; this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); return(Json(this.TaxonIdentifier.Id, JsonRequestBehavior.AllowGet)); }
public ActionResult Graphviz(string taxonId) { IUserContext userContext = GetCurrentUser(); if (!(userContext.IsTaxonRevisionAdministrator() || userContext.IsTaxonEditor())) { return(RedirectToAction("AccessIsNotAllowed", "Account", new { url = this.Request.Url })); } TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); ExportGraphVizViewModel model = null; ITaxon taxon = null; if (searchResult.NumberOfMatches == 1) { taxon = searchResult.Taxon; this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ViewBag.Taxon = taxon; model = new ExportGraphVizViewModel(); model.ClipBoard = this.TaxonIdentifier.Id.Value.ToString(); } else { //model = ExportDatabaseViewModel.Create(GetCurrentUser(), taxon); model = new ExportGraphVizViewModel(); model.ClipBoard = ""; } var rowDelimiters = from MatchTaxonRowDelimiter rd in Enum.GetValues(typeof(MatchTaxonRowDelimiter)) select new { value = (int)rd, text = rd.GetLocalizedDescription() }; ViewData["RowDelimiter"] = new SelectList(rowDelimiters, "value", "text", model.RowDelimiter.ToString()); ModelState.Remove("TaxonId"); if (userContext.IsTaxonRevisionAdministrator() || userContext.IsTaxonEditor()) { ViewBag.ShowRefreshDyntaxaTaxonTreeButton = true; } else { ViewBag.ShowRefreshDyntaxaTaxonTreeButton = false; } ViewBag.TreeLastUpdatedTime = TaxonRelationsTreeCacheManager.CacheLastUpdatedTime; return(View(model)); }
public ActionResult Delete(string taxonId, int nameId) { var searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId)); } this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ITaxon taxon = searchResult.Taxon; ViewBag.Taxon = taxon; //this.NavigateData = new NavigateData("TaxonName", "List"); var model = _taxonNameViewManager.GetViewModel(taxon, nameId); return(View(model)); }
public ActionResult TaxonList(string taxonId) { TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId)); } ITaxon taxon = searchResult.Taxon; this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ViewBag.Taxon = taxon; var model = ExportViewModel.Create(GetCurrentUser(), taxon, false); ModelState.Remove("TaxonId"); return(View(model)); }
void Session_Start(object sender, EventArgs e) { const string masterName = "Site"; Session["masterpage"] = masterName; Session["TaxonId"] = TaxonIdTuple.Create(RootTaxonId.ToString(), RootTaxonId); Session["RootTaxonId"] = RootTaxonId; string requestCookies = Request.Headers["Cookie"]; if ((requestCookies != null) && (requestCookies.IndexOf("ASP.NET_SessionId") >= 0)) { //cookie existed, so this new one is due to timeout. //Redirect the user System.Diagnostics.Debug.WriteLine("Session expired!"); Response.RedirectToRoute(new { controller = "Taxon", Action = "SearchResult" }); } Session["language"] = Thread.CurrentThread.CurrentUICulture.Name; }
public ActionResult Settings(string taxonId) { TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId); if (searchResult.NumberOfMatches != 1) { return(RedirectToSearch(taxonId)); } ITaxon taxon = searchResult.Taxon; this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id); ViewBag.Taxon = taxon; var viewManager = new MatchViewManager(GetCurrentUser()); MatchSettingsViewModel model = viewManager.GetMatchSettingsViewModel(taxon); CreateMatchSelectLists(model); ModelState.Remove("TaxonId"); return(View(model)); }
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)); }
public void AddPostTest() { using (ShimsContext.Create()) { // Arrange LoginApplicationUserAndSetSessionVariables(); // TODO this does not work; how do we set transactions to a user and shim them in code? Transaction = new ShimTransaction() { Commit = () => { return; }, }; TaxonController controller = new TaxonController(); string controllerName = "Taxon"; string actionName = "Add"; controller.ControllerContext = GetShimControllerContext(actionName, controllerName); ITaxonRevision refTaxonRevision = TaxonDataSourceTestRepositoryData.GetReferenceRevision(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId, TaxonRevisionStateId.Ongoing.ToString()); ITaxon refTaxon = TaxonDataSourceTestRepositoryData.GetReferenceTaxon(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId); TaxonIdTuple taxonIdentifier = TaxonIdTuple.Create(refTaxon.ScientificName, refTaxon.Id); SessionRevision = refTaxonRevision; SessionRevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId; SessionTaxonId = taxonIdentifier; // Create model.... TaxonAddViewModel model = new TaxonAddViewModel(); model.ParentTaxonId = DyntaxaTestSettings.Default.TestParentTaxonId.ToString(); model.TaxonCategoryId = 14; model.ScientificName = "New Parent"; // Test 1: Model state is valid // Act var result = controller.Add(model) as RedirectToRouteResult; // Test that correct view is returned Assert.IsNotNull(result); Assert.AreEqual(DyntaxaTestSettings.Default.TestTaxonId.ToString(), result.RouteValues["taxonId"]); Assert.AreEqual("Edit", result.RouteValues["action"]); // Test 2: Model state is invalid // Act // Set model state to be invalid controller.ModelState.AddModelError("", "dummy error message"); var addResult = controller.Add(model) as ViewResult; var addViewModel = addResult.ViewData.Model as TaxonAddViewModel; // Assert Assert.IsNotNull(addResult); // Test that correct view is returned ie th add view is reloaded... Assert.AreEqual("Add", addResult.ViewName); Assert.IsNotNull(addViewModel); // Test that Imodel values. Assert.AreEqual(DyntaxaTestSettings.Default.TestParentTaxonId.ToString(), addViewModel.ParentTaxonId); } }
public void DropParentPostTest() { using (ShimsContext.Create()) { // Arrange LoginApplicationUserAndSetSessionVariables(); // TODO this does not work; how do we set transactions to a user and shim them in code? Transaction = new ShimTransaction() { Commit = () => { return; }, }; TaxonController controller = new TaxonController(); string controllerName = "Taxon"; string actionName = "DropParent"; controller.ControllerContext = GetShimControllerContext(actionName, controllerName); ITaxonRevision refTaxonRevision = TaxonDataSourceTestRepositoryData.GetReferenceRevision(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId, TaxonRevisionStateId.Ongoing.ToString()); ITaxon refTaxon = TaxonDataSourceTestRepositoryData.GetReferenceTaxon(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId); TaxonIdTuple taxonIdentifier = TaxonIdTuple.Create(refTaxon.ScientificName, refTaxon.Id); SessionRevision = refTaxonRevision; SessionRevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId; SessionTaxonId = taxonIdentifier; refTaxon.GetNearestParentTaxonRelations(UserContextData).Add(new TaxonRelation() { ReplacedInTaxonRevisionEventId = null, CreatedBy = 1, CreatedDate = new DateTime(2011), ValidToDate = new DateTime(2022), IsMainRelation = false, Id = 55555 }); // Mock Controller // builder.InitializeController(controller); // Create model.... TaxonDropParentViewModel model = new TaxonDropParentViewModel(); model.TaxonId = DyntaxaTestSettings.Default.TestTaxonId.ToString(); model.RevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId.ToString(); model.SelectedTaxonList = new List <string>() { "55555" }; var addParentResult = controller.DropParent(model) as RedirectToRouteResult; // Test 1: Test Save button pressed // Assert Assert.IsNotNull(addParentResult); // Test that AddParent action is returned. Assert.AreEqual(refTaxon.Id.ToString(), addParentResult.RouteValues["TaxonId"]); Assert.AreEqual("DropParent", addParentResult.RouteValues["action"]); // Test 2: No new parent seleceted reload view // Act model.SelectedTaxonList = null; var addParentResult2 = controller.DropParent(model) as RedirectToRouteResult; // Assert Assert.IsNotNull(addParentResult2); // Test that AddParent action is returned. Assert.AreEqual(refTaxon.Id.ToString(), addParentResult2.RouteValues["taxonId"]); Assert.AreEqual("DropParent", addParentResult.RouteValues["action"]); } }
/// <summary> /// Login application user. /// </summary> /// <param name="stubbedSwedishUserContext"> /// The stubbed swedish user context, if required. /// </param> protected void LoginApplicationUser(IUserContext stubbedSwedishApplicationUserContext, IUserContext stubbedApplicationUserContext) { // Set session helper for handling HttpContext data. HttpContext contextBase = GetShimHttpContext(); sessionHelper = new HttpContextSessionHelper(contextBase); // Login application user try { CoreData.UserManager.LoginApplicationUser(); } catch (TimeoutException) { // Try Once more if service is turned off... Thread.Sleep(20000); CoreData.UserManager.LoginApplicationUser(); } //if (stubbedApplicationUserContext.IsNotNull() && stubbedSwedishApplicationUserContext.IsNotNull()) //{ // // Set session settings. // SessionHelper.SetInSession(DyntaxaSettings.Default.ApplicationContextCacheKey, stubbedApplicationUserContext); // SessionHelper.SetInSession(DyntaxaSettings.Default.ApplicationContextCacheKey + DyntaxaTestSettings.Default.EnglishLocale, stubbedApplicationUserContext); // SessionHelper.SetInSession(DyntaxaSettings.Default.ApplicationContextCacheKey + DyntaxaTestSettings.Default.SwedishLocale, stubbedSwedishApplicationUserContext); // SessionHelper.SetInSession(DyntaxaTestSettings.Default.LanguageContextString, DyntaxaTestSettings.Default.EnglishLocale); // SessionHelper.SetInSession(DyntaxaTestSettings.Default.LanguageContextIdString, DyntaxaTestSettings.Default.EnglishLocaleId); //} // Get cash settings. //applicationUserContext = CacheHelper.GetFromCache<IUserContext>(DyntaxaSettings.Default.ApplicationContextCacheKey); //IUserContext applicationUserContextEN = CacheHelper.GetFromCache<IUserContext>(DyntaxaSettings.Default.ApplicationContextCacheKey + DyntaxaTestSettings.Default.EnglishLocale); //IUserContext applicationUserContextSV = CacheHelper.GetFromCache<IUserContext>(DyntaxaSettings.Default.ApplicationContextCacheKey + DyntaxaTestSettings.Default.SwedishLocale); // If we use stubbed object we have to set application context for swedish also, if we use login to DB this is not needed. if (applicationUserContextSV.IsNull() && stubbedSwedishApplicationUserContext != null) { applicationUserContextSV = stubbedSwedishApplicationUserContext; } else if (stubbedSwedishApplicationUserContext == null) { applicationUserContextSV = CoreData.UserManager.GetApplicationContext("sv-SE"); applicationUserContext = CoreData.UserManager.GetApplicationContext(); } // Set session settings. //SessionHelper.SetInSession(DyntaxaSettings.Default.ApplicationContextCacheKey, applicationUserContext); //SessionHelper.SetInSession(DyntaxaSettings.Default.ApplicationContextCacheKey + DyntaxaTestSettings.Default.EnglishLocale, applicationUserContextEN); //SessionHelper.SetInSession(DyntaxaSettings.Default.ApplicationContextCacheKey + DyntaxaTestSettings.Default.SwedishLocale, applicationUserContextSV); //CacheHelper.SetInCache(DyntaxaSettings.Default.ApplicationContextCacheKey + DyntaxaTestSettings.Default.SwedishLocale, applicationUserContextSV); //// Set Session start parameters that will be set in Global.asax.cs-Session_Start(object sender, EventArgs e) //SessionHelper.SetInSession(DyntaxaTestSettings.Default.LanguageContextString, SpeciesIdentificationTestSettings.Default.EnglishLocale); //// Set language that will be set in Global.asax.cs-Application_BeginRequest(object sender, EventArgs e) //Thread.CurrentThread.CurrentUICulture = new CultureInfo(SessionHelper.GetFromSession<string>(SpeciesIdentificationTestSettings.Default.LanguageContextString)); //Thread.CurrentThread.CurrentCulture = new CultureInfo(SessionHelper.GetFromSession<string>(SpeciesIdentificationTestSettings.Default.LanguageContextString)); // Set Session start parameters that will be set in Global.asax.cs-Session_Start(object sender, EventArgs e) //SessionHelper.SetInSession(DyntaxaTestSettings.Default.LanguageContextString, DyntaxaTestSettings.Default.EnglishLocale); // Set language that will be set in Global.asax.cs-Application_BeginRequest(object sender, EventArgs e) Thread.CurrentThread.CurrentUICulture = new CultureInfo(DyntaxaTestSettings.Default.EnglishLocale); Thread.CurrentThread.CurrentCulture = new CultureInfo(DyntaxaTestSettings.Default.EnglishLocale); SessionTaxonId = TaxonIdTuple.Create(100047.ToString(), 100047); }