initial commit
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferInManager.Queries;
|
||||
|
||||
public record GetTransferInListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? TransferReceiveDate { get; init; }
|
||||
public TransferStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? TransferOutId { get; init; }
|
||||
public string? TransferOutNumber { get; init; }
|
||||
public string? WarehouseFromName { get; init; }
|
||||
public string? WarehouseToName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInListProfile : Profile
|
||||
{
|
||||
public GetTransferInListProfile()
|
||||
{
|
||||
CreateMap<TransferIn, GetTransferInListDto>()
|
||||
.ForMember(
|
||||
dest => dest.TransferOutNumber,
|
||||
opt => opt.MapFrom(src => src.TransferOut != null ? src.TransferOut.Number : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.WarehouseFromName,
|
||||
opt => opt.MapFrom(src => src.TransferOut!.WarehouseFrom != null ? src.TransferOut.WarehouseFrom.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.WarehouseToName,
|
||||
opt => opt.MapFrom(src => src.TransferOut!.WarehouseTo != null ? src.TransferOut.WarehouseTo.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferInListResult
|
||||
{
|
||||
public List<GetTransferInListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInListRequest : IRequest<GetTransferInListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetTransferInListHandler : IRequestHandler<GetTransferInListRequest, GetTransferInListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetTransferInListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTransferInListResult> Handle(GetTransferInListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.TransferIn
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x.WarehouseFrom)
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x.WarehouseTo)
|
||||
.AsQueryable();
|
||||
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetTransferInListDto>>(entities);
|
||||
|
||||
return new GetTransferInListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferInManager.Queries;
|
||||
|
||||
|
||||
public class GetTransferInSingleProfile : Profile
|
||||
{
|
||||
public GetTransferInSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferInSingleResult
|
||||
{
|
||||
public TransferIn? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInSingleRequest : IRequest<GetTransferInSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInSingleValidator : AbstractValidator<GetTransferInSingleRequest>
|
||||
{
|
||||
public GetTransferInSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferInSingleHandler : IRequestHandler<GetTransferInSingleRequest, GetTransferInSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetTransferInSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTransferInSingleResult> Handle(GetTransferInSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.TransferIn
|
||||
.AsNoTracking()
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x.WarehouseFrom)
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x.WarehouseTo)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.AsQueryable();
|
||||
|
||||
var data = await queryData.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
|
||||
var queryTransactionList = _context
|
||||
.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.Product)
|
||||
.Include(x => x.Warehouse)
|
||||
.Include(x => x.WarehouseFrom)
|
||||
.Include(x => x.WarehouseTo)
|
||||
.Where(x => x.ModuleId == request.Id && x.ModuleName == nameof(TransferIn))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetTransferInSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferInManager.Queries;
|
||||
|
||||
public record GetTransferInStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInStatusListProfile : Profile
|
||||
{
|
||||
public GetTransferInStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferInStatusListResult
|
||||
{
|
||||
public List<GetTransferInStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInStatusListRequest : IRequest<GetTransferInStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetTransferInStatusListHandler : IRequestHandler<GetTransferInStatusListRequest, GetTransferInStatusListResult>
|
||||
{
|
||||
|
||||
public GetTransferInStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetTransferInStatusListResult> Handle(GetTransferInStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(TransferStatus))
|
||||
.Cast<TransferStatus>()
|
||||
.Select(status => new GetTransferInStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetTransferInStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user