Ejemplo n.º 1
0
        public async Task <IActionResult> StateEdit(GeoZoneViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string successFormat;

            if (model.Id == Guid.Empty)
            {
                successFormat = sr["The state {0} was successfully created."];
                await dataManager.Add(model);
            }
            else
            {
                successFormat = sr["The state {0} was successfully updated."];
                await dataManager.Update(model);
            }

            this.AlertSuccess(string.Format(successFormat, model.Name), true);

            return(RedirectToAction("StateListPage",
                                    new
            {
                countryId = model.CountryId,
                crp = model.CountryListReturnPageNumber,
                pageNumber = model.ReturnPageNumber
            }));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> StateEdit(
            GeoZoneViewModel model)
        {
            ViewBag.Title = "Edit State";

            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            bool   result;
            string successFormat;

            if (model.Guid == Guid.Empty)
            {
                successFormat = "The state <b>{0}</b> was successfully created.";
                result        = await dataManager.Add(model);
            }
            else
            {
                successFormat = "The state <b>{0}</b> was successfully updated.";
                result        = await dataManager.Update(model);
            }


            if (result)
            {
                this.AlertSuccess(string.Format(successFormat,
                                                model.Name), true);
            }

            //IGeoCountry country = await geoRepo.FetchCountry(model.CountryGuid);


            //IGeoZone state = model;
            //model = GeoZoneViewModel.FromIGeoZone(state);
            //model.Country = GeoCountryViewModel.FromIGeoCountry(country);

            //model.Heading = "Edit State";

            //return PartialView(model);


            return(RedirectToAction("StateListPage",
                                    new
            {
                countryGuid = model.CountryGuid,
                crp = model.CountryListReturnPageNumber,
                pageNumber = model.ReturnPageNumber
            }));
        }
Ejemplo n.º 4
0
        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));
        }