-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
BaseController.cs
40 lines (37 loc) · 1.42 KB
/
BaseController.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
36
37
38
39
40
using DeviceManager.Api.Constants;
using DeviceManager.Api.Resources;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace DeviceManager.Api.Controllers
{
/// <summary>
/// Base api controller all api controllers should inherit from this controller
/// </summary>
/// <typeparam name="TViewModel">Type of the view model</typeparam>
#if UseAuthentication
[Authorize]
#endif
public abstract class BaseController<TViewModel> : Controller where TViewModel : class
{
/// <summary>
/// Shared resource file
/// </summary>
protected readonly IStringLocalizer<SharedResource> SharedLocalizer;
/// <summary>
/// TODO: Pass base validation service and common CRUD operation in the base controller
/// </summary>
public BaseController(IStringLocalizer<SharedResource> sharedLocalizer)
{
this.SharedLocalizer = sharedLocalizer;
}
/// <summary>
/// Ping method to test the status of the service
/// </summary>
/// <returns>Based on the ui culture hello message is picked from the shared resource file and sent back</returns>
[HttpGet(nameof(Ping))]
[SwaggerOperation(nameof(Ping))]
public IActionResult Ping() => Json(SharedLocalizer[DefaultConstants.Hello].Value);
}
}