Exemple #1
0
        public async Task <IActionResult> StateEdit(
            Guid countryId,
            Guid?stateId,
            int crp = 1,
            int returnPageNumber = 1
            )
        {
            if (countryId == Guid.Empty)
            {
                return(RedirectToAction("CountryListPage"));
            }

            GeoZoneViewModel model;

            if ((stateId.HasValue) && (stateId.Value != Guid.Empty))
            {
                var state = await dataManager.FetchGeoZone(stateId.Value);

                if ((state != null) && (state.CountryId == countryId))
                {
                    model = GeoZoneViewModel.FromIGeoZone(state);

                    var currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext);
                    currentCrumbAdjuster.KeyToAdjust    = "StateEdit";
                    currentCrumbAdjuster.AdjustedText   = model.Name;
                    currentCrumbAdjuster.ViewFilterName = NamedNavigationFilters.Breadcrumbs; // this is default but showing here for readers of code
                    currentCrumbAdjuster.AddToContext();
                }
                else
                {
                    // invalid guid provided
                    return(RedirectToAction("CountryListPage", new { pageNumber = crp }));
                }
            }
            else
            {
                model           = new GeoZoneViewModel();
                model.CountryId = countryId;
            }

            model.ReturnPageNumber            = returnPageNumber;
            model.CountryListReturnPageNumber = crp;

            var country = await dataManager.FetchCountry(countryId);

            model.CountryName = country.Name;

            var stateListCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext);

            stateListCrumbAdjuster.KeyToAdjust    = "StateListPage";
            stateListCrumbAdjuster.AdjustedText   = string.Format(sr["{0} States"], model.CountryName);
            stateListCrumbAdjuster.ViewFilterName = NamedNavigationFilters.Breadcrumbs; // this is default but showing here for readers of code
            stateListCrumbAdjuster.AddToContext();

            return(View(model));
        }
        public async Task <IActionResult> StateEdit(
            Guid countryGuid,
            Guid?guid,
            int crp = 1,
            int returnPageNumber = 1
            )
        {
            if (countryGuid == Guid.Empty)
            {
                return(RedirectToAction("CountryListPage"));
            }

            //int returnPage = 1;
            //if (returnPageNumber.HasValue) { returnPage = returnPageNumber.Value; }

            ViewBag.Title = "Edit State";

            GeoZoneViewModel model;

            if ((guid.HasValue) && (guid.Value != Guid.Empty))
            {
                IGeoZone state = await dataManager.FetchGeoZone(guid.Value);

                if ((state != null) && (state.CountryGuid == countryGuid))
                {
                    model         = GeoZoneViewModel.FromIGeoZone(state);
                    model.Heading = "Edit State";
                }
                else
                {
                    // invalid guid provided
                    return(RedirectToAction("CountryListPage", new { pageNumber = crp }));
                }
            }
            else
            {
                model             = new GeoZoneViewModel();
                model.Heading     = "Create New State";
                model.CountryGuid = countryGuid;
            }

            model.ReturnPageNumber            = returnPageNumber;
            model.CountryListReturnPageNumber = crp;

            IGeoCountry country = await dataManager.FetchCountry(countryGuid);

            model.Country = GeoCountryViewModel.FromIGeoCountry(country);

            NavigationNodeAdjuster currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext);

            currentCrumbAdjuster.KeyToAdjust    = "StateEdit";
            currentCrumbAdjuster.AdjustedText   = model.Heading;
            currentCrumbAdjuster.ViewFilterName = NamedNavigationFilters.Breadcrumbs; // this is default but showing here for readers of code
            currentCrumbAdjuster.AddToContext();

            //var node = SiteMaps.Current.FindSiteMapNodeFromKey("StateEdit");
            //if (node != null)
            //{
            //    node.Title = model.Heading;
            //    var parent = node.ParentNode;
            //    if (parent != null)
            //    {
            //        parent.Title = model.Country.Name + " States";

            //    }
            //}

            return(View(model));
        }