mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Import view and controller to permit importing data recipes.
--HG-- branch : dev
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Web.Mvc;
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ImportExport.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.ImportExport.Controllers {
|
||||
public class AdminController : Controller {
|
||||
@@ -18,6 +20,25 @@ namespace Orchard.ImportExport.Controllers {
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Import")]
|
||||
public ActionResult ImportPOST() {
|
||||
if (!Services.Authorizer.Authorize(Permissions.Import, T("Not allowed to import.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
if (String.IsNullOrEmpty(Request.Files["RecipeFile"].FileName)) {
|
||||
throw new ArgumentException(T("Please choose a recipe file to import.").Text);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Your recipe has been imported."));
|
||||
return RedirectToAction("Import");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Import failed {0}", exception.Message));
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Export() {
|
||||
var viewModel = new ExportViewModel();
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
@model Orchard.ImportExport.ViewModels.ImportViewModel
|
||||
|
||||
@{ Layout.Title = T("Import").ToString(); }
|
||||
@{
|
||||
Layout.Title = T("Import").ToString();
|
||||
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Import", new { area = "Orchard.ImportExport" }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
|
||||
Html.ValidationSummary();
|
||||
<p>@T("Choose a recipe file to import. Please consider {0} or backing up your data first.",
|
||||
@Html.Link(T("exporting").Text, Url.Action("Export", "Admin", new { area = "Orchard.ImportExport" })))</p>
|
||||
<fieldset>
|
||||
<label for="RecipeFile">@T("Recipe File:")</label>
|
||||
<input type="file" id="RecipeFile" size="64" name="RecipeFile" value="Browse..." />
|
||||
</fieldset>
|
||||
<button type="submit" class="primaryAction">@T("Import")</button>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user