-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppActionFilter.cs
36 lines (31 loc) · 964 Bytes
/
AppActionFilter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
namespace SoapConsumer;
public class AppActionFilter : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
if (context.ActionArguments.ContainsKey("userId"))
{
int userId = (int)context.ActionArguments["userId"];
if (userId <= 0)
{
context.ActionArguments["userId"] = 1;
}
}
}
public void OnActionExecuted(ActionExecutedContext context)
{
var user = (context.Result as ObjectResult)?.Value as ServiceReference1.User;
if (user is not null)
{
if (!user.Email.Contains('@'))
user.Email = user.Email + "@unosquare.com";
}
else
{
user = new ServiceReference1.User() { Id = 0, Name = "Not found" };
}
context.Result = new ObjectResult(user);
}
}