initial commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
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.TransferOutManager.Queries;
|
||||
|
||||
public record GetTransferOutListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? TransferReleaseDate { get; init; }
|
||||
public TransferStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? WarehouseFromId { get; init; }
|
||||
public string? WarehouseFromName { get; init; }
|
||||
public string? WarehouseToId { get; init; }
|
||||
public string? WarehouseToName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutListProfile : Profile
|
||||
{
|
||||
public GetTransferOutListProfile()
|
||||
{
|
||||
CreateMap<TransferOut, GetTransferOutListDto>()
|
||||
.ForMember(
|
||||
dest => dest.WarehouseFromName,
|
||||
opt => opt.MapFrom(src => src.WarehouseFrom != null ? src.WarehouseFrom.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.WarehouseToName,
|
||||
opt => opt.MapFrom(src => src.WarehouseTo != null ? src.WarehouseTo.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferOutListResult
|
||||
{
|
||||
public List<GetTransferOutListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutListRequest : IRequest<GetTransferOutListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetTransferOutListHandler : IRequestHandler<GetTransferOutListRequest, GetTransferOutListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetTransferOutListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTransferOutListResult> Handle(GetTransferOutListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.TransferOut
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.WarehouseFrom)
|
||||
.Include(x => x.WarehouseTo)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetTransferOutListDto>>(entities);
|
||||
|
||||
return new GetTransferOutListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferOutManager.Queries;
|
||||
|
||||
|
||||
public class GetTransferOutSingleProfile : Profile
|
||||
{
|
||||
public GetTransferOutSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferOutSingleResult
|
||||
{
|
||||
public TransferOut? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutSingleRequest : IRequest<GetTransferOutSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutSingleValidator : AbstractValidator<GetTransferOutSingleRequest>
|
||||
{
|
||||
public GetTransferOutSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferOutSingleHandler : IRequestHandler<GetTransferOutSingleRequest, GetTransferOutSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetTransferOutSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTransferOutSingleResult> Handle(GetTransferOutSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.TransferOut
|
||||
.AsNoTracking()
|
||||
.Include(x => x.WarehouseFrom)
|
||||
.Include(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(TransferOut))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetTransferOutSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferOutManager.Queries;
|
||||
|
||||
public record GetTransferOutStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutStatusListProfile : Profile
|
||||
{
|
||||
public GetTransferOutStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferOutStatusListResult
|
||||
{
|
||||
public List<GetTransferOutStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutStatusListRequest : IRequest<GetTransferOutStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetTransferOutStatusListHandler : IRequestHandler<GetTransferOutStatusListRequest, GetTransferOutStatusListResult>
|
||||
{
|
||||
|
||||
public GetTransferOutStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetTransferOutStatusListResult> Handle(GetTransferOutStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(TransferStatus))
|
||||
.Cast<TransferStatus>()
|
||||
.Select(status => new GetTransferOutStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetTransferOutStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user