public ViewResult CommitImportResources(bool?previewImport, bool?showMenu, ICollection <DetectedImportChange> changes)
        {
            var model = new ImportResourcesViewModel {
                ShowMenu = showMenu ?? false
            };

            try
            {
                // prepare incoming model a bit
                // if change is selected and translation and/or language is `null` -> most probably this means that translation was empty
                // but Mvc model binder set it to `null` -> we need to fix this to get functionality to set empty translations via import process
                var importer = new ResourceImportWorkflow();
                var detectedImportChanges = changes.Where(c => c.Selected)
                                            .ForEach(c =>
                {
                    c.ImportingResource.Translations.ForEach(t =>
                    {
                        t.Value    = t.Value ?? (t.Value = string.Empty);
                        t.Language = t.Language ?? (t.Language = string.Empty);
                    });
                })
                                            .ToList();

                var result = importer.ImportChanges(detectedImportChanges);

                ViewData["LocalizationProvider_ImportResult"] = string.Join("<br/>", result);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("importFailed", $"Import failed! Reason: {e.Message}");
            }

            return(View("ImportResources", model));
        }
Exemple #2
0
        public ViewResult CommitImportResources(bool?previewImport, bool?showMenu, ICollection <DetectedImportChange> changes)
        {
            var model = new ImportResourcesViewModel
            {
                ShowMenu = showMenu ?? false
            };

            try
            {
                var importer = new ResourceImportWorkflow();
                var result   = importer.ImportChanges(changes.Where(c => c.Selected).ToList());

                ViewData["LocalizationProvider_ImportResult"] = string.Join("<br/>", result);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("importFailed", $"Import failed! Reason: {e.Message}");
            }

            return(View("ImportResources", model));
        }