示例#1
0
        protected virtual void PrepareFlagsModel(LanguageModel model) {
            if (model == null)
                throw new ArgumentNullException("model");

            model.FlagFileNames = Directory
                .EnumerateFiles(_webHelper.MapPath("~/Administration/Content/Images/flags/"), "*.png", SearchOption.TopDirectoryOnly)
                .Select(Path.GetFileName)
                .ToList();
        }
示例#2
0
        protected virtual void PrepareStoresMappingModel(LanguageModel model, Language language, bool excludeProperties) {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableStores = _storeService
                .GetAllStores()
                .Select(s => s.ToModel())
                .ToList();
            if (!excludeProperties) {
                if (language != null) {
                    model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(language);
                }
            }
        }
示例#3
0
 protected virtual void SaveStoreMappings(Language language, LanguageModel model) {
     var existingStoreMappings = _storeMappingService.GetStoreMappings(language);
     var allStores = _storeService.GetAllStores();
     foreach (var store in allStores) {
         if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id)) {
             //new store
             if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0)
                 _storeMappingService.InsertStoreMapping(language, store.Id);
         } else {
             //remove store
             var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id);
             if (storeMappingToDelete != null)
                 _storeMappingService.DeleteStoreMapping(storeMappingToDelete);
         }
     }
 }
示例#4
0
        public ActionResult Edit(LanguageModel model, bool continueEditing) {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
                return AccessDeniedView();

            var language = _languageService.GetLanguageById(model.Id);
            if (language == null)
                //No language found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid) {
                //ensure we have at least one published language
                var allLanguages = _languageService.GetAllLanguages();
                if (allLanguages.Count == 1 && allLanguages[0].Id == language.Id &&
                    !model.Published) {
                    ErrorNotification("At least one published language is required.");
                    return RedirectToAction("Edit", new { id = language.Id });
                }

                //update
                language = model.ToEntity(language);
                _languageService.UpdateLanguage(language);

                //Stores
                SaveStoreMappings(language, model);

                //notification
                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Languages.Updated"));
                if (continueEditing) {
                    //selected tab
                    SaveSelectedTabIndex();

                    return RedirectToAction("Edit", new { id = language.Id });
                }
                return RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form

            //Stores
            PrepareStoresMappingModel(model, language, true);
            //flags
            PrepareFlagsModel(model);

            return View(model);
        }
示例#5
0
        public ActionResult Create(LanguageModel model, bool continueEditing) {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
                return AccessDeniedView();

            if (ModelState.IsValid) {
                var language = model.ToEntity();
                _languageService.InsertLanguage(language);

                //Stores
                SaveStoreMappings(language, model);

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Languages.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = language.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form

            //Stores
            PrepareStoresMappingModel(model, null, true);
            //flags
            PrepareFlagsModel(model);

            return View(model);
        }
示例#6
0
        public ActionResult Create() {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
                return AccessDeniedView();

            var model = new LanguageModel();
            //Stores
            PrepareStoresMappingModel(model, null, false);
            //flags
            PrepareFlagsModel(model);
            //default values
            model.Published = true;
            return View(model);
        }