This commit is contained in:
@@ -160,17 +160,76 @@ namespace AyaNova.Api.Controllers
|
||||
public async Task<IActionResult> GetCustomerAlert([FromRoute] long id)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Customer))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
return Ok(ApiOkResponse.Response(await ct.Customer.AsNoTracking().Where(x => x.Id == id).Select(x => x.PopUpNotes).FirstOrDefaultAsync()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get billing address for this customer
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>Billing address (including headoffice if bill to head office = true)</returns>
|
||||
[HttpGet("bill-to-address/{id}")]
|
||||
public async Task<IActionResult> GetCustomerBillToAddress([FromRoute] long id)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Customer))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
var cust = await ct.Customer.AsNoTracking().Where(x => x.Id == id).FirstOrDefaultAsync();
|
||||
if (cust == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
HeadOffice head = null;
|
||||
if (cust.BillHeadOffice == true && cust.HeadOfficeId != null)
|
||||
head = await ct.HeadOffice.AsNoTracking().Where(x => x.Id == cust.HeadOfficeId).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
return Ok(ApiOkResponse.Response(new
|
||||
{
|
||||
customer = new PostalAddressRecord(cust.PostAddress, cust.PostCity, cust.PostRegion, cust.PostCountry, cust.PostCode),
|
||||
headoffice = (head == null ? new PostalAddressRecord(head.PostAddress, head.PostCity, head.PostRegion, head.PostCountry, head.PostCode) : new PostalAddressRecord("", "", "", "", ""))
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get service (physical) address for this customer
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>Service address</returns>
|
||||
[HttpGet("service-address/{id}")]
|
||||
public async Task<IActionResult> GetCustomerServiceAddress([FromRoute] long id)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Customer))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
var cust = await ct.Customer.AsNoTracking().Where(x => x.Id == id).FirstOrDefaultAsync();
|
||||
if (cust == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
return Ok(ApiOkResponse.Response(new
|
||||
{
|
||||
customer = new AddressRecord(cust.Address, cust.City, cust.Region, cust.Country, cust.Latitude, cust.Longitude)
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//------------
|
||||
|
||||
|
||||
}//eoc
|
||||
|
||||
// internal record PostalAddressRecord(string PostAddress, string PostCity, string PostRegion, string PostCountry, string PostCode);
|
||||
// internal record AddressRecord(string Address, string City, string Region, string Country, decimal? Latitude, decimal? Longitude);
|
||||
}//eons
|
||||
8
server/AyaNova/models/dto/AddressRecord.cs
Normal file
8
server/AyaNova/models/dto/AddressRecord.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
namespace AyaNova.Models
|
||||
{
|
||||
//physical
|
||||
public record AddressRecord(string Address, string City, string Region, string Country, decimal? Latitude, decimal? Longitude);
|
||||
//postal
|
||||
public record PostalAddressRecord(string PostAddress, string PostCity, string PostRegion, string PostCountry, string PostCode);
|
||||
}
|
||||
Reference in New Issue
Block a user