1
+ // ***********************************************************************
2
+ // Assembly : RzR.Shared.ResultMessage.AggregatedGenericResultMessage.Web
3
+ // Author : RzR
4
+ // Created On : 2024-12-24 13:56
5
+ //
6
+ // Last Modified By : RzR
7
+ // Last Modified On : 2024-12-26 18:30
8
+ // ***********************************************************************
9
+ // <copyright file="ResultToProblemDetails.cs" company="RzR SOFT & TECH">
10
+ // Copyright © RzR. All rights reserved.
11
+ // </copyright>
12
+ //
13
+ // <summary>
14
+ // </summary>
15
+ // ***********************************************************************
16
+
17
+ #region U S A G E S
18
+
19
+ using AggregatedGenericResultMessage . Abstractions ;
20
+ using AggregatedGenericResultMessage . Web . Helpers ;
21
+ using Microsoft . AspNetCore . Mvc ;
22
+ using System . Collections . Generic ;
23
+ using System . Net ;
24
+
25
+ #endregion
26
+
27
+ namespace AggregatedGenericResultMessage . Web . Extensions . ProblemDetail
28
+ {
29
+ /// -------------------------------------------------------------------------------------------------
30
+ /// <summary>
31
+ /// `Result` extension methods that are converted to the `ProblemDetails` model with customization possibilities.
32
+ /// </summary>
33
+ /// =================================================================================================
34
+ public static class ResultToProblemDetails
35
+ {
36
+ /// -------------------------------------------------------------------------------------------------
37
+ /// <summary>
38
+ /// An IResult extension method that converts this object to to problem details.
39
+ /// </summary>
40
+ /// <typeparam name="T">Generic type parameter.</typeparam>
41
+ /// <param name="result">The result to act on.</param>
42
+ /// <param name="statusCode">The HTTP status code.</param>
43
+ /// <param name="message">(Optional) The custom `ProblemDetails` message.</param>
44
+ /// <param name="detailMessage">(Optional) The custom message `ProblemDetails` describing the detail.</param>
45
+ /// <param name="accessedResourceUri">(Optional) URI of the accessed resource.</param>
46
+ /// <param name="additionInformation">(Optional) Information describing the addition `ProblemDetails` objects.</param>
47
+ /// <returns>
48
+ /// An ObjectResult.
49
+ /// </returns>
50
+ /// =================================================================================================
51
+ public static ObjectResult AsToProblemDetails < T > (
52
+ this Result < T > result ,
53
+ HttpStatusCode statusCode ,
54
+ string message = null ,
55
+ string detailMessage = null ,
56
+ string accessedResourceUri = null ,
57
+ IDictionary < string , object > additionInformation = null )
58
+ => ResultProblemDetailsHelper . BuildObjectResult ( result , statusCode , message , detailMessage , accessedResourceUri , additionInformation ) ;
59
+
60
+ /// -------------------------------------------------------------------------------------------------
61
+ /// <summary>
62
+ /// An IResult extension method that converts this object to to problem details.
63
+ /// </summary>
64
+ /// <typeparam name="T">Generic type parameter.</typeparam>
65
+ /// <param name="result">The result to act on.</param>
66
+ /// <param name="statusCode">The HTTP status code.</param>
67
+ /// <param name="message">(Optional) The custom `ProblemDetails` message.</param>
68
+ /// <param name="detailMessage">(Optional) The custom message `ProblemDetails` describing the detail.</param>
69
+ /// <param name="accessedResourceUri">(Optional) URI of the accessed resource.</param>
70
+ /// <param name="additionInformation">(Optional) Information describing the addition `ProblemDetails` objects.</param>
71
+ /// <returns>
72
+ /// An ObjectResult.
73
+ /// </returns>
74
+ /// =================================================================================================
75
+ public static ObjectResult AsToProblemDetails (
76
+ this Result result ,
77
+ HttpStatusCode statusCode ,
78
+ string message = null ,
79
+ string detailMessage = null ,
80
+ string accessedResourceUri = null ,
81
+ IDictionary < string , object > additionInformation = null )
82
+ => ResultProblemDetailsHelper . BuildObjectResult ( result , statusCode , message , detailMessage , accessedResourceUri , additionInformation ) ;
83
+
84
+ /// -------------------------------------------------------------------------------------------------
85
+ /// <summary>
86
+ /// An IResult extension method that converts this object to to problem details.
87
+ /// </summary>
88
+ /// <typeparam name="T">Generic type parameter.</typeparam>
89
+ /// <param name="result">The result to act on.</param>
90
+ /// <param name="statusCode">The HTTP status code.</param>
91
+ /// <param name="message">(Optional) The custom `ProblemDetails` message.</param>
92
+ /// <param name="detailMessage">(Optional) The custom message `ProblemDetails` describing the detail.</param>
93
+ /// <param name="accessedResourceUri">(Optional) URI of the accessed resource.</param>
94
+ /// <param name="additionInformation">(Optional) Information describing the addition `ProblemDetails` objects.</param>
95
+ /// <returns>
96
+ /// An ObjectResult.
97
+ /// </returns>
98
+ /// =================================================================================================
99
+ public static ObjectResult AsToProblemDetails < T > (
100
+ this IResult < T > result ,
101
+ HttpStatusCode statusCode ,
102
+ string message = null ,
103
+ string detailMessage = null ,
104
+ string accessedResourceUri = null ,
105
+ IDictionary < string , object > additionInformation = null )
106
+ => ResultProblemDetailsHelper . BuildObjectResult ( result , statusCode , message , detailMessage , accessedResourceUri , additionInformation ) ;
107
+
108
+ /// -------------------------------------------------------------------------------------------------
109
+ /// <summary>
110
+ /// An IResult extension method that converts this object to to problem details.
111
+ /// </summary>
112
+ /// <typeparam name="T">Generic type parameter.</typeparam>
113
+ /// <param name="result">The result to act on.</param>
114
+ /// <param name="statusCode">The HTTP status code.</param>
115
+ /// <param name="message">(Optional) The custom `ProblemDetails` message.</param>
116
+ /// <param name="detailMessage">(Optional) The custom message `ProblemDetails` describing the detail.</param>
117
+ /// <param name="accessedResourceUri">(Optional) URI of the accessed resource.</param>
118
+ /// <param name="additionInformation">(Optional) Information describing the addition `ProblemDetails` objects.</param>
119
+ /// <returns>
120
+ /// An ObjectResult.
121
+ /// </returns>
122
+ /// =================================================================================================
123
+ public static ObjectResult AsToProblemDetails (
124
+ this IResult result ,
125
+ HttpStatusCode statusCode ,
126
+ string message = null ,
127
+ string detailMessage = null ,
128
+ string accessedResourceUri = null ,
129
+ IDictionary < string , object > additionInformation = null )
130
+ => ResultProblemDetailsHelper . BuildObjectResult ( result , statusCode , message , detailMessage , accessedResourceUri , additionInformation ) ;
131
+ }
132
+ }
0 commit comments