Skip to content

Instantly share code, notes, and snippets.

@dgg
dgg / gist:6389625
Created August 30, 2013 13:03
Model binding dynamic collections. V Templated textbox
public MvcHtmlString TextBox<TProperty>(Expression<Func<TModel, TProperty>> zeroIndexedExpression, string value, object htmlAttributes = null)
{
TagBuilder text = input(HtmlHelper.GetInputTypeString(InputType.Text), zeroIndexedExpression, value, htmlAttributes);
return MvcHtmlString.Create(text.ToString(TagRenderMode.SelfClosing));
}
private TagBuilder input<TProperty>(string type, Expression<Func<TModel, TProperty>> zeroIndexedExpression, string value, object htmlAttributes = null)
{
var input = new TagBuilder("input");
setNonTemplatedAttributes(input, type, value, htmlAttributes);
@dgg
dgg / gist:6389636
Created August 30, 2013 13:05
Model binding dynamic collections. V Collection naming conventions for default model binder
public class IndexedExpressionConventions
{
private readonly string _replacement;
private static readonly Regex _idMatcher = new Regex("(?<array>[a-z]+_)(?<index>\\d+)(?<property>__[a-z]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex _nameMatcher = new Regex("(?<array>[a-z]+\\[)(?<index>\\d+)(?<property>\\]\\.[a-z]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public IndexedExpressionConventions(string indexReplacement)
{
_replacement = "${array}" + indexReplacement + "${property}"; ;
}
@dgg
dgg / gist:6389655
Created August 30, 2013 13:07
Model binding dynamic collections. V addTemplatedRow
DGON_DOTNET.ClientInteraction =
{
addTemplatedRow: function (tableSelector, templateSelector, options) {
options = optionsWithDefaults(options, {
templateIndexer: 'NewIndex',
indexSelector: '.data-index',
});
var last = calculateLast(tableSelector);
@dgg
dgg / gist:6389670
Created August 30, 2013 13:09
Model binding dynamic collections. V calculateLast
function calculateLast(tableSelector) {
var last = { $row: null, index: 0 };
$(tableSelector + ' tbody tr').each(function () {
last.$row = $(this);
last.index++;
});
return last;
}
@dgg
dgg / gist:6389689
Created August 30, 2013 13:11
Model binding dynamic collections. V AddController
[HttpPost]
public override ActionResult Index(string save, string discard, AddViewModel posted)
{
if (isSave(save, discard))
{
_repository.Save(AddableThing.ToThings(posted.Things));
}
IEnumerable<Thing> updatedThings = _repository.Find();
var model = new AddViewModel
@dgg
dgg / gist:7512819
Last active December 28, 2015 14:09
Love but sometimes. Dev configuration file
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="foo" connectionString="dev-value"/>
</connectionStrings>
</configuration>
@dgg
dgg / gist:7512824
Last active December 28, 2015 14:09
Love but Sometimes. Configuration transformation
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="foo" connectionString="qaa-value" xdt:Transform="SetAttributes(connectionString)" />
</connectionStrings>
</configuration>
@dgg
dgg / gist:7512843
Created November 17, 2013 12:38
Love but sometimes. error-free psake task
task TransformConfig_HappyPath {
$transformer = ".\tools\WebConfigTransformRunner.1.0.0.1\WebConfigTransformRunner.exe"
$config = ".\src\LoveButSometimes.config"
$transformation = ".\src\LoveButSometimes.QA.config"
$target = ".\deploy\LoveButSometimes.config"
exec { &$transformer $config $transformation $target }
}
@dgg
dgg / gist:7512856
Last active December 28, 2015 14:09
Love but sometimes. Passing task ISE output
> .\tools\psake.4.2.0.1\psake.ps1 .\LoveButSometimes.build.ps1 TransformConfig_HappyPath
psake version 4.2.0
Copyright (c) 2010 James Kovacs
Executing TransformConfig_HappyPath
Build Succeeded!
----------------------------------------------------------------------
Build Time Report
@dgg
dgg / gist:7512866
Created November 17, 2013 12:40
Love but sometimes. Failing psake task
task TransformConfig_CloudsAndThunders {
$transformer = ".\tools\WebConfigTransformRunner.1.0.0.1\WebConfigTransformRunner.exe"
$config = ".\src\LoveButSometimes.config"
$transformation = ".\src\LoveButSometimes.QAA.config"
$target = ".\deploy\LoveButSometimes.config"
exec { &$transformer $config $transformation $target }
}