diff --git a/api/Controllers/ClientsController.cs b/api/Controllers/ClientsController.cs index 1a785d9..037b3aa 100644 --- a/api/Controllers/ClientsController.cs +++ b/api/Controllers/ClientsController.cs @@ -171,30 +171,34 @@ public IActionResult Delete(Guid id) if (foundclient == null) return NotFound(new { message = "Client not found." }); - return Ok(new ClientResponse + return Ok(new { - Id = foundclient.Id, - Name = foundclient.Name, - Contact = new ContactResponse - { - Id = foundclient.ContactId, - Name = foundclient.Contact?.Name, - Phone = foundclient.Contact?.Phone, - Email = foundclient.Contact?.Email - }, - Address = new AddressResponse - { - Id = foundclient.AddressId, - Street = foundclient.Address?.Street, - HouseNumber = foundclient.Address?.HouseNumber, - HouseNumberExtension = foundclient.Address?.HouseNumberExtension, - ZipCode = foundclient.Address?.ZipCode, - City = foundclient.Address?.City, - Province = foundclient.Address?.Province, - CountryCode = foundclient.Address?.CountryCode - }, - CreatedAt = foundclient.CreatedAt, - UpdatedAt = foundclient.UpdatedAt + Message = "Client deleted", + new_client = new ClientResponse{ + + Id = foundclient.Id, + Name = foundclient.Name, + Contact = new ContactResponse + { + Id = foundclient.ContactId, + Name = foundclient.Contact?.Name, + Phone = foundclient.Contact?.Phone, + Email = foundclient.Contact?.Email + }, + Address = new AddressResponse + { + Id = foundclient.AddressId, + Street = foundclient.Address?.Street, + HouseNumber = foundclient.Address?.HouseNumber, + HouseNumberExtension = foundclient.Address?.HouseNumberExtension, + ZipCode = foundclient.Address?.ZipCode, + City = foundclient.Address?.City, + Province = foundclient.Address?.Province, + CountryCode = foundclient.Address?.CountryCode + }, + CreatedAt = foundclient.CreatedAt, + UpdatedAt = foundclient.UpdatedAt + } }); } diff --git a/api/providers/ClientsProvider.cs b/api/providers/ClientsProvider.cs index a68258f..bea2306 100644 --- a/api/providers/ClientsProvider.cs +++ b/api/providers/ClientsProvider.cs @@ -46,9 +46,12 @@ public ClientsProvider(AppDbContext db, IValidator clientValidator, Cont public override Client? Delete(Guid id) { Client? foundClient = GetById(id); - if (foundClient == null) return null; + if (_db.Orders.Any(o => o.BillToClientId == id) ) + { + throw new ApiFlowException($"{id} The provided client_id is in use and cannot be modified."); + } _db.Clients.Remove(foundClient); SaveToDBOrFail();