Browse Source

[WebApiUtils] Simplified BMRHandler

develop
Robin Thoni 9 years ago
parent
commit
de8d5e260d

+ 6
- 6
WebAPiUtils-test/Controllers/ValuesController.cs View File

7
 
7
 
8
 namespace WebAPiUtils_test.Controllers
8
 namespace WebAPiUtils_test.Controllers
9
 {
9
 {
10
-    public class ValuesController : ApiController
10
+    public class ValuesController : BMRHandler
11
     {
11
     {
12
         [HttpGet]
12
         [HttpGet]
13
         [Route("api/values/{id}")]
13
         [Route("api/values/{id}")]
14
         public ValuesDboGet Get(int id)
14
         public ValuesDboGet Get(int id)
15
         {
15
         {
16
-            return BMRHandler<ValuesDboGet>.Handle(ValuesBusiness.Get(id), Request);
16
+            return Handle(ValuesBusiness.Get(id));
17
         }
17
         }
18
 
18
 
19
         [HttpGet]
19
         [HttpGet]
20
         [Route("api/values/contains")]
20
         [Route("api/values/contains")]
21
         public DboGetMultiple<ValuesDboGet> Contains(string text, int page = 0, int perPage = Int32.MaxValue)
21
         public DboGetMultiple<ValuesDboGet> Contains(string text, int page = 0, int perPage = Int32.MaxValue)
22
         {
22
         {
23
-            return BMRHandler<DboGetMultiple<ValuesDboGet>>.Handle(ValuesBusiness.Contains(text, page, perPage), Request);
23
+            return Handle(ValuesBusiness.Contains(text, page, perPage));
24
         }
24
         }
25
 
25
 
26
         [HttpPost]
26
         [HttpPost]
27
         [Route("api/values/edit/{id}")]
27
         [Route("api/values/edit/{id}")]
28
         public bool Edit(long id, ValuesDboEdit obj)
28
         public bool Edit(long id, ValuesDboEdit obj)
29
         {
29
         {
30
-            return BMRHandler<bool>.Handle(ValuesBusiness.Edit(obj, id), Request);
30
+            return Handle(ValuesBusiness.Edit(obj, id));
31
         }
31
         }
32
 
32
 
33
         [HttpPost]
33
         [HttpPost]
34
         [Route("api/values/add")]
34
         [Route("api/values/add")]
35
         public long Add(ValuesDboAdd obj)
35
         public long Add(ValuesDboAdd obj)
36
         {
36
         {
37
-            return BMRHandler<long>.Handle(ValuesBusiness.Add(obj), Request);
37
+            return Handle(ValuesBusiness.Add(obj));
38
         }
38
         }
39
 
39
 
40
         [HttpPost]
40
         [HttpPost]
41
         [Route("api/values/adddbo")]
41
         [Route("api/values/adddbo")]
42
         public ValuesDboGet AddDbo(ValuesDboAdd obj)
42
         public ValuesDboGet AddDbo(ValuesDboAdd obj)
43
         {
43
         {
44
-            return BMRHandler<ValuesDboGet>.Handle(ValuesBusiness.AddDbo(obj), Request);
44
+            return Handle(ValuesBusiness.AddDbo(obj));
45
         }
45
         }
46
     }
46
     }
47
 }
47
 }

+ 1
- 1
WebAPiUtils-test/WebAPiUtils-test.csproj View File

48
       <Private>True</Private>
48
       <Private>True</Private>
49
     </Reference>
49
     </Reference>
50
     <Reference Include="Logs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
50
     <Reference Include="Logs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
51
-      <HintPath>..\packages\Logs.dll.1.2.2\lib\net45\Logs.dll</HintPath>
51
+      <HintPath>..\packages\Logs.dll.1.2.5\lib\net45\Logs.dll</HintPath>
52
       <Private>True</Private>
52
       <Private>True</Private>
53
     </Reference>
53
     </Reference>
54
     <Reference Include="Microsoft.CSharp" />
54
     <Reference Include="Microsoft.CSharp" />

+ 1
- 1
WebAPiUtils-test/packages.config View File

8
   <package id="EnterpriseLibrary.Logging.Database" version="6.0.1304.0" targetFramework="net45" />
8
   <package id="EnterpriseLibrary.Logging.Database" version="6.0.1304.0" targetFramework="net45" />
9
   <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
9
   <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
10
   <package id="jQuery" version="1.10.2" targetFramework="net45" />
10
   <package id="jQuery" version="1.10.2" targetFramework="net45" />
11
-  <package id="Logs.dll" version="1.2.2" targetFramework="net45" />
11
+  <package id="Logs.dll" version="1.2.5" targetFramework="net45" />
12
   <package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
12
   <package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
13
   <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
13
   <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
14
   <package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />
14
   <package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />

+ 1
- 1
WebApiUtils/BusinessManager/Attributes/ExceptionLoggerAttribute.cs View File

12
         public override void OnException(HttpActionExecutedContext context)
12
         public override void OnException(HttpActionExecutedContext context)
13
         {
13
         {
14
             var result = Logger.Error<int>(ResultStatus.InternalError, context.Exception);
14
             var result = Logger.Error<int>(ResultStatus.InternalError, context.Exception);
15
-            context.Response = context.Request.CreateErrorResponse(BMRHandler<int>.ResultStatusToHttp(result.Status), BMRHandler<int>.OpResultToString(result));
15
+            context.Response = context.Request.CreateErrorResponse(BMRHandler.ResultStatusToHttp(result.Status), BMRHandler.OpResultToString(result));
16
         }
16
         }
17
     }
17
     }
18
 }
18
 }

+ 4
- 5
WebApiUtils/BusinessManager/BMRHandler.cs View File

9
     /// <summary>
9
     /// <summary>
10
     /// Handle business manager results
10
     /// Handle business manager results
11
     /// </summary>
11
     /// </summary>
12
-    /// <typeparam name="T">Data type</typeparam>
13
-    public class BMRHandler<T>
12
+    public class BMRHandler : ApiController
14
     {
13
     {
15
         /// <summary>
14
         /// <summary>
16
         /// Converts ResultStatus codes to HttpStatusCodes codes
15
         /// Converts ResultStatus codes to HttpStatusCodes codes
35
         /// </summary>
34
         /// </summary>
36
         /// <param name="result">The result of the operation</param>
35
         /// <param name="result">The result of the operation</param>
37
         /// <returns>The error string</returns>
36
         /// <returns>The error string</returns>
38
-        public static string OpResultToString(OpResult<T> result)
37
+        public static string OpResultToString<T>(OpResult<T> result)
39
         {
38
         {
40
             if (result.PublicDetails != null)
39
             if (result.PublicDetails != null)
41
                 return result.PublicDetails;
40
                 return result.PublicDetails;
58
         /// <param name="result">The result to handle</param>
57
         /// <param name="result">The result to handle</param>
59
         /// <param name="request">The request to handle</param>
58
         /// <param name="request">The request to handle</param>
60
         /// <returns>The data to return to the user</returns>
59
         /// <returns>The data to return to the user</returns>
61
-        public static T Handle(OpResult<T> result, HttpRequestMessage request)
60
+        public T Handle<T>(OpResult<T> result)
62
         {
61
         {
63
             if (result.Status == ResultStatus.Success)
62
             if (result.Status == ResultStatus.Success)
64
                 return result.Data;
63
                 return result.Data;
65
             result.Log();
64
             result.Log();
66
-            var msg = request.CreateErrorResponse(ResultStatusToHttp(result.Status), OpResultToString(result));
65
+            var msg = Request.CreateErrorResponse(ResultStatusToHttp(result.Status), OpResultToString(result));
67
             throw new HttpResponseException(msg);
66
             throw new HttpResponseException(msg);
68
         }
67
         }
69
     }
68
     }

+ 0
- 2279
WebApiUtils/Dynamic Expressions.html
File diff suppressed because it is too large
View File


+ 0
- 3
WebApiUtils/WebApiUtils.csproj View File

103
     <None Include="app.config" />
103
     <None Include="app.config" />
104
     <None Include="packages.config" />
104
     <None Include="packages.config" />
105
   </ItemGroup>
105
   </ItemGroup>
106
-  <ItemGroup>
107
-    <Content Include="Dynamic Expressions.html" />
108
-  </ItemGroup>
109
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
106
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
110
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
107
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
111
        Other similar extension points exist, see Microsoft.Common.targets.
108
        Other similar extension points exist, see Microsoft.Common.targets.

Loading…
Cancel
Save