Skip to content

Commit fd5ae9a

Browse files
Add grid timespan editor sample
1 parent 2144acb commit fd5ae9a

File tree

83 files changed

+90955
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+90955
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.30723.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GridTimeSpanEditor", "GridTimeSpanEditor\GridTimeSpanEditor.csproj", "{AD9BD01E-9C5C-473D-B3FC-9325F5184415}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{AD9BD01E-9C5C-473D-B3FC-9325F5184415}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{AD9BD01E-9C5C-473D-B3FC-9325F5184415}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{AD9BD01E-9C5C-473D-B3FC-9325F5184415}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{AD9BD01E-9C5C-473D-B3FC-9325F5184415}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Web;
2+
using System.Web.Optimization;
3+
4+
namespace GridTimeSpanEditor
5+
{
6+
public class BundleConfig
7+
{
8+
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
9+
public static void RegisterBundles(BundleCollection bundles)
10+
{
11+
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
12+
"~/Scripts/jquery-{version}.js"));
13+
14+
// Use the development version of Modernizr to develop with and learn from. Then, when you're
15+
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
16+
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
17+
"~/Scripts/modernizr-*"));
18+
19+
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
20+
"~/Scripts/bootstrap.js",
21+
"~/Scripts/respond.js"));
22+
23+
bundles.Add(new StyleBundle("~/Content/css").Include(
24+
"~/Content/bootstrap.css",
25+
"~/Content/site.css"));
26+
}
27+
}
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Web;
2+
using System.Web.Mvc;
3+
4+
namespace GridTimeSpanEditor
5+
{
6+
public class FilterConfig
7+
{
8+
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
9+
{
10+
filters.Add(new HandleErrorAttribute());
11+
}
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using System.Web.Routing;
7+
8+
namespace GridTimeSpanEditor
9+
{
10+
public class RouteConfig
11+
{
12+
public static void RegisterRoutes(RouteCollection routes)
13+
{
14+
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
15+
16+
routes.MapRoute(
17+
name: "Default",
18+
url: "{controller}/{action}/{id}",
19+
defaults: new { controller = "Home", action = "TimePickerEditor", id = UrlParameter.Optional }
20+
);
21+
}
22+
}
23+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
7+
namespace GridTimeSpanEditor.Binders
8+
{
9+
public class TimeSpanModelBinder: DefaultModelBinder
10+
{
11+
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
12+
{
13+
ValueProviderResult valueResultHours = bindingContext.ValueProvider
14+
.GetValue(bindingContext.ModelName + ".Hours");
15+
ValueProviderResult valueResultMinutes = bindingContext.ValueProvider
16+
.GetValue(bindingContext.ModelName + ".Minutes");
17+
ValueProviderResult valueResultSeconds = bindingContext.ValueProvider
18+
.GetValue(bindingContext.ModelName + ".Seconds");
19+
20+
if (valueResultHours != null || valueResultMinutes != null | valueResultSeconds != null)
21+
{
22+
int hours = 0;
23+
int minutes = 0;
24+
int seconds = 0;
25+
TimeSpan? actualValue = null;
26+
var valueResult = new ValueProviderResult(null, string.Empty, System.Globalization.CultureInfo.CurrentCulture);
27+
28+
var modelState = new ModelState { Value = valueResult };
29+
try
30+
{
31+
if (valueResultHours != null)
32+
{
33+
hours = int.Parse(valueResultHours.AttemptedValue);
34+
}
35+
36+
if (valueResultMinutes != null)
37+
{
38+
minutes = int.Parse(valueResultMinutes.AttemptedValue);
39+
}
40+
41+
if (valueResultSeconds != null)
42+
{
43+
seconds = int.Parse(valueResultSeconds.AttemptedValue);
44+
}
45+
actualValue = new TimeSpan(hours, minutes, seconds);
46+
}
47+
catch (FormatException e)
48+
{
49+
modelState.Errors.Add(e);
50+
}
51+
52+
bindingContext.ModelState.Add(bindingContext.ModelName, modelState);
53+
54+
return actualValue;
55+
}
56+
else
57+
{
58+
return base.BindModel(controllerContext, bindingContext);
59+
}
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)