Beispiel #1
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"));
            }
        }