This commit is contained in:
2021-04-30 21:28:13 +00:00
parent 0fcdf2cf21
commit 0a6199adea
3 changed files with 42 additions and 28 deletions

View File

@@ -169,11 +169,12 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Get billing address for this customer
/// Get addresses of interest for Customer id provided
/// (postal, physical, headoffice postal if billheadoffice=true)
/// </summary>
/// <param name="id"></param>
/// <returns>Billing address (including headoffice if bill to head office = true)</returns>
[HttpGet("bill-to-address/{id}")]
/// <returns>Multiple addresses</returns>
[HttpGet("address/{id}")]
public async Task<IActionResult> GetCustomerBillToAddress([FromRoute] long id)
{
if (!serverState.IsOpen)
@@ -193,34 +194,35 @@ namespace AyaNova.Api.Controllers
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("", "", "", "", ""))
customerpost = new PostalAddressRecord(cust.PostAddress, cust.PostCity, cust.PostRegion, cust.PostCountry, cust.PostCode),
customerphys = new AddressRecord(cust.Address, cust.City, cust.Region, cust.Country, cust.Latitude, cust.Longitude),
headofficepost = (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));
// /// <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)
}));
}
// return Ok(ApiOkResponse.Response(new
// {
// customer = new AddressRecord(cust.Address, cust.City, cust.Region, cust.Country, cust.Latitude, cust.Longitude)
// }));
// }