Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 69 additions & 6 deletions MBDEVproAPI.API/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ public CustomerController(ICustomerService customerService)
#endregion


#region CustomerViewModel
#region Get All Customers | CustomerViewModel
/// <summary>
/// GET: Gets all customers for a business.
/// GET: 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
/// "CustomerControllerGetAllCustomers": "Customer/GetAllCustomers",
/// "CustomerControllerGetAllCustomersVMAsync": "Customer/GetAllCustomersVMAsync",
/// </summary>
/// <param name="BusinessID"></param>
/// <returns></returns>
//[Route("GetAllCustomers")]
//[HttpGet("{BusinessID}")]
[HttpGet]
public async Task<ActionResult<CustomerViewModel>> GetAllCustomersAsync(int BusinessID)
public async Task<ActionResult<CustomerViewModel>> GetAllCustomersVMAsync(int BusinessID)
{
BusinessID = 52466; // temp hard code for testing, can remove later.
try
{
var customers = await _customerService.GetAllCustomersAsync(BusinessID);
var customers = await _customerService.GetAllCustomersVMAsync(BusinessID);

if (customers == null)
{
Expand All @@ -53,8 +53,37 @@ public async Task<ActionResult<CustomerViewModel>> GetAllCustomersAsync(int Busi
#endregion


#region Get All Customers | CustomerModel
/// <summary>
/// GET: 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
#region Get Customer | Customer
/// <summary>
/// GET: Gets a customer for a business.
/// TEST URL: https://localhost:7092/api/Customer/GetCustomer/3 | https://localhost:7092/api/Customer/GetCustomer?CustomerID=3
Expand All @@ -79,6 +108,39 @@ public async Task<ActionResult<Customer>> GetCustomerAsync(int CustomerID)
#endregion



#region Add Customer | CustomerViewModel
/// <summary>
/// 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)
{
return Ok(_customerService.CreateCustomerVMAsync(vm));
}
#endregion



#region Add Customer | Customer
/// <summary>
/// Create a new customer for a business.
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> CreateCustomerAsync([FromBody] CustomerModel model)
{
return Ok(_customerService.CreateCustomerAsync(model));
//return Ok("UNDER CONTRUCTION | CreateCustomerAsync([FromBody] Customer model)");
}
#endregion




//// PUT - CREATE: api/Customer/5
//// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
//[HttpPut("{id}")]
Expand Down Expand Up @@ -123,6 +185,7 @@ public async Task<ActionResult<Customer>> GetCustomerAsync(int CustomerID)
// return CreatedAtAction("GetCustomer", new { id = customer.CustomerID }, customer);
//}


//// DELETE: api/Customer/5
//[HttpDelete("{id}")]
//public async Task<IActionResult> DeleteCustomer(int id)
Expand Down
8 changes: 5 additions & 3 deletions MBDEVproAPI.BLL/Interfaces/ICustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ namespace MBDEVproAPI.BLL.Interfaces
public interface ICustomerService : IBaseService<CustomerModel>
{

//CustomerViewModel GetAllCustomers(int BusinessID);
Task<CustomerViewModel> GetAllCustomersVMAsync(int BusinessID);

Task<CustomerViewModel> GetAllCustomersAsync(int BusinessID);
Task<IEnumerable<CustomerModel>> GetAllCustomersAsync(int BusinessID);


Task<Customer> GetCustomerAsync(int CustomerID);

Task<SaveViewModel> CreateCustomerVMAsync(CustomerViewModel vm);

Task<SaveViewModel> CreateCustomerAsync(CustomerModel model);

//CustomerModel GetCustomer(int id);

SaveViewModel CreateCustomer(CustomerModel model);

Expand Down
Loading