All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (pull_request) Successful in 18m57s
- Se agregan DeliveryNoteDto y DeliveryNoteItemDto - Se implementa proyección a DTO en PhSDeliveryNoteRepository - Se extiende IPhSDeliveryNoteRepository con métodos DTO - Se ajusta DeliveryNoteService para trabajar con DTO - Se actualiza DeliveryNoteController para devolver DTO - Se elimina exposición directa de EDeliveryNote en la API Closes #23
88 lines
3.2 KiB
C#
88 lines
3.2 KiB
C#
using Domain.Dtos.Sales;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Models.Interfaces;
|
|
using Models.Models;
|
|
|
|
namespace Models.Repositories
|
|
{
|
|
public class PhSDeliveryNoteRepository(PhronCareOperationsHubContext context) : IPhSDeliveryNoteRepository
|
|
{
|
|
private readonly PhronCareOperationsHubContext _context = context;
|
|
|
|
public async Task<DeliveryNoteDto?> GetDtoByIdAsync(int id)
|
|
{
|
|
var entity = await _context.PhSDeliveryNotes
|
|
.Include(x => x.PhSDeliveryNoteDetails)
|
|
.AsNoTracking()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
return entity == null ? null : MapDeliveryNoteDto(entity);
|
|
}
|
|
|
|
public async Task<DeliveryNoteDto?> GetDtoByDeliveryNoteNumberAsync(string deliveryNoteNumber)
|
|
{
|
|
var entity = await _context.PhSDeliveryNotes
|
|
.Include(x => x.PhSDeliveryNoteDetails)
|
|
.AsNoTracking()
|
|
.FirstOrDefaultAsync(x => x.Deliverynotenumber == deliveryNoteNumber);
|
|
|
|
return entity == null ? null : MapDeliveryNoteDto(entity);
|
|
}
|
|
|
|
public async Task<IEnumerable<DeliveryNoteDto>> GetDtosByQuoteIdAsync(int quoteId)
|
|
{
|
|
var entities = await _context.PhSDeliveryNotes
|
|
.Include(x => x.PhSDeliveryNoteDetails)
|
|
.AsNoTracking()
|
|
.Where(x => x.QuoteId == quoteId)
|
|
.OrderByDescending(x => x.Issuedate)
|
|
.ThenByDescending(x => x.Id)
|
|
.ToListAsync();
|
|
|
|
return entities.Select(MapDeliveryNoteDto);
|
|
}
|
|
|
|
private static DeliveryNoteDto MapDeliveryNoteDto(PhSDeliveryNote source)
|
|
{
|
|
return new DeliveryNoteDto
|
|
{
|
|
Id = source.Id,
|
|
DeliveryNoteNumber = source.Deliverynotenumber,
|
|
QuoteId = source.QuoteId,
|
|
SalesInvoiceId = source.SalesinvoiceId,
|
|
IssueDate = source.Issuedate,
|
|
CustomerId = source.CustomerId,
|
|
Status = source.Status,
|
|
Observations = source.Observations,
|
|
ExtraInfoJson = source.ExtrainfoJson,
|
|
PrintCount = source.Printcount,
|
|
CreatedAt = source.Createdat,
|
|
ModifiedAt = source.Modifiedat,
|
|
Items = source.PhSDeliveryNoteDetails
|
|
.OrderBy(d => d.LineNumber)
|
|
.ThenBy(d => d.Id)
|
|
.Select(MapDeliveryNoteItemDto)
|
|
.ToList()
|
|
};
|
|
}
|
|
|
|
private static DeliveryNoteItemDto MapDeliveryNoteItemDto(PhSDeliveryNoteDetail source)
|
|
{
|
|
return new DeliveryNoteItemDto
|
|
{
|
|
Id = source.Id,
|
|
DeliverynoteId = source.DeliverynoteId,
|
|
LineNumber = source.LineNumber,
|
|
OriginType = source.OriginType,
|
|
OriginId = source.OriginId,
|
|
QuoteDetailId = source.QuoteDetailId,
|
|
Description = source.Description,
|
|
Quantity = source.Quantity,
|
|
Notes = source.Notes,
|
|
Createdat = source.Createdat,
|
|
Modifiedat = source.Modifiedat
|
|
};
|
|
}
|
|
}
|
|
}
|