コード例 #1
0
        public PartialViewResult GetLanguages()
        {
            var viewModel = new ListLanguagesViewModel {
                Languages = new List <LanguageDisplayViewModel>()
            };

            try
            {
                foreach (var language in LocalizationService.AllLanguages)
                {
                    var languageViewModel = new LanguageDisplayViewModel
                    {
                        Id        = language.Id,
                        IsDefault =
                            language.Id == LocalizationService.CurrentLanguage.Id,
                        Name            = language.Name,
                        LanguageCulture = language.LanguageCulture
                    };

                    viewModel.Languages.Add(languageViewModel);
                }
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
                LoggingService.Error(ex);
            }

            return(PartialView(viewModel));
        }
コード例 #2
0
        public ActionResult DeleteLanguageConfirmation(Guid id)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    using (UnitOfWorkManager.NewUnitOfWork())
                    {
                        var language          = LocalizationService.Get(id);
                        var languageViewModel = new LanguageDisplayViewModel
                        {
                            Id        = language.Id,
                            IsDefault =
                                language.Id == LocalizationService.CurrentLanguage.Id,
                            Name            = language.Name,
                            LanguageCulture = language.LanguageCulture,
                        };

                        return(View(languageViewModel));
                    }
                }
                catch (Exception ex)
                {
                    ShowError(ex.Message);
                    LoggingService.Error("Delete confirmation not working");
                    return(View("Index"));
                }
            }
        }
コード例 #3
0
        public ActionResult EditAll(Guid resourceKeyId)
        {
            try
            {
                var resourceKey = LocalizationService.GetResourceKey(resourceKeyId);
                var localeResourceKeyViewModel = new LocaleResourceKeyViewModel
                {
                    Id        = resourceKey.Id,
                    Name      = resourceKey.Name,
                    Notes     = resourceKey.Notes,
                    DateAdded = resourceKey.DateAdded
                };

                var viewModel = new AllResourceValuesViewModel
                {
                    ResourceKey    = localeResourceKeyViewModel,
                    ResourceValues =
                        new Dictionary <LanguageDisplayViewModel, LocaleResourceViewModel>()
                };

                foreach (var localeStringResource in LocalizationService.GetAllValuesForKey(resourceKeyId))
                {
                    var stringResourceViewModel = new LocaleResourceViewModel
                    {
                        Id                = localeStringResource.Id,
                        ResourceKeyId     = localeStringResource.LocaleResourceKey.Id,
                        LocaleResourceKey = localeStringResource.LocaleResourceKey.Name,
                        ResourceValue     = localeStringResource.ResourceValue
                    };

                    var languageViewModel = new LanguageDisplayViewModel
                    {
                        Id              = localeStringResource.Language.Id,
                        IsDefault       = localeStringResource.Language.Id == LocalizationService.CurrentLanguage.Id,
                        Name            = localeStringResource.Language.Name,
                        LanguageCulture = localeStringResource.Language.LanguageCulture
                    };

                    if (!viewModel.ResourceValues.ContainsKey(languageViewModel))
                    {
                        viewModel.ResourceValues.Add(languageViewModel, stringResourceViewModel);
                    }
                    else
                    {
                        viewModel.ResourceValues[languageViewModel] = stringResourceViewModel;
                    }
                }

                //Context.SaveChanges();
                return(View("ListAllValues", viewModel));
            }
            catch (Exception ex)
            {
                //Context.RollBack();
                ShowError(ex.Message);
                LoggingService.Error(ex);
                return(RedirectToAction("Index"));
            }
        }