Import view and controller to permit importing data recipes.

--HG--
branch : dev
This commit is contained in:
Suha Can
2011-03-10 12:47:52 -08:00
parent dbce4188ab
commit aafdc8941f
3 changed files with 36 additions and 2 deletions

View File

@@ -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();

View File

@@ -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">

View File

@@ -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>
}
}