예제 #1
0
        public ActionResult BranchEdit(int branchId, int vendorId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)
                 && !_permissionService.Authorize(StandardPermissionProvider.ManageVendor)//add by hz
                )
                return AccessDeniedView();

            var vendor = _vendorService.GetVendorById(vendorId);
            if (vendor == null)
                throw new ArgumentException("No vendor found with the specified id");

            var branch = _branchService.GetBranchById(branchId);
            if (branch == null)
                throw new ArgumentException("No branch found with the specified id", "branchId");

            var model = new VendorBranchModel();

            model.VendorId = vendorId;
            model.Branch = branch.ToModel();
            //locales
            AddLocales(_languageService, model.Branch.Locales, (locale, languageId) =>
            {
                locale.Name = branch.GetLocalized(x => x.Name, languageId, false, false);
                locale.City = branch.GetLocalized(x => x.City, languageId, false, false);
                locale.Address1 = branch.GetLocalized(x => x.Address1, languageId, false, false);
                locale.Address2 = branch.GetLocalized(x => x.Address2, languageId, false, false);
            });
            //countries
            model.Branch.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" });
            foreach (var c in _countryService.GetAllCountries(true))
                model.Branch.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = (c.Id == branch.CountryId) });
            //states
            var states = model.Branch.CountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(model.Branch.CountryId.Value, true).ToList() : new List<StateProvince>();
            if (states.Count > 0)
            {
                foreach (var s in states)
                    model.Branch.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == branch.StateProvinceId) });
            }
            else
                model.Branch.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" });

            return View(model);
        }
예제 #2
0
        public ActionResult BranchEdit(VendorBranchModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)
                 && !_permissionService.Authorize(StandardPermissionProvider.ManageVendor)//add by hz
                )
                return AccessDeniedView();

            var vendor = _vendorService.GetVendorById(model.VendorId);
            if (vendor == null)
                throw new ArgumentException("No vendor found with the specified id");

            var branch = _branchService.GetBranchById(model.Branch.Id);
            if (branch == null)
                throw new ArgumentException("No branch found with the specified id");

            if (ModelState.IsValid)
            {
                branch = model.Branch.ToEntity(branch);
                _branchService.UpdateBranch(branch);

                //locales
                UpdateLocalesBranch(branch, model.Branch);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Vendors.Branches.Updated"));
                return RedirectToAction("BranchEdit", new { branchId = model.Branch.Id, vendorId = model.VendorId });
            }

            //If we got this far, something failed, redisplay form
            model.VendorId = vendor.Id;
            model.Branch = branch.ToModel();
            //countries
            model.Branch.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" });
            foreach (var c in _countryService.GetAllCountries(true))
                model.Branch.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = (c.Id == branch.CountryId) });
            //states
            var states = branch.Country != null ? _stateProvinceService.GetStateProvincesByCountryId(branch.Country.Id, true).ToList() : new List<StateProvince>();
            if (states.Count > 0)
            {
                foreach (var s in states)
                    model.Branch.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == branch.StateProvinceId) });
            }
            else
                model.Branch.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" });

            return View(model);
        }
예제 #3
0
        public ActionResult BranchCreate(int vendorId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)
                 && !_permissionService.Authorize(StandardPermissionProvider.ManageVendor)//add by hz
                )
                return AccessDeniedView();

            var vendor = _vendorService.GetVendorById(vendorId);
            if (vendor == null)
                throw new ArgumentException("No vendor found with the specified id", "vendorId");

            var model = new VendorBranchModel();
            model.Branch = new BranchModel();
            //locales
            AddLocales(_languageService, model.Branch.Locales);
            model.VendorId = vendorId;
            //countries
            model.Branch.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" });
            foreach (var c in _countryService.GetAllCountries(true))
                model.Branch.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() });
            model.Branch.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" });

            return View(model);
        }