diff --git a/src/Microsoft.Data.Domain.Samples.Northwind/Controllers/NorthwindController.cs b/src/Microsoft.Data.Domain.Samples.Northwind/Controllers/NorthwindController.cs index ddf8625f..82504b39 100644 --- a/src/Microsoft.Data.Domain.Samples.Northwind/Controllers/NorthwindController.cs +++ b/src/Microsoft.Data.Domain.Samples.Northwind/Controllers/NorthwindController.cs @@ -19,6 +19,7 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System.Linq; +using System.Web.Http; using System.Web.OData; using System.Web.OData.Domain; using System.Web.OData.Routing; @@ -37,10 +38,47 @@ private NorthwindContext DbContext } } + // OData Attibute Routing [ODataRoute("Customers({key})/CompanyName")] + [ODataRoute("Customers({key})/CompanyName/$value")] public string GetCustomerCompanyName([FromODataUri]string key) { return DbContext.Customers.Where(c => c.CustomerID == key).Select(c => c.CompanyName).FirstOrDefault(); } + + [ODataRoute("Products/$count")] + public IHttpActionResult GetProductsCount() + { + return Ok(DbContext.Products.Count()); + } + + [HttpPut] + [ODataRoute("Products({key})/UnitPrice")] + public IHttpActionResult UpdateProductUnitPrice(int key, [FromBody]decimal price) + { + var entity = DbContext.Products.Find(key); + if (entity == null) + { + return NotFound(); + } + entity.UnitPrice = price; + + try + { + DbContext.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!DbContext.Products.Any(p => p.ProductID == key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Ok(price); + } } } diff --git a/src/Microsoft.Data.Domain.Samples.Northwind/Models/NorthwindDomain.cs b/src/Microsoft.Data.Domain.Samples.Northwind/Models/NorthwindDomain.cs index 7089a051..74d614cb 100644 --- a/src/Microsoft.Data.Domain.Samples.Northwind/Models/NorthwindDomain.cs +++ b/src/Microsoft.Data.Domain.Samples.Northwind/Models/NorthwindDomain.cs @@ -19,10 +19,7 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System; -using System.Collections.Generic; -using System.Data.Entity; using System.Linq; -using System.Web; using Microsoft.Data.Domain.EntityFramework; using Microsoft.Data.Domain.Security; @@ -30,17 +27,29 @@ namespace Microsoft.Data.Domain.Samples.Northwind.Models { [EnableConventions] [EnableRoleBasedSecurity] - [Grant(DomainPermissionType.Inspect)] [Grant(DomainPermissionType.All, On = "Customers")] - [Grant(DomainPermissionType.All, On = "Employees")] - [Grant(DomainPermissionType.All, On = "CurrentOrders")] - [Grant(DomainPermissionType.All, On = "Orders")] //, To = "Manager")] [Grant(DomainPermissionType.All, On = "Products")] + [Grant(DomainPermissionType.All, On = "CurrentOrders")] + [Grant(DomainPermissionType.All, On = "ExpensiveProducts")] + [Grant(DomainPermissionType.All, On = "Orders")] + [Grant(DomainPermissionType.All, On = "Employees")] + [Grant(DomainPermissionType.Inspect, On = "Suppliers")] + [Grant(DomainPermissionType.Read, On = "Suppliers")] + public class NorthwindDomain : DbDomain { public NorthwindContext Context { get { return DbContext; } } - // [Assert("Manager")] + // Imperative views. Currenly CUD operations not supported + protected IQueryable ExpensiveProducts + { + get + { + return this.Source("Products") + .Where(c => c.UnitPrice > 50); + } + } + protected IQueryable CurrentOrders { get @@ -50,9 +59,26 @@ protected IQueryable CurrentOrders } } + // Entity set filter private IQueryable OnFilterCustomers(IQueryable customers) { return customers.Where(c => c.CountryRegion == "France"); } + + // Submit logic + private void OnUpdatingProducts(Product product) + { + WriteLog(DateTime.Now.ToString() + product.ProductID + " is being updated"); + } + + private void OnInsertedProducts(Product product) + { + WriteLog(DateTime.Now.ToString() + product.ProductID + " has been inserted"); + } + + private void WriteLog(string text) + { + // Fake writing log method for submit logic demo + } } } \ No newline at end of file diff --git a/test/Microsoft.Data.Domain.Samples.Northwind.Tests/Baselines/TestGetNorthwindMetadata.txt b/test/Microsoft.Data.Domain.Samples.Northwind.Tests/Baselines/TestGetNorthwindMetadata.txt index 40707a1d..9f0a1d2a 100644 --- a/test/Microsoft.Data.Domain.Samples.Northwind.Tests/Baselines/TestGetNorthwindMetadata.txt +++ b/test/Microsoft.Data.Domain.Samples.Northwind.Tests/Baselines/TestGetNorthwindMetadata.txt @@ -398,19 +398,11 @@ - - - - - - - - @@ -421,44 +413,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +