public class WebApiConfig
{
public static void Configure(HttpConfiguration config)
{
// remove xml formatter
config.Formatters.Remove(config.Formatters.XmlFormatter);
// use camelcase for json
$(function () { | |
$.ajax({ | |
url: "http://localhost:62351/api/projects/jsonp?siteId=10", | |
dataType: "jsonp", | |
contentType: "text/javascript", | |
success: function (data) { | |
if (!data) | |
return; | |
$.each(data, function (i, post) { |
public class RouteConfig | |
{ | |
public static void RegisterRoutes(RouteCollection routes) | |
{ | |
routes.MapHttpRoute( | |
name: "DefaultApi", | |
routeTemplate: "api/{controller}/{id}", | |
defaults: new { id = RouteParameter.Optional }, | |
constraints: new { url = new LowercaseRouteConstraint() } | |
); |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Starting migration."); | |
using (var store = new DocumentStore { ConnectionStringName = "RavenDb" }.Initialize()) | |
{ | |
using (var session = store.OpenSession()) | |
{ |
public class PagedResult<T> | |
{ | |
public PagedResult(IEnumerable<T> source, int pageIndex, int pageSize) : | |
this(source.GetPage(pageIndex, pageSize), pageIndex, pageSize, source.Count()) { } | |
public PagedResult(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount) | |
{ | |
Ensure.Argument.NotNull(source, "source"); | |
this.TotalCount = totalCount; |
public class SitesController : ApiControllerBase | |
{ | |
// GET api/sites | |
public PagedResult<Site> Get([FromUri]GetSitesCommand command) | |
{ | |
RavenQueryStatistics stats; | |
var sites = Session.Query<Domain.Site>() | |
.Statistics(out stats) | |
.NotDeleted() | |
.If(command.Hostname.IsNotNullOrEmpty(), q => q.WithHostname(command.Hostname)) |
public class ProjectMediaController : ApiControllerBase | |
{ | |
/// <summary> | |
/// Adds a new media item to a project. | |
/// </summary> | |
/// <example> | |
/// POST /api/projects/1/media | |
/// </example> | |
public HttpResponseMessage Post(int projectId, AddProjectMediaCommand command) | |
{ |
public static IDocumentQuery<T> WhereAll<T>(this IDocumentQuery<T> query, string fieldName, object[] values) | |
{ | |
if (values == null || values.Length == 0) | |
throw new ArgumentException("Cannot be a null or empty array.", "values"); | |
query.OpenSubclause(); | |
query.WhereEquals(fieldName, values[0]); | |
for (int i = 1; i < values.Length; i++) |
if (criteria.HasSalaryCriteria) | |
{ | |
var salaryFrom = criteria.SalaryFrom ?? 0; | |
var salaryTo = criteria.SalaryTo ?? int.MaxValue; | |
query.AndAlso() | |
.OpenSubclause() | |
// is Criteria.From between Salary.From and Salary.To? |
public class CustomJsonFormatter : JsonMediaTypeFormatter | |
{ | |
public override Task WriteToStreamAsync(Type type, object value, System.IO.Stream writeStream, | |
System.Net.Http.HttpContent content, System.Net.TransportContext transportContext) | |
{ | |
var objectWithLinks = value as IResourceWithLinks; | |
if (objectWithLinks != null) | |
{ | |
objectWithLinks.Links = new[] { new Link { Rel = "Self", Href = "???" } }; | |
} |