diff --git a/Mvc.sln b/Mvc.sln index d0bc676261..487d3c64e4 100644 --- a/Mvc.sln +++ b/Mvc.sln @@ -1,7 +1,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22726.0 +VisualStudioVersion = 14.0.22806.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DAAE4C74-D06F-4874-A166-33305D2643CE}" EndProject @@ -160,6 +160,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.JsonPatch. EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.JsonPatch", "src\Microsoft.AspNet.JsonPatch\Microsoft.AspNet.JsonPatch.xproj", "{4D55F4D8-633B-462F-A5B1-FEB84BD2D534}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "JsonPatchWebSite", "test\WebSites\JsonPatchWebSite\JsonPatchWebSite.xproj", "{DAB1252D-577C-4912-98BE-1A812BF83F86}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -950,6 +952,18 @@ Global {4D55F4D8-633B-462F-A5B1-FEB84BD2D534}.Release|Mixed Platforms.Build.0 = Release|Any CPU {4D55F4D8-633B-462F-A5B1-FEB84BD2D534}.Release|x86.ActiveCfg = Release|Any CPU {4D55F4D8-633B-462F-A5B1-FEB84BD2D534}.Release|x86.Build.0 = Release|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Debug|x86.ActiveCfg = Debug|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Debug|x86.Build.0 = Debug|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Release|Any CPU.Build.0 = Release|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Release|x86.ActiveCfg = Release|Any CPU + {DAB1252D-577C-4912-98BE-1A812BF83F86}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1028,5 +1042,6 @@ Global {B42D4844-FFF8-4EC2-88D1-3AE95234D9EB} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {81C20848-E063-4E12-AC40-0B55A532C16C} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {4D55F4D8-633B-462F-A5B1-FEB84BD2D534} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E} + {DAB1252D-577C-4912-98BE-1A812BF83F86} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} EndGlobalSection EndGlobal diff --git a/samples/MvcSample.Web/Controllers/JsonPatchController.cs b/samples/MvcSample.Web/Controllers/JsonPatchController.cs index 2e6c964c19..747be302f3 100644 --- a/samples/MvcSample.Web/Controllers/JsonPatchController.cs +++ b/samples/MvcSample.Web/Controllers/JsonPatchController.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using System.Linq; using Microsoft.AspNet.JsonPatch; using Microsoft.AspNet.Mvc; @@ -34,7 +35,12 @@ namespace MvcSample.Web.Controllers } }; - patchDoc.ApplyTo(customer); + patchDoc.ApplyTo(customer, ModelState); + + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } return new ObjectResult(customer); } diff --git a/samples/MvcSample.Web/Views/JsonPatch/Index.cshtml b/samples/MvcSample.Web/Views/JsonPatch/Index.cshtml index 4e86235cf9..660fb9c426 100644 --- a/samples/MvcSample.Web/Views/JsonPatch/Index.cshtml +++ b/samples/MvcSample.Web/Views/JsonPatch/Index.cshtml @@ -7,9 +7,9 @@ "Orders": [{"OrderName": "Order1"}, {"OrderName": "Order2"}] }; - $('#currentlabel').text(JSON.stringify(currentObj)) + $('#currentLabel').text(JSON.stringify(currentObj)) - $('#addorder').on("click", function () { + $('#addOrder').on("click", function () { var obj = [{ "op": "Add", "path": "Customer/Orders/2", @@ -22,12 +22,34 @@ dataType: 'json', contentType: 'application/json-patch+json', success: function (data) { - $('#addlabel').text(JSON.stringify(data)) + $('#addLabel').text(JSON.stringify(data)) } }); }); - $('#removeorder').on("click", function () { + $('#invalidAddOrder').on("click", function () { + var obj = [{ + "op": "Add", + "path": "Customer/Orders/5", + "value": { "OrderName": "Name5" } + }] + $.ajax({ + url: 'jsonpatch', + type: 'PATCH', + data: JSON.stringify(obj), + dataType: 'json', + contentType: 'application/json-patch+json', + success: function (data) { + $('#invalidAddLabel').text(data) + }, + error: function (request, status, error) { + $('#invalidAddLabel').text(error) + } + }); + }); + + + $('#removeOrder').on("click", function () { var obj = [{ "op": "Remove", "path": "Customer/Name" @@ -39,12 +61,12 @@ dataType: 'json', contentType: 'application/json-patch+json', success: function (data) { - $('#removelabel').text(JSON.stringify(data)) + $('#removeLabel').text(JSON.stringify(data)) } }); }); - $('#moveorder').on("click", function () { + $('#moveOrder').on("click", function () { var obj = [{ "op": "Move", "from": "Customer/Orders/0", @@ -57,12 +79,12 @@ dataType: 'json', contentType: 'application/json-patch+json', success: function (data) { - $('#movelabel').text(JSON.stringify(data)) + $('#moveLabel').text(JSON.stringify(data)) } }); }); - $('#replaceorder').on("click", function () { + $('#replaceOrder').on("click", function () { var obj = [{ "op": "Replace", "path": "Customer/Name", @@ -75,7 +97,7 @@ dataType: 'json', contentType: 'application/json-patch+json', success: function (data) { - $('#replacelabel').text(JSON.stringify(data)) + $('#replaceLabel').text(JSON.stringify(data)) } }); }); @@ -86,29 +108,35 @@