public ActionResult Save(SubOrganizationPageViewModel viewModel)
        {
            if (string.IsNullOrEmpty(viewModel.SubOrganizationModel.Name))
            {
                ModelState.AddModelError("SubOrganization.Name", "SubOrganization Name is requried");
            }

            if (viewModel.SubOrganizationModel.OrganizationId != Guid.Empty)
            {
                //update the locations list
                var updatedLocations = new List <B2BAddressViewModel>();
                foreach (var location in viewModel.SubOrganizationModel.Locations)
                {
                    if (location.Name != "removed")
                    {
                        updatedLocations.Add(location);
                    }
                    else
                    {
                        if (location.AddressId != Guid.Empty)
                        {
                            _addressService.DeleteAddress(viewModel.SubOrganizationModel.OrganizationId.ToString(), location.AddressId.ToString());
                        }
                    }
                }
                viewModel.SubOrganizationModel.Locations = updatedLocations;
                _organizationService.UpdateSubOrganization(viewModel.SubOrganizationModel);
            }
            return(RedirectToAction("Index", new { suborg = viewModel.SubOrganizationModel.OrganizationId }));
        }
예제 #2
0
        public ActionResult Edit(SubOrganizationPage currentPage)
        {
            var viewModel = new SubOrganizationPageViewModel
            {
                CurrentContent       = currentPage,
                SubOrganizationModel = _organizationService.GetSubOrganizationById(Request["suborg"])
            };

            if (viewModel.SubOrganizationModel == null)
            {
                var startPage = _contentLoader.Get <CommerceHomePage>(ContentReference.StartPage);
                return(Redirect(UrlResolver.Current.GetUrl(startPage.OrganizationMainPage)));
            }

            viewModel.SubOrganizationModel.CountryOptions = _addressService.GetAllCountries();
            return(View(viewModel));
        }
        public ActionResult Edit(SubOrganizationPage currentPage)
        {
            var viewModel = new SubOrganizationPageViewModel
            {
                CurrentContent       = currentPage,
                SubOrganizationModel = _organizationService.GetSubOrganizationById(Request["suborg"])
            };

            if (viewModel.SubOrganizationModel == null)
            {
                var referencePages = _settingsService.GetSiteSettings <ReferencePageSettings>();
                return(Redirect(UrlResolver.Current.GetUrl(referencePages?.OrganizationMainPage ?? ContentReference.StartPage)));
            }
            if (viewModel.SubOrganizationModel.Locations.Count == 0)
            {
                viewModel.SubOrganizationModel.Locations.Add(new B2BAddressViewModel());
            }
            viewModel.SubOrganizationModel.CountryOptions = _addressService.GetAllCountries();
            return(View(viewModel));
        }
        public ActionResult Index(SubOrganizationPage currentPage)
        {
            var viewModel = new SubOrganizationPageViewModel
            {
                CurrentContent       = currentPage,
                SubOrganizationModel = _organizationService.GetSubOrganizationById(Request["suborg"])
            };

            //Set selected suborganization
            _cookieService.Set(Constant.Fields.SelectedOrganization, Request["suborg"]);
            _cookieService.Set(Constant.Fields.SelectedNavOrganization, Request["suborg"]);

            if (viewModel.SubOrganizationModel == null)
            {
                var startPage = _contentLoader.Get <CommerceHomePage>(ContentReference.StartPage);
                return(Redirect(UrlResolver.Current.GetUrl(startPage.OrganizationMainPage)));
            }
            viewModel.IsAdmin = CustomerContext.Current.CurrentContact.Properties[Constant.Fields.UserRole].Value.ToString() == Constant.UserRoles.Admin;

            return(View(viewModel));
        }