| 1234567891011121314151617181920212223242526272829303132333435363738 |
- using System.Collections.Generic;
- using System.Linq;
-
- namespace cwebplusApp.Shared.Services {
- public class PageHistoryManager {
-
- private readonly List<string> previousPages;
-
- public PageHistoryManager() {
- previousPages = new List<string>();
- }
-
- public void Reset() {
- previousPages.Clear();
- }
-
- public void AddPageToHistory(string pageName) {
- previousPages.Add(pageName);
- }
-
- public string GetPreviousPage() {
- if (CanGoBack()) {
- // You add a page on initialization, so you need to return the 2nd from the last
- string previousPage = previousPages.ElementAt(previousPages.Count - 2);
- previousPages.RemoveAt(previousPages.Count - 1);
- previousPages.RemoveAt(previousPages.Count - 1);
- return previousPage;
- }
-
- // Can't go back because you didn't navigate enough
- return previousPages.FirstOrDefault();
- }
-
- public bool CanGoBack() {
- return previousPages.Count > 1;
- }
- }
- }
|