-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathEmployeeController.cs
112 lines (101 loc) · 5.85 KB
/
EmployeeController.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* This file is automatically generated; any changes will be lost.
*/
namespace My.Hr.Api.Controllers;
/// <summary>
/// Provides the <see cref="Employee"/> Web API functionality.
/// </summary>
[Consumes(System.Net.Mime.MediaTypeNames.Application.Json)]
[Produces(System.Net.Mime.MediaTypeNames.Application.Json)]
public partial class EmployeeController : ControllerBase
{
private readonly WebApi _webApi;
private readonly IEmployeeManager _manager;
/// <summary>
/// Initializes a new instance of the <see cref="EmployeeController"/> class.
/// </summary>
/// <param name="webApi">The <see cref="WebApi"/>.</param>
/// <param name="manager">The <see cref="IEmployeeManager"/>.</param>
public EmployeeController(WebApi webApi, IEmployeeManager manager)
{ _webApi = webApi.ThrowIfNull(); _manager = manager.ThrowIfNull(); EmployeeControllerCtor(); }
partial void EmployeeControllerCtor(); // Enables additional functionality to be added to the constructor.
/// <summary>
/// Gets the specified <c>Employee</c>.
/// </summary>
/// <param name="id">The <c>Employee</c> identifier.</param>
/// <returns>The selected <c>Employee</c> where found.</returns>
[HttpGet("employees/{id}", Name="Employee_Get")]
[ProducesResponseType(typeof(Common.Entities.Employee), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public Task<IActionResult> Get(Guid id)
=> _webApi.GetWithResultAsync<Employee?>(Request, p => _manager.GetAsync(id));
/// <summary>
/// Creates a new <c>Employee</c>.
/// </summary>
/// <returns>The created <c>Employee</c>.</returns>
[HttpPost("employees", Name="Employee_Create")]
[AcceptsBody(typeof(Common.Entities.Employee))]
[ProducesResponseType(typeof(Common.Entities.Employee), (int)HttpStatusCode.Created)]
public Task<IActionResult> Create()
=> _webApi.PostWithResultAsync<Employee, Employee>(Request, p => _manager.CreateAsync(p.Value!), statusCode: HttpStatusCode.Created, locationUri: r => new Uri($"/employees/{r.Id}", UriKind.Relative));
/// <summary>
/// Updates an existing <c>Employee</c>.
/// </summary>
/// <param name="id">The <c>Employee</c> identifier.</param>
/// <returns>The updated <c>Employee</c>.</returns>
[HttpPut("employees/{id}", Name="Employee_Update")]
[AcceptsBody(typeof(Common.Entities.Employee))]
[ProducesResponseType(typeof(Common.Entities.Employee), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public Task<IActionResult> Update(Guid id)
=> _webApi.PutWithResultAsync<Employee, Employee>(Request, p => _manager.UpdateAsync(p.Value!, id));
/// <summary>
/// Patches an existing <c>Employee</c>.
/// </summary>
/// <param name="id">The <c>Employee</c> identifier.</param>
/// <returns>The patched <c>Employee</c>.</returns>
[HttpPatch("employees/{id}", Name="Employee_Patch")]
[AcceptsBody(typeof(Common.Entities.Employee), HttpConsts.MergePatchMediaTypeName)]
[ProducesResponseType(typeof(Common.Entities.Employee), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public Task<IActionResult> Patch(Guid id)
=> _webApi.PatchWithResultAsync<Employee>(Request, get: _ => _manager.GetAsync(id), put: p => _manager.UpdateAsync(p.Value!, id));
/// <summary>
/// Deletes the specified <c>Employee</c>.
/// </summary>
/// <param name="id">The <c>Employee</c> identifier.</param>
[HttpDelete("employees/{id}", Name="Employee_Delete")]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
public Task<IActionResult> Delete(Guid id)
=> _webApi.DeleteWithResultAsync(Request, p => _manager.DeleteAsync(id));
/// <summary>
/// Gets the <c>EmployeeBase</c> array that contains the items that match the selection criteria.
/// </summary>
/// <param name="firstName">The First Name.</param>
/// <param name="lastName">The Last Name.</param>
/// <param name="genders">The Genders.</param>
/// <param name="startFrom">The Start From.</param>
/// <param name="startTo">The Start To.</param>
/// <param name="isIncludeTerminated">Indicates whether Is Include Terminated.</param>
/// <returns>The <c>EmployeeBase</c> array</returns>
[HttpGet("employees", Name="Employee_GetByArgs")]
[Paging]
[ProducesResponseType(typeof(Common.Entities.EmployeeBaseCollection), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
public Task<IActionResult> GetByArgs(string? firstName = default, string? lastName = default, List<string?>? genders = default, DateTime? startFrom = default, DateTime? startTo = default, [FromQuery(Name="includeTerminated")] bool? isIncludeTerminated = default)
{
var args = new EmployeeArgs { FirstName = firstName, LastName = lastName, GendersSids = genders, StartFrom = startFrom, StartTo = startTo, IsIncludeTerminated = isIncludeTerminated };
return _webApi.GetWithResultAsync<EmployeeBaseCollectionResult>(Request, p => _manager.GetByArgsAsync(args, p.RequestOptions.Paging), alternateStatusCode: HttpStatusCode.NoContent);
}
/// <summary>
/// Terminates an existing <c>Employee</c>.
/// </summary>
/// <param name="id">The <c>Employee</c> identifier.</param>
/// <returns>The updated <c>Employee</c>.</returns>
[HttpPost("employees/{id}/terminate", Name="Employee_Terminate")]
[AcceptsBody(typeof(Common.Entities.TerminationDetail))]
[ProducesResponseType(typeof(Common.Entities.Employee), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public Task<IActionResult> Terminate(Guid id)
=> _webApi.PostWithResultAsync<TerminationDetail, Employee>(Request, p => _manager.TerminateAsync(p.Value!, id), alternateStatusCode: HttpStatusCode.NotFound, operationType: CoreEx.OperationType.Update);
}