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
119 changes: 66 additions & 53 deletions MBDEVproAPI.API/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@


namespace MBDEVproAPI.API.Controllers
namespace MBDEVproAPI.API.Controllers
{
public class CustomerController : BaseController
{
Expand All @@ -20,9 +18,9 @@ public CustomerController(ICustomerService customerService)
#endregion


#region Get All Customers | CustomerViewModel
#region Get All Customers
/// <summary>
/// GET: Gets all customers for a business in a VM for web UI.
/// 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>
Expand Down Expand Up @@ -50,12 +48,10 @@ public async Task<ActionResult<CustomerViewModel>> GetAllCustomersVMAsync(int Bu
return BadRequest("Customer API error: " + ex.Message + " | " + ex.InnerException);
}
}
#endregion


#region Get All Customers | CustomerModel
/// <summary>
/// GET: Gets all customers for a business.
/// 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>
Expand Down Expand Up @@ -83,9 +79,9 @@ public async Task<ActionResult<CustomerModel>> GetAllCustomersAsync(int Business



#region Get Customer | Customer
#region Get Customer
/// <summary>
/// GET: Gets a customer for a business.
/// 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>
Expand All @@ -109,9 +105,10 @@ public async Task<ActionResult<Customer>> GetCustomerAsync(int CustomerID)



#region Add Customer | CustomerViewModel

#region Add Customer
/// <summary>
/// Create a new customer for a business from client web application using a CustomerViewModel.
/// Add Customer | CustomerViewModel | Create a new customer for a business from client web application using a CustomerViewModel.
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
Expand All @@ -120,13 +117,10 @@ public async Task<IActionResult> CreateCustomerVMAsync([FromBody] CustomerViewMo
{
return Ok(_customerService.CreateCustomerVMAsync(vm));
}
#endregion



#region Add Customer | Customer
/// <summary>
/// Create a new customer for a business.
/// Add Customer | CustomerModel | Create a new customer for a business.
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
Expand All @@ -141,50 +135,69 @@ public async Task<IActionResult> CreateCustomerAsync([FromBody] CustomerModel mo



//// PUT - CREATE: api/Customer/5
//// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
//[HttpPut("{id}")]
#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>CustomerViewModel</returns>
[HttpPost]
public async Task<IActionResult> EditCustomerVMAsync([FromBody] CustomerViewModel vm)
{
// if model is valid, then update, else return bad request with model state errors.
return Ok(_customerService.EditCustomerVMAsync(vm));
//return Ok("UNDER CONTRUCTION | EditCustomer(int id, [FromBody] Customer model)");
}

//[HttpPost]
//public async Task<IActionResult> PutCustomer(int id, Customer customer)
//{
// if (id != customer.CustomerID)
// {
// return BadRequest();
// }

// _context.Entry(customer).State = EntityState.Modified;
/// <summary>
/// EDIT: Customer | CustomerModel | edit a customer for a business.
/// "CustomerControllerEditCustomer": "Customer/EditCustomer"
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> EditCustomer(int id, [FromBody] CustomerModel model)
{
// if model is valid, then update, else return bad request with model state errors.
return Ok(_customerService.EditCustomer(model));
}

// try
// {
// await _context.SaveChangesAsync();
// }
// catch (DbUpdateConcurrencyException)
// {
// if (!CustomerExists(id))
// {
// return NotFound();
// }
// else
// {
// throw;
// }
// }
// CustomerModel to just return a CustomerModel instead of a SaveViewModel with the RefID. We could do this for the VM as well.
#endregion

// return NoContent();
//}

//// POST: api/Customer
//// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
//[HttpPost]
//public async Task<ActionResult<Customer>> PostCustomer(Customer customer)
//{
// _context.Customers.Add(customer);
// await _context.SaveChangesAsync();

// return CreatedAtAction("GetCustomer", new { id = customer.CustomerID }, customer);
//}
#region Delete Customer
/// <summary>
/// DELET: Customer | CustomerModel | Delete a customer for a business.
/// "CustomerControllerDeleteCustomer": "Customer/DeleteCustomer"
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id:int}")]
public async Task<IActionResult> DeleteCustomer(int id)
{
return Ok(_customerService.DeleteCustomer(id));
}
#endregion


//#region DELETE: Citation Type
///// <summary>
///// DELETE: Citation Type
///// "CitationTypeControllerDeleteCitationType": "CitationType/DeleteCitationType"
///// </summary>
///// <param name="CitationTypeID"></param>
///// <returns></returns>
//[HttpDelete("{CitationTypeID:int}")]
//public IActionResult DeleteCitationType(int CitationTypeID)
//{
// return Ok(_citationTypeService.DeleteCitationType(CitationTypeID));
//}
//#endregion

//// DELETE: api/Customer/5
//[HttpDelete("{id}")]
Expand Down
2 changes: 1 addition & 1 deletion MBDEVproAPI.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
});
});


//ADD: API security and authentication (OAuth2, OpenID Connect, JWT)

var app = builder.Build();

Expand Down
1 change: 1 addition & 0 deletions MBDEVproAPI.BLL/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
global using MBDEVproAPI.DataModel;
global using MBDEVproAPI.DataModel.Entities;
global using MBDEVproAPI.Repository.Interfaces;
global using MBDEVproAPI.Repository.Repositories;
26 changes: 23 additions & 3 deletions MBDEVproAPI.BLL/Interfaces/ICustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,43 @@ namespace MBDEVproAPI.BLL.Interfaces
public interface ICustomerService : IBaseService<CustomerModel>
{


#region
#endregion



#region Get All Customers
Task<CustomerViewModel> GetAllCustomersVMAsync(int BusinessID);

Task<IEnumerable<CustomerModel>> GetAllCustomersAsync(int BusinessID);
#endregion


#region Get Customer
Task<Customer> GetCustomerAsync(int CustomerID);
#endregion


#region Add Customer
Task<SaveViewModel> CreateCustomerVMAsync(CustomerViewModel vm);

Task<SaveViewModel> CreateCustomerAsync(CustomerModel model);

SaveViewModel CreateCustomer(CustomerModel model);
#endregion


SaveViewModel CreateCustomer(CustomerModel model);
#region Edit Customer
Task<SaveViewModel> EditCustomerVMAsync(CustomerViewModel vm);

SaveViewModel EditCustomer(int id, CustomerModel model);
Task<SaveViewModel> EditCustomer(CustomerModel model);
#endregion

SaveViewModel DeleteCustomer(int id);

#region Delete Customer
Task<SaveViewModel> DeleteCustomerVM(int CustomerID);
SaveViewModel DeleteCustomer(int CustomerID);
#endregion
}
}
Loading