11using AdminHubApi . Dtos . ApiResponse ;
22using AdminHubApi . Dtos . Invoice ;
3+ using AdminHubApi . Dtos . InvoiceItem ;
34using AdminHubApi . Dtos . UserManagement ;
45using AdminHubApi . Entities . Invoice ;
56using AdminHubApi . Interfaces ;
@@ -21,7 +22,6 @@ public async Task<ApiResponse<IEnumerable<InvoiceResponseDto>>> GetAllAsync()
2122 {
2223 try
2324 {
24-
2525 var invoices = await _invoiceRepository . GetAllAsync ( ) ;
2626
2727 return new ApiResponse < IEnumerable < InvoiceResponseDto > >
@@ -103,9 +103,9 @@ public async Task<ApiResponse<InvoiceResponseDto>> UpdateAsync(InvoiceResponseDt
103103 {
104104 var existingInvoice = await _invoiceRepository . GetByIdAsync ( invoiceResponse . Id ) ;
105105
106- if ( existingInvoice == null )
106+ if ( existingInvoice == null )
107107 throw new KeyNotFoundException ( $ "Invoice with id: { invoiceResponse . Id } was not found") ;
108-
108+
109109 existingInvoice . InvoiceNumber = invoiceResponse . InvoiceNumber ;
110110 existingInvoice . IssueDate = invoiceResponse . IssueDate ;
111111 existingInvoice . OrderId = invoiceResponse . OrderId ;
@@ -116,7 +116,7 @@ public async Task<ApiResponse<InvoiceResponseDto>> UpdateAsync(InvoiceResponseDt
116116 existingInvoice . ModifiedById = invoiceResponse . ModifiedById ;
117117
118118 await _invoiceRepository . UpdateAsync ( existingInvoice ) ;
119-
119+
120120 return new ApiResponse < InvoiceResponseDto >
121121 {
122122 Succeeded = true ,
@@ -130,11 +130,11 @@ public async Task<ApiResponse<bool>> DeleteAsync(Guid id)
130130 {
131131 var product = await _invoiceRepository . GetByIdAsync ( id ) ;
132132
133- if ( product == null )
133+ if ( product == null )
134134 throw new KeyNotFoundException ( $ "Invoice with id: { id } was not found") ;
135135
136136 await _invoiceRepository . DeleteAsync ( id ) ;
137-
137+
138138 return new ApiResponse < bool >
139139 {
140140 Succeeded = true ,
@@ -152,12 +152,28 @@ private static InvoiceResponseDto MapToResponseDto(Invoice invoice)
152152 InvoiceNumber = invoice . InvoiceNumber ,
153153 IssueDate = invoice . IssueDate ,
154154 DueDate = invoice . DueDate ,
155- OrderId = invoice . OrderId ,
155+ OrderId = invoice . OrderId , // Now both are nullable
156156 PaidAmount = invoice . PaidAmount ,
157+ TotalAmount = invoice . TotalAmount ,
157158 Notes = invoice . Notes ,
158159 Status = invoice . Status ,
160+
161+ // Customer fields
162+ CustomerName = invoice . CustomerName ,
163+ CustomerEmail = invoice . CustomerEmail ,
164+ CustomerPhone = invoice . CustomerPhone ,
165+ CustomerAddress = invoice . CustomerAddress ,
166+ BillingAddress = invoice . BillingAddress ,
167+
168+ // Pricing fields
169+ Subtotal = invoice . Subtotal ,
170+ TaxRate = invoice . TaxRate ,
171+ TaxAmount = invoice . TaxAmount ,
172+ DiscountAmount = invoice . DiscountAmount ,
173+ PaymentTerms = invoice . PaymentTerms ,
174+
159175 Created = invoice . Created ,
160- Modified = invoice . Modified ,
176+ CreatedById = invoice . CreatedById ,
161177 CreatedBy = invoice . CreatedBy != null
162178 ? new UserDto
163179 {
@@ -172,6 +188,8 @@ private static InvoiceResponseDto MapToResponseDto(Invoice invoice)
172188 LockoutEnd = invoice . CreatedBy . LockoutEnd
173189 }
174190 : null ,
191+ Modified = invoice . Modified ,
192+ ModifiedById = invoice . ModifiedById ,
175193 ModifiedBy = invoice . ModifiedBy != null
176194 ? new UserDto
177195 {
@@ -185,7 +203,20 @@ private static InvoiceResponseDto MapToResponseDto(Invoice invoice)
185203 LockoutEnabled = invoice . ModifiedBy . LockoutEnabled ,
186204 LockoutEnd = invoice . ModifiedBy . LockoutEnd
187205 }
188- : null
206+ : null ,
207+
208+ // Map invoice items
209+ Items = invoice . Items ? . Select ( item => new InvoiceItemResponseDto
210+ {
211+ Id = item . Id ,
212+ Description = item . Description ,
213+ Quantity = item . Quantity ,
214+ UnitPrice = item . UnitPrice ,
215+ TotalPrice = item . TotalPrice ,
216+ ProductId = item . ProductId ,
217+ Created = item . Created ,
218+ Modified = item . Modified
219+ } ) . ToList ( ) ?? new List < InvoiceItemResponseDto > ( )
189220 } ;
190221 }
191222}
0 commit comments