Skip to content

Commit 8f21df3

Browse files
lewischeng-msxuzhg
authored andcommitted
Check in OData.vNext. Merge PR: #353
1 parent dadf266 commit 8f21df3

27 files changed

Lines changed: 1397 additions & 1 deletion

.gitignore

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,23 @@ _[Ss]cripts
1515
*.vsp
1616
*.psess
1717
*.orig
18-
*.sln.ide
18+
*.sln.ide
19+
.nuget/
20+
*.sln.ide/
21+
_ReSharper.*/
22+
packages/
23+
artifacts/
24+
PublishProfiles/
25+
.vs/
26+
debugSettings.json
27+
project.lock.json
28+
*.docstates
29+
*net45.csproj
30+
*net451.csproj
31+
*k10.csproj
32+
*.pidb
33+
*.userprefs
34+
*DS_Store
35+
*.ncrunchsolution
36+
*.*sdf
37+
*.ipch

vNext/NuGet.Config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="odlnightly" value="https://www.myget.org/F/odlnightly/api/v2" />
5+
<add key="NuGet" value="https://nuget.org/api/v2/" />
6+
</packageSources>
7+
</configuration>

vNext/WebApiOData.sln

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.22823.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3E55571F-8E8F-448A-ACE8-63849EE0871F}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E02A56F8-1F9A-4988-A929-D10582529C21}"
9+
ProjectSection(SolutionItems) = preProject
10+
global.json = global.json
11+
EndProjectSection
12+
EndProject
13+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.OData", "src\Microsoft.AspNet.OData\Microsoft.AspNet.OData.xproj", "{391207F8-D7ED-4233-BAD9-ABBFF700B71C}"
14+
EndProject
15+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{CB7EBE84-3A72-454A-BDFF-C2A604A98C11}"
16+
EndProject
17+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.OData.Test", "test\Microsoft.AspNet.OData.Test\Microsoft.AspNet.OData.Test.xproj", "{0B959ACA-F82B-43C4-946A-39066B4FA8C3}"
18+
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{CDB37674-D801-412C-9B1A-2103A114D41B}"
20+
EndProject
21+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ODataSample.Web", "samples\ODataSample.Web\ODataSample.Web.xproj", "{533D4AD6-FCE4-41D5-85BE-891A2D092B72}"
22+
EndProject
23+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{31922483-4CE7-4B02-88E4-EAF27D5E941B}"
24+
EndProject
25+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ResxGenerator", "tools\ResxGenerator\ResxGenerator.xproj", "{DACCD7F1-5E28-4AFF-BBA9-CB42F892A20C}"
26+
EndProject
27+
Global
28+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
29+
Debug|Any CPU = Debug|Any CPU
30+
Release|Any CPU = Release|Any CPU
31+
EndGlobalSection
32+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
33+
{391207F8-D7ED-4233-BAD9-ABBFF700B71C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{391207F8-D7ED-4233-BAD9-ABBFF700B71C}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{391207F8-D7ED-4233-BAD9-ABBFF700B71C}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{391207F8-D7ED-4233-BAD9-ABBFF700B71C}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{0B959ACA-F82B-43C4-946A-39066B4FA8C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{0B959ACA-F82B-43C4-946A-39066B4FA8C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{0B959ACA-F82B-43C4-946A-39066B4FA8C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{0B959ACA-F82B-43C4-946A-39066B4FA8C3}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{533D4AD6-FCE4-41D5-85BE-891A2D092B72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{533D4AD6-FCE4-41D5-85BE-891A2D092B72}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{533D4AD6-FCE4-41D5-85BE-891A2D092B72}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{533D4AD6-FCE4-41D5-85BE-891A2D092B72}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{DACCD7F1-5E28-4AFF-BBA9-CB42F892A20C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{DACCD7F1-5E28-4AFF-BBA9-CB42F892A20C}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{DACCD7F1-5E28-4AFF-BBA9-CB42F892A20C}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{DACCD7F1-5E28-4AFF-BBA9-CB42F892A20C}.Release|Any CPU.Build.0 = Release|Any CPU
49+
EndGlobalSection
50+
GlobalSection(SolutionProperties) = preSolution
51+
HideSolutionNode = FALSE
52+
EndGlobalSection
53+
GlobalSection(NestedProjects) = preSolution
54+
{391207F8-D7ED-4233-BAD9-ABBFF700B71C} = {3E55571F-8E8F-448A-ACE8-63849EE0871F}
55+
{0B959ACA-F82B-43C4-946A-39066B4FA8C3} = {CB7EBE84-3A72-454A-BDFF-C2A604A98C11}
56+
{533D4AD6-FCE4-41D5-85BE-891A2D092B72} = {CDB37674-D801-412C-9B1A-2103A114D41B}
57+
{DACCD7F1-5E28-4AFF-BBA9-CB42F892A20C} = {31922483-4CE7-4B02-88E4-EAF27D5E941B}
58+
EndGlobalSection
59+
EndGlobal

vNext/global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": [ "src", "test" ],
3+
"sdk": {
4+
"version": "1.0.0-beta4"
5+
}
6+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNet.Mvc;
6+
using Microsoft.Framework.DependencyInjection;
7+
using ODataSample.Web.Models;
8+
9+
namespace ODataSample.Web.Controllers
10+
{
11+
[Route("api/Customers")]
12+
public class CustomersController : Controller
13+
{
14+
private readonly SampleContext _sampleContext;
15+
16+
public CustomersController(SampleContext sampleContext)
17+
{
18+
_sampleContext = sampleContext;
19+
}
20+
21+
// GET: api/Customers
22+
[HttpGet]
23+
public IEnumerable<Customer> Get()
24+
{
25+
return _sampleContext.Customers;
26+
}
27+
28+
// GET api/Customers/5
29+
[HttpGet("{id}")]
30+
public IActionResult Get(int id)
31+
{
32+
return Json(_sampleContext.Customers.Single(p => p.CustomerId == id));
33+
}
34+
35+
// POST api/Customers
36+
[HttpPost]
37+
public IActionResult Post([FromBody]Customer value)
38+
{
39+
var locationUri = $"http://localhost:9091/api/Customers/{value.CustomerId}";
40+
return Created(locationUri, _sampleContext.AddCustomer(value));
41+
}
42+
43+
// PUT api/Customers/5
44+
[HttpPut("{id}")]
45+
public IActionResult Put(int id, [FromBody]Customer value)
46+
{
47+
if (!_sampleContext.UpdateCustomer(id, value))
48+
{
49+
return HttpNotFound();
50+
}
51+
52+
return new NoContentResult();
53+
}
54+
55+
// DELETE api/Customers/5
56+
[HttpDelete("{id}")]
57+
public IActionResult Delete(int id)
58+
{
59+
if (!_sampleContext.DeleteCustomer(id))
60+
{
61+
return HttpNotFound();
62+
}
63+
64+
return new NoContentResult();
65+
}
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNet.Mvc;
6+
using Microsoft.Framework.DependencyInjection;
7+
using ODataSample.Web.Models;
8+
9+
namespace ODataSample.Web.Controllers
10+
{
11+
[Route("api/Products")]
12+
public class ProductsController : Controller
13+
{
14+
private readonly SampleContext _sampleContext;
15+
16+
public ProductsController(SampleContext sampleContext)
17+
{
18+
_sampleContext = sampleContext;
19+
}
20+
21+
// GET: api/Products
22+
[HttpGet]
23+
public IEnumerable<Product> Get()
24+
{
25+
return _sampleContext.Products;
26+
}
27+
28+
// GET api/Products/5
29+
[HttpGet("{id}")]
30+
public IActionResult Get(int id)
31+
{
32+
return Json(_sampleContext.Products.Single(p => p.ProductId == id));
33+
}
34+
35+
// POST api/Products
36+
[HttpPost]
37+
public IActionResult Post([FromBody]Product value)
38+
{
39+
var locationUri = $"http://localhost:9091/api/Products/{value.ProductId}";
40+
return Created(locationUri, _sampleContext.AddProduct(value));
41+
}
42+
43+
// PUT api/Products/5
44+
[HttpPut("{id}")]
45+
public IActionResult Put(int id, [FromBody]Product value)
46+
{
47+
if (!_sampleContext.UpdateProduct(id, value))
48+
{
49+
return HttpNotFound();
50+
}
51+
52+
return new NoContentResult();
53+
}
54+
55+
// DELETE api/Products/5
56+
[HttpDelete("{id}")]
57+
public IActionResult Delete(int id)
58+
{
59+
if (!_sampleContext.DeleteProduct(id))
60+
{
61+
return HttpNotFound();
62+
}
63+
64+
return new NoContentResult();
65+
}
66+
}
67+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace ODataSample.Web.Models
7+
{
8+
public class Customer
9+
{
10+
public int CustomerId { get; set; }
11+
public string FirstName { get; set; }
12+
public string LastName { get; set; }
13+
public IEnumerable<Product> Products { get; set; }
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace ODataSample.Web.Models
7+
{
8+
public interface ISampleService
9+
{
10+
IEnumerable<Product> Products { get; }
11+
IEnumerable<Customer> Customers { get; }
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ODataSample.Web.Models
2+
{
3+
public class Product
4+
{
5+
public int ProductId { get; set; }
6+
public string Name { get; set; }
7+
public double Price { get; set; }
8+
}
9+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace ODataSample.Web.Models
5+
{
6+
public class SampleContext : ISampleService
7+
{
8+
#region In-memory data
9+
private readonly List<Product> _products = new List<Product>
10+
{
11+
new Product { ProductId = 1, Name = "Apple", Price = 10 },
12+
new Product { ProductId = 2, Name = "Orange", Price = 20 },
13+
};
14+
15+
private readonly List<Customer> _customers = new List<Customer>
16+
{
17+
new Customer { CustomerId = 1, FirstName = "Var1", LastName = "Var2" }
18+
};
19+
20+
public SampleContext()
21+
{
22+
_customers[0].Products = new List<Product>
23+
{
24+
_products[0],
25+
_products[1]
26+
};
27+
}
28+
#endregion
29+
30+
#region ISampleService
31+
public IEnumerable<Product> Products => _products;
32+
33+
public IEnumerable<Customer> Customers => _customers;
34+
#endregion
35+
36+
#region Products business logic
37+
public Product AddProduct(Product product)
38+
{
39+
var existingProduct = _products.SingleOrDefault(p => p.ProductId == product.ProductId);
40+
if (existingProduct != null)
41+
{
42+
return existingProduct;
43+
}
44+
45+
_products.Add(product);
46+
return product;
47+
}
48+
49+
public bool UpdateProduct(int id, Product product)
50+
{
51+
if (id != product.ProductId)
52+
{
53+
return false;
54+
}
55+
56+
var index = _products.FindIndex(p => p.ProductId == id);
57+
if (index == -1)
58+
{
59+
return false;
60+
}
61+
62+
_products[index] = product;
63+
return true;
64+
}
65+
66+
public bool DeleteProduct(int id)
67+
{
68+
int count = _products.RemoveAll(p => p.ProductId == id);
69+
return count > 0;
70+
}
71+
#endregion
72+
73+
#region Customers business logic
74+
public Customer AddCustomer(Customer customer)
75+
{
76+
var existingCustomer = _customers.SingleOrDefault(p => p.CustomerId == customer.CustomerId);
77+
if (existingCustomer != null)
78+
{
79+
return existingCustomer;
80+
}
81+
82+
_customers.Add(customer);
83+
return customer;
84+
}
85+
86+
public bool UpdateCustomer(int id, Customer customer)
87+
{
88+
if (id != customer.CustomerId)
89+
{
90+
return false;
91+
}
92+
93+
var index = _customers.FindIndex(p => p.CustomerId == id);
94+
if (index == -1)
95+
{
96+
return false;
97+
}
98+
99+
_customers[index] = customer;
100+
return true;
101+
}
102+
103+
public bool DeleteCustomer(int id)
104+
{
105+
int count = _customers.RemoveAll(p => p.CustomerId == id);
106+
return count > 0;
107+
}
108+
#endregion
109+
}
110+
}

0 commit comments

Comments
 (0)