-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from rbeauchamp/feature/5
- Loading branch information
Showing
47 changed files
with
2,014 additions
and
269 deletions.
There are no files selected for viewing
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
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
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
6 changes: 3 additions & 3 deletions
6
Swashbuckle.OData.Tests/Customer.cs → ...kle.OData.Sample/ApiControllers/Client.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Swashbuckle.OData.Tests | ||
namespace SwashbuckleODataSample.Models | ||
{ | ||
public class Customer | ||
public class Client | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public IList<Order> Orders { get; set; } | ||
public IList<Project> Projects { get; set; } | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
Swashbuckle.OData.Sample/ApiControllers/ClientsController.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System.Data.Entity; | ||
using System.Data.Entity.Infrastructure; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using System.Web.Http.Description; | ||
using SwashbuckleODataSample.Models; | ||
|
||
namespace SwashbuckleODataSample.ApiControllers | ||
{ | ||
public class ClientsController : ApiController | ||
{ | ||
private readonly SwashbuckleODataContext db = new SwashbuckleODataContext(); | ||
|
||
// GET: api/Clients | ||
public IQueryable<Client> GetClients() | ||
{ | ||
return db.Clients; | ||
} | ||
|
||
// GET: api/Clients/5 | ||
[ResponseType(typeof (Client))] | ||
public async Task<IHttpActionResult> GetClient(int id) | ||
{ | ||
var client = await db.Clients.FindAsync(id); | ||
if (client == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(client); | ||
} | ||
|
||
// PUT: api/Clients/5 | ||
[ResponseType(typeof (void))] | ||
public async Task<IHttpActionResult> PutClient(int id, Client client) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
if (id != client.Id) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
db.Entry(client).State = EntityState.Modified; | ||
|
||
try | ||
{ | ||
await db.SaveChangesAsync(); | ||
} | ||
catch (DbUpdateConcurrencyException) | ||
{ | ||
if (!ClientExists(id)) | ||
{ | ||
return NotFound(); | ||
} | ||
throw; | ||
} | ||
|
||
return StatusCode(HttpStatusCode.NoContent); | ||
} | ||
|
||
// POST: api/Clients | ||
[ResponseType(typeof (Client))] | ||
public async Task<IHttpActionResult> PostClient(Client client) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
db.Clients.Add(client); | ||
await db.SaveChangesAsync(); | ||
|
||
return CreatedAtRoute("DefaultApi", new | ||
{ | ||
id = client.Id | ||
}, client); | ||
} | ||
|
||
// DELETE: api/Clients/5 | ||
[ResponseType(typeof (Client))] | ||
public async Task<IHttpActionResult> DeleteClient(int id) | ||
{ | ||
var client = await db.Clients.FindAsync(id); | ||
if (client == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
db.Clients.Remove(client); | ||
await db.SaveChangesAsync(); | ||
|
||
return Ok(client); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
db.Dispose(); | ||
} | ||
base.Dispose(disposing); | ||
} | ||
|
||
private bool ClientExists(int id) | ||
{ | ||
return db.Clients.Count(e => e.Id == id) > 0; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using System.Web.OData.Builder; | ||
using Microsoft.OData.Edm; | ||
|
||
namespace SwashbuckleODataSample.Models | ||
{ | ||
public class Project | ||
{ | ||
[Key] | ||
public int ProjectId { get; set; } | ||
|
||
public string ProjectName { get; set; } | ||
|
||
public int ClientId { get; set; } | ||
|
||
[ForeignKey("ClientId")] | ||
[ActionOnDelete(EdmOnDeleteAction.Cascade)] | ||
public Client Client { get; set; } | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
Swashbuckle.OData.Sample/ApiControllers/ProjectsController.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System.Data.Entity; | ||
using System.Data.Entity.Infrastructure; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using System.Web.Http.Description; | ||
using SwashbuckleODataSample.Models; | ||
|
||
namespace SwashbuckleODataSample.ApiControllers | ||
{ | ||
public class ProjectsController : ApiController | ||
{ | ||
private readonly SwashbuckleODataContext db = new SwashbuckleODataContext(); | ||
|
||
[Route("Projects/v1")] | ||
public IQueryable<Project> GetProjects() | ||
{ | ||
return db.Projects; | ||
} | ||
|
||
[Route("Projects/v1/{id}")] | ||
[ResponseType(typeof (Project))] | ||
public async Task<IHttpActionResult> GetProject(int id) | ||
{ | ||
var project = await db.Projects.FindAsync(id); | ||
if (project == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(project); | ||
} | ||
|
||
[Route("Projects/v1/{id}")] | ||
[ResponseType(typeof (void))] | ||
public async Task<IHttpActionResult> PutProject(int id, Project project) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
if (id != project.ProjectId) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
db.Entry(project).State = EntityState.Modified; | ||
|
||
try | ||
{ | ||
await db.SaveChangesAsync(); | ||
} | ||
catch (DbUpdateConcurrencyException) | ||
{ | ||
if (!ProjectExists(id)) | ||
{ | ||
return NotFound(); | ||
} | ||
throw; | ||
} | ||
|
||
return StatusCode(HttpStatusCode.NoContent); | ||
} | ||
|
||
[Route("Projects/v1")] | ||
[ResponseType(typeof (Project))] | ||
public async Task<IHttpActionResult> PostProject(Project project) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
db.Projects.Add(project); | ||
await db.SaveChangesAsync(); | ||
|
||
return CreatedAtRoute("DefaultApi", new | ||
{ | ||
id = project.ProjectId | ||
}, project); | ||
} | ||
|
||
[Route("Projects/v1/{id}")] | ||
[ResponseType(typeof (Project))] | ||
public async Task<IHttpActionResult> DeleteProject(int id) | ||
{ | ||
var project = await db.Projects.FindAsync(id); | ||
if (project == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
db.Projects.Remove(project); | ||
await db.SaveChangesAsync(); | ||
|
||
return Ok(project); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
db.Dispose(); | ||
} | ||
base.Dispose(disposing); | ||
} | ||
|
||
private bool ProjectExists(int id) | ||
{ | ||
return db.Projects.Count(e => e.ProjectId == id) > 0; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Web.Http; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace SwashbuckleODataSample | ||
{ | ||
/// <summary> | ||
/// </summary> | ||
public static class FormatterConfig | ||
{ | ||
/// <summary> | ||
/// Registers the specified configuration. | ||
/// </summary> | ||
/// <param name="config">The configuration.</param> | ||
public static void Register(HttpConfiguration config) | ||
{ | ||
var formatters = config.Formatters; | ||
|
||
formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore, | ||
DateFormatHandling = DateFormatHandling.IsoDateFormat, | ||
DateTimeZoneHandling = DateTimeZoneHandling.Utc, | ||
MetadataPropertyHandling = MetadataPropertyHandling.Ignore | ||
}; | ||
|
||
formatters.JsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter()); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.