-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerController.cs
More file actions
199 lines (162 loc) · 7.01 KB
/
Copy pathCustomerController.cs
File metadata and controls
199 lines (162 loc) · 7.01 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
namespace MBDEVproAPI.API.Controllers
{
public class CustomerController : BaseController
{
#region variables and constructors
private ICustomerService _customerService;
public CustomerController(ICustomerService customerService)
{
_customerService = customerService;
}
#endregion
#region
#endregion
#region Get All Customers
/// <summary>
/// GET: Get All Customers | CustomerViewModel | Gets all customers for a business in a VM for web UI.
/// TEST URL: https://localhost:7092/api/Customer/GetAllCustomers/52466 | https://localhost:7092/api/Customer/GetAllCustomers?BusinessID=52466
/// "CustomerControllerGetAllCustomersVMAsync": "Customer/GetAllCustomersVMAsync",
/// </summary>
/// <param name="BusinessID"></param>
/// <returns></returns>
//[Route("GetAllCustomers")]
//[HttpGet("{BusinessID}")]
[HttpGet]
public async Task<ActionResult<CustomerViewModel>> GetAllCustomersVMAsync(int BusinessID)
{
BusinessID = 52466; // temp hard code for testing, can remove later.
try
{
var customers = await _customerService.GetAllCustomersVMAsync(BusinessID);
if (customers == null)
{
return NotFound();
}
return Ok(customers);
}
catch (Exception ex)
{
return BadRequest("Customer API error: " + ex.Message + " | " + ex.InnerException);
}
}
/// <summary>
/// GET: Get All Customers | CustomerModel | Gets all customers for a business.
/// TEST URL: https://localhost:7092/api/Customer/GetAllCustomers?BusinessID=52466
/// "CustomerControllerGetAllCustomersAsync": "Customer/GetAllCustomersAsync",
/// </summary>
/// <param name="BusinessID"></param>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult<CustomerModel>> GetAllCustomersAsync(int BusinessID)
{
BusinessID = 52466; // temp hard code for testing, can remove later.
try
{
var customers = await _customerService.GetAllCustomersAsync(BusinessID);
if (customers == null)
{
return NotFound();
}
return Ok(customers);
}
catch (Exception ex)
{
return BadRequest("Customer API error: " + ex.Message + " | " + ex.InnerException);
}
}
#endregion
#region Get Customer
/// <summary>
/// GET: Get Customer | Customer | Gets a customer for a business.
/// TEST URL: https://localhost:7092/api/Customer/GetCustomer/3 | https://localhost:7092/api/Customer/GetCustomer?CustomerID=3
/// "CustomerControllerGetCustomer": "Customer/GetCustomer",
/// </summary>
/// <param name="CustomerID"></param>
/// <returns></returns>
//[Route("GetCustomer")]
//[HttpGet("{CustomerID}")]
[HttpGet]
public async Task<ActionResult<Customer>> GetCustomerAsync(int CustomerID)
{
var customer = await _customerService.GetCustomerAsync(CustomerID);
if (customer == null)
{
return NotFound();
}
return customer;
}
#endregion
#region Create Customer
/// <summary>
/// Add Customer | CustomerViewModel | Create a new customer for a business from client web application using a CustomerViewModel.
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> CreateCustomerVMAsync([FromBody] CustomerViewModel vm)
{
var result = await _customerService.CreateCustomerVMAsync(vm);
return Ok(result);
}
/// <summary>
/// Add Customer | CustomerModel | Create a new customer for a business.
/// TEST URL: https://localhost:7092/api/Customer/CreateCustomer
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> CreateCustomerAsync([FromBody] CustomerModel model)
{
var result = await _customerService.CreateCustomerAsync(model);
return Ok(result);
//return Ok("UNDER CONTRUCTION | CreateCustomerAsync([FromBody] Customer model)");
}
#endregion
#region Edit Customer
/// <summary>
/// EDIT: Edit a Customer | CustomerViewModel | edit a customer for a business in a VM for web UI.
/// TEST URL: |
/// "CustomerControllerEditCustomerVMAsync": "Customer/EditCustomerVMAsync",
/// </summary>
/// <param name="vm"></param>
/// <returns>SaveViewModel</returns>
[HttpPost]
public async Task<IActionResult> EditCustomerVMAsync([FromBody] CustomerViewModel vm)
{
// if model is valid, then update, else return bad request with model state errors.
var result = await _customerService.EditCustomerVMAsync(vm);
return Ok(result);
//return Ok("UNDER CONTRUCTION | EditCustomer(int id, [FromBody] Customer model)");
}
/// <summary>
/// EDIT: Customer | CustomerModel | edit a customer for a business.
/// TEST URL: https://localhost:7092/api/Customer/EditCustomer?id=5
/// "CustomerControllerEditCustomer": "Customer/EditCustomer"
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> EditCustomer([FromBody] CustomerModel model)
{
// if model is valid, then update, else return bad request with model state errors.
var result = await _customerService.EditCustomer(model);
return Ok(result);
}
// CustomerModel to just return a CustomerModel instead of a SaveViewModel with the RefID. We could do this for the VM as well.
#endregion
#region Delete Customer
/// <summary>
/// DELETE: Customer | SaveViewModel | delete a customer for a business and return a SaveViewModel with the RefID of the deleted customer.
/// "CustomerControllerDeleteCustomerVMAsync": "Customer/DeleteCustomerVMAsync"
/// </summary>
/// <param name="id"></param>
/// <returns>SaveViewModel</returns>
[HttpDelete("{CustomerID:int}")]
public async Task<IActionResult> DeleteCustomerVMAsync(int CustomerID)// LOOK AT ALL THESE IN CONTROLLER COMPAARED TO LICENSE API, WE JUST USE ACTION RESULT HERE AND RETURN THE MODEL THAT IS IN THE SERVICE.
{
var result = await _customerService.DeleteCustomerVMAsync(CustomerID);
return Ok(result);
}
#endregion
}
}