Skip to content

Instantly share code, notes, and snippets.

View beyond-code-github's full-sized avatar

Pete Smith beyond-code-github

View GitHub Profile
@beyond-code-github
beyond-code-github / teacherscontroller.cs
Last active August 29, 2015 14:27
After refactoring, intent has simply been moved into the controller/model
public class TeachersController : ListController
{
protected override ListConfig Configuration
{
get
{
return new ListConfig()
{
ListTitle = "List of Teachers",
PostUrl = "api/teachers",

So you've learned to code... now what? Beyond code provides blog posts, podcasts, videos and training material to help you on your journey from entry level programmer to productive software development team member

Beyond Code is important because ultimately, making software is a 'people' business, and the social/personal aspects of a team are just as important as the tech.

@beyond-code-github
beyond-code-github / teacherlist.html
Last active November 22, 2015 12:35
Teacher list after componentisation
<h1>List of teachers</h1>
<tablelist href="http://example.com/teachers">
<column id="notes"></column>
<column id="text"></columns>
</tablelist>
<bulkupload id="teacherUpload">
</bulkupload>
@beyond-code-github
beyond-code-github / gist:4723682
Created February 6, 2013 16:16
Read a delta from a custom media type formatter... if a bit naughty.
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<EfContext>("EfContext");
IEdmModel model = builder.GetEdmModel();
var odataFormatters = ODataMediaTypeFormatters.Create(model);
var delta = content.ReadAsAsync(type, odataFormatters).Result;
@beyond-code-github
beyond-code-github / gist:5048997
Created February 27, 2013 15:59
Useful feature for Delta<T> - Get previous and current values for changed properties
public Dictionary<string, Tuple<object, object>> GetChanges(TEntityType original)
{
if (original == null)
{
throw new ArgumentNullException("original");
}
if (!_entityType.IsAssignableFrom(original.GetType()))
{
throw new InvalidOperationException(string.Format("Entity mismatch exception between {0} and {1}", _entityType, original.GetType()));
@beyond-code-github
beyond-code-github / Config
Last active December 14, 2015 15:18
We have two different kinds of route at present, /Api/{AppId}/{Controller}/{Id} and /Api/{Controller}/{Id}. The Linked route provider ensures that if we PATCH or PUT to either of these that we also invalidate the cache for the same route without the {Id} parameter
config.MessageHandlers.Add(new CachingHandler
{
UriTrimmer = (uri) => uri.LocalPath,
LinkedRoutePatternProvider = LinkedRoutePatternProvider
});
public static IEnumerable<string> LinkedRoutePatternProvider(string s, HttpMethod httpMethod)
{
var appAware = new Regex("/Api/[0-9]+/([a-z]|[A-Z])+/[0-9]+");
if (appAware.IsMatch(s))
@beyond-code-github
beyond-code-github / gist:5115938
Last active December 14, 2015 16:29
Quick sketch of pulling together data required to build nested routes
var timer = new Stopwatch();
timer.Start();
var configuration = GlobalConfiguration.Configuration;
var explorer = new ApiExplorer(configuration);
var descriptions = explorer.ApiDescriptions;
var controllerDescriptors = descriptions.Select(o => o.ActionDescriptor.ControllerDescriptor).Distinct().ToList();
@beyond-code-github
beyond-code-github / gist:5142264
Last active December 14, 2015 20:09
Very simple example of hierarchical route generation in asp.net web api
// Base route
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
// Nested route (must be distinguishable by param names from above) - Deisgnated by leading _
config.Routes.MapHttpRoute("NestedRoute", "_/{controller}/{rootId}");
// Root controller signature:
public class AppDataController : ApiController
{
public static void RegisterCors(HttpConfiguration httpConfiguration)
{
WebApiCorsConfiguration corsConfig = new WebApiCorsConfiguration();
corsConfig.RegisterGlobal(httpConfiguration);
corsConfig.ForAllOrigins().AllowMethods("GET", "POST", "PUT", "PATCH", "DELETE").AllowAllRequestHeaders();
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (this.Context.Request.Path.Contains("signalr/"))
{
this.Context.Response.AddHeader("Access-Control-Allow-Headers", "accept,origin,authorization,content-type");
}
}