Sfoglia il codice sorgente

[WebApiUtils] Simplified BMRHandler

develop
Robin Thoni 9 anni fa
parent
commit
de8d5e260d

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

@@ -7,41 +7,41 @@ using WebAPiUtils_test.DBO;
7 7
 
8 8
 namespace WebAPiUtils_test.Controllers
9 9
 {
10
-    public class ValuesController : ApiController
10
+    public class ValuesController : BMRHandler
11 11
     {
12 12
         [HttpGet]
13 13
         [Route("api/values/{id}")]
14 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 19
         [HttpGet]
20 20
         [Route("api/values/contains")]
21 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 26
         [HttpPost]
27 27
         [Route("api/values/edit/{id}")]
28 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 33
         [HttpPost]
34 34
         [Route("api/values/add")]
35 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 40
         [HttpPost]
41 41
         [Route("api/values/adddbo")]
42 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 Vedi File

@@ -48,7 +48,7 @@
48 48
       <Private>True</Private>
49 49
     </Reference>
50 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 52
       <Private>True</Private>
53 53
     </Reference>
54 54
     <Reference Include="Microsoft.CSharp" />

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

@@ -8,7 +8,7 @@
8 8
   <package id="EnterpriseLibrary.Logging.Database" version="6.0.1304.0" targetFramework="net45" />
9 9
   <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
10 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 12
   <package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
13 13
   <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
14 14
   <package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />

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

@@ -12,7 +12,7 @@ namespace iiie.WebApiUtils.BusinessManager.Attributes
12 12
         public override void OnException(HttpActionExecutedContext context)
13 13
         {
14 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 Vedi File

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

+ 0
- 2279
WebApiUtils/Dynamic Expressions.html
File diff soppresso perché troppo grande
Vedi File


+ 0
- 3
WebApiUtils/WebApiUtils.csproj Vedi File

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

Loading…
Annulla
Salva