diff --git a/server/AyaNova/Controllers/CustomerController.cs b/server/AyaNova/Controllers/CustomerController.cs index 8236c32f..8b0a7e72 100644 --- a/server/AyaNova/Controllers/CustomerController.cs +++ b/server/AyaNova/Controllers/CustomerController.cs @@ -160,17 +160,76 @@ namespace AyaNova.Api.Controllers public async Task 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())); } + /// + /// Get billing address for this customer + /// + /// + /// Billing address (including headoffice if bill to head office = true) + [HttpGet("bill-to-address/{id}")] + public async Task 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("", "", "", "", "")) + })); + } + + /// + /// Get service (physical) address for this customer + /// + /// + /// Service address + [HttpGet("service-address/{id}")] + public async Task 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 \ No newline at end of file diff --git a/server/AyaNova/models/dto/AddressRecord.cs b/server/AyaNova/models/dto/AddressRecord.cs new file mode 100644 index 00000000..447c5956 --- /dev/null +++ b/server/AyaNova/models/dto/AddressRecord.cs @@ -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); +}