👷♂️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| routes.MapHttpRoute( | |
| name: "DefaultApi", | |
| routeTemplate: "api/{controller}/{action}/{id}", | |
| defaults: new { id = RouteParameter.Optional } | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var builder = new ContainerBuilder(); | |
| builder.Register<ICustomerRepository, CustomerRepository>(); | |
| var container = builder.Build(); | |
| var config = GlobalConfiguration.Configuration; | |
| config.ServiceResolver.SetResolver( | |
| t => container.Resolve(t), | |
| t => container.ResolveAll(t)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Customer { | |
| public int Id { get; set; } | |
| [Required] | |
| public string Name { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ValidationActionFilter : ActionFilterAttribute | |
| { | |
| public override void OnActionExecuting(HttpActionContext context) | |
| { | |
| var modelState = context.ModelState; | |
| if (!modelState.IsValid) | |
| { | |
| dynamic errors = new JsonObject(); | |
| foreach (var key in modelState.Keys) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.ajax({ | |
| url: '/api/customers', | |
| cache: false, | |
| type: 'POST', | |
| data: json, | |
| contentType: 'application/json; charset=utf-8', | |
| statusCode: { | |
| 201 /*Created*/: function (data) { | |
| viewModel.customers.push(data); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <label for="customer">Customer</label> | |
| <input id="customer" name="customer" type="text" data-val="true" data-val-required="Kunden-Name benötigt" value="" /> | |
| <span class="field-validation-valid" data-valmsg-for="customer" data-valmsg-replace="true"></span> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void Main() | |
| { | |
| var config = new HttpSelfHostConfiguration("http://localhost:9191"); | |
| config.Routes.MapHttpRoute("default", "{controller}/{id}", | |
| new { id = UrlParameter.Optional }); | |
| var builder = new ContainerBuilder(); | |
| builder.Bind<ICustomerRepository, CustomerRepository>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// This filter will manage the session for all of the controllers that needs a Raven Document Session. | |
| /// It does so by automatically injecting a session to the first public property of type IDocumentSession available | |
| /// on the controller. | |
| /// </summary> | |
| public class RavenActionFilterAttribute : ActionFilterAttribute { | |
| public override void OnActionExecuting(HttpActionContext filterContext) { | |
| filterContext.Request.Properties["RavenDocumentStore"] = | |
| DocumentStoreHolder.TryAddSession(filterContext.ControllerContext.Controller); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// This class manages the state of objects that desire a document session. We aren't relying on an IoC container here | |
| /// because this is the sole case where we actually need to do injection. | |
| /// </summary> | |
| public class DocumentStoreHolder { | |
| private static IDocumentStore documentStore; | |
| public static IDocumentStore DocumentStore { | |
| get { return (documentStore ?? (documentStore = CreateDocumentStore())); } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RavenController : ApiController { | |
| public new IDocumentSession Session { get; set; } | |
| } |