Last active
February 11, 2016 15:00
-
-
Save karbyninc/40879a6e7c0ef5f8a0e5 to your computer and use it in GitHub Desktop.
This file contains 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 IQueryable<CustomerPurchases> GetPurchases(int customerID) | |
{ | |
return _purchaseService.GetPurchases(customerID); | |
} |
This file contains 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 CouponCodeConstraint : IHttpRouteConstraint | |
{ | |
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, | |
IDictionary<string, object> values, HttpRouteDirection routeDirection) | |
{ | |
object o; | |
if (values.TryGetValue(parameterName, out o) && o != null) | |
{ | |
if (!values.TryGetValue(parameterName, out o) || o == null) | |
return false; | |
///Coupon Code must be in format c#####c, i.e. A12345D | |
return (Regex.Match(Convert.ToString(o), "^[a-zA-Z][0-9]{5}[a-zA-Z]$").Success); | |
} | |
return false; | |
} | |
} |
This file contains 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 static class WebApiConfig | |
{ | |
public static void Register(HttpConfiguration config) | |
{ | |
// Web API configuration and services | |
var constraintResolver = new DefaultInlineConstraintResolver(); | |
constraintResolver.ConstraintMap.Add("coupon", typeof(CouponCodeConstraint)); | |
// Web API routes | |
config.MapHttpAttributeRoutes(constraintResolver); | |
config.Routes.MapHttpRoute( | |
name: "DefaultApi", | |
routeTemplate: "api/{controller}/{id}", | |
defaults: new { id = RouteParameter.Optional } | |
); | |
} | |
} |
This file contains 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
[HttpGet, Route("{couponCode:coupon}")] | |
public HttpResponseMessage GetCoupon(String couponCode) | |
{ | |
... | |
} |
This file contains 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
[HttpGet, Route("api/customer/{customerID}/purchases")] |
This file contains 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
[HttpGet, Route("api/customer/{customerID}/purchases")] | |
public IQueryable<CustomerPurchases> GetPurchases(int customerID) | |
{ | |
return _purchaseService.GetPurchases(customerID); | |
} |
This file contains 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
[RoutePrefix("api/customer")] | |
public class CustomerController : ApiController |
This file contains 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
[HttpGet, Route("{customerID}")] |
This file contains 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
[HttpGet, Route("api/customer/{customerID:guid}/purchases")] |
This file contains 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
[Route("api/pages/{pageNum:int=1}")] |
This file contains 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
[Route("api/pages/{pageNum:int?}")] |
This file contains 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
[Route("{customerID:minlength(1):alpha}")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment