mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
Merge default => dev
--HG-- branch : dev
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Mvc.ModelBinders;
|
||||
|
||||
namespace Orchard.Tests.Mvc.ModelBinders {
|
||||
[TestFixture]
|
||||
public class KeyedListModelBinderTests {
|
||||
private class Foo {
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
[Test]
|
||||
public void BinderShouldBindValues() {
|
||||
var controllerContext = new ControllerContext();
|
||||
|
||||
var binders = new ModelBinderDictionary {
|
||||
{ typeof(Foo), new DefaultModelBinder() }
|
||||
};
|
||||
|
||||
var input = new FormCollection {
|
||||
{ "fooInstance[Bar1].Value", "bar1value" },
|
||||
{ "fooInstance[Bar2].Value", "bar2value" }
|
||||
};
|
||||
|
||||
var foos = new[] {
|
||||
new Foo {Name = "Bar1", Value = "uno"},
|
||||
new Foo {Name = "Bar2", Value = "dos"},
|
||||
new Foo {Name = "Bar3", Value = "tres"},
|
||||
};
|
||||
|
||||
var providers = new EmptyModelMetadataProvider();
|
||||
|
||||
var bindingContext = new ModelBindingContext {
|
||||
ModelMetadata = providers.GetMetadataForType(() => foos, foos.GetType()),
|
||||
ModelName = "fooInstance",
|
||||
ValueProvider = input.ToValueProvider()
|
||||
};
|
||||
|
||||
var binder = new KeyedListModelBinder<Foo>(binders, foo => foo.Name);
|
||||
|
||||
var result = (IList<Foo>)binder.BindModel(controllerContext, bindingContext);
|
||||
|
||||
Assert.That(result.Count, Is.EqualTo(3));
|
||||
Assert.That(result[0].Value, Is.EqualTo("bar1value"));
|
||||
Assert.That(result[1].Value, Is.EqualTo("bar2value"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -272,7 +272,6 @@
|
||||
<Compile Include="Environment\Extensions\ExtensionTypes\StubTypes.cs" />
|
||||
<Compile Include="Localization\NullLocalizerTests.cs" />
|
||||
<Compile Include="Logging\LoggingModuleTests.cs" />
|
||||
<Compile Include="Mvc\ModelBinders\KeyedListModelBinderTests.cs" />
|
||||
<Compile Include="Mvc\OrchardControllerFactoryTests.cs" />
|
||||
<Compile Include="Mvc\RouteCollectionPublisherTests.cs" />
|
||||
<Compile Include="Mvc\Routes\StandardExtensionRouteProviderTests.cs" />
|
||||
|
@@ -4,7 +4,7 @@ Author: The Orchard Team
|
||||
Website: http://orchardproject.net
|
||||
Version: 0.8.0
|
||||
OrchardVersion: 0.8.0
|
||||
Description: The ArhiveLater module introduces scheduled archiving functionality.
|
||||
Description: The ArchiveLater module introduces scheduled archiving functionality.
|
||||
Features:
|
||||
Orchard.ArchiveLater:
|
||||
Name: Archive Later
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Extensions;
|
||||
using Orchard.Blogs.Models;
|
||||
@@ -54,7 +55,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to create blogs")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var blog = Services.ContentManager.New<BlogPart>("Blog");
|
||||
BlogPart blog = Services.ContentManager.New<BlogPart>("Blog");
|
||||
if (blog == null)
|
||||
return HttpNotFound();
|
||||
|
||||
|
@@ -95,5 +95,6 @@ namespace Orchard.Blogs.Controllers {
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)blog);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
Name: Code generation
|
||||
Name: Code Generation
|
||||
AntiForgery: enabled
|
||||
Author: The Orchard Team
|
||||
Website: http://orchardproject.net
|
||||
|
@@ -4,7 +4,7 @@ using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Roles.ViewModels {
|
||||
public class RoleCreateViewModel {
|
||||
[Required]
|
||||
[Required, StringLength(255)]
|
||||
public string Name { get; set; }
|
||||
public IDictionary<string, IEnumerable<Permission>> FeaturePermissions { get; set; }
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ using Orchard.Security.Permissions;
|
||||
namespace Orchard.Roles.ViewModels {
|
||||
public class RoleEditViewModel {
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
[Required, StringLength(255)]
|
||||
public string Name { get; set; }
|
||||
public IDictionary<string, IEnumerable<Permission>> RoleCategoryPermissions { get; set; }
|
||||
public IEnumerable<string> CurrentPermissions { get; set; }
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System.Reflection;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Localization;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace Orchard.Environment {
|
||||
namespace Orchard.Environment {
|
||||
/// <summary>
|
||||
/// Abstraction of the running environment
|
||||
/// </summary>
|
||||
@@ -10,5 +9,4 @@ namespace Orchard.Environment {
|
||||
bool IsAssemblyLoaded(string name);
|
||||
|
||||
void RestartAppDomain();
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.Mvc.ModelBinders {
|
||||
public class KeyedListModelBinder<T> : IModelBinder {
|
||||
private readonly ModelBinderDictionary _binders;
|
||||
private readonly ModelMetadataProvider _providers;
|
||||
private readonly Func<T, string> _keySelector;
|
||||
|
||||
public KeyedListModelBinder(
|
||||
ModelBinderDictionary binders,
|
||||
Func<T, string> keySelector) {
|
||||
_binders = binders;
|
||||
_providers = ModelMetadataProviders.Current;
|
||||
_keySelector = keySelector;
|
||||
}
|
||||
|
||||
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
|
||||
var binder = _binders.GetBinder(typeof(T));
|
||||
|
||||
// given an existing collection
|
||||
var model = (IList<T>)bindingContext.Model;
|
||||
if (model != null) {
|
||||
foreach (var item in model) {
|
||||
// only update non-null collections
|
||||
if (Equals(item, default(T)))
|
||||
continue;
|
||||
|
||||
// that have a key value
|
||||
var key = _keySelector(item);
|
||||
if (string.IsNullOrEmpty(key))
|
||||
continue;
|
||||
|
||||
// use the configured binder to update the rest of the properties on the object
|
||||
var currentItem = item;
|
||||
var itemContext = new ModelBindingContext {
|
||||
ModelMetadata = _providers.GetMetadataForType(() => currentItem, typeof(T)),
|
||||
ModelName = bindingContext.ModelName + "[" + key + "]",
|
||||
ModelState = bindingContext.ModelState,
|
||||
PropertyFilter = bindingContext.PropertyFilter,
|
||||
ValueProvider = bindingContext.ValueProvider,
|
||||
};
|
||||
binder.BindModel(controllerContext, itemContext);
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
@@ -739,7 +739,6 @@
|
||||
<Compile Include="Mvc\ModelBinders\ModelBinderPublisher.cs" />
|
||||
<Compile Include="Mvc\ModelBinders\IModelBinderProvider.cs" />
|
||||
<Compile Include="Mvc\ModelBinders\IModelBinderPublisher.cs" />
|
||||
<Compile Include="Mvc\ModelBinders\KeyedListModelBinder.cs" />
|
||||
<Compile Include="Mvc\ModelBinders\ModelBinderDescriptor.cs" />
|
||||
<Compile Include="Mvc\Routes\RouteExtensions.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\IViewEngineProvider.cs" />
|
||||
|
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Web;
|
||||
using System.Web.Compilation;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.Host;
|
||||
|
Reference in New Issue
Block a user