initial commit
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
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.ScrappingManager.Queries;
|
||||
|
||||
public record GetScrappingListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? ScrappingDate { get; init; }
|
||||
public ScrappingStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? WarehouseName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetScrappingListProfile : Profile
|
||||
{
|
||||
public GetScrappingListProfile()
|
||||
{
|
||||
CreateMap<Scrapping, GetScrappingListDto>()
|
||||
.ForMember(
|
||||
dest => dest.WarehouseName,
|
||||
opt => opt.MapFrom(src => src.Warehouse != null ? src.Warehouse.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetScrappingListResult
|
||||
{
|
||||
public List<GetScrappingListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetScrappingListRequest : IRequest<GetScrappingListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetScrappingListHandler : IRequestHandler<GetScrappingListRequest, GetScrappingListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetScrappingListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetScrappingListResult> Handle(GetScrappingListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Scrapping
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.Warehouse)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetScrappingListDto>>(entities);
|
||||
|
||||
return new GetScrappingListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.ScrappingManager.Queries;
|
||||
|
||||
|
||||
public class GetScrappingSingleProfile : Profile
|
||||
{
|
||||
public GetScrappingSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetScrappingSingleResult
|
||||
{
|
||||
public Scrapping? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetScrappingSingleRequest : IRequest<GetScrappingSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetScrappingSingleValidator : AbstractValidator<GetScrappingSingleRequest>
|
||||
{
|
||||
public GetScrappingSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetScrappingSingleHandler : IRequestHandler<GetScrappingSingleRequest, GetScrappingSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetScrappingSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetScrappingSingleResult> Handle(GetScrappingSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.Scrapping
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Warehouse)
|
||||
.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(Scrapping))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetScrappingSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.ScrappingManager.Queries;
|
||||
|
||||
public record GetScrappingStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetScrappingStatusListProfile : Profile
|
||||
{
|
||||
public GetScrappingStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetScrappingStatusListResult
|
||||
{
|
||||
public List<GetScrappingStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetScrappingStatusListRequest : IRequest<GetScrappingStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetScrappingStatusListHandler : IRequestHandler<GetScrappingStatusListRequest, GetScrappingStatusListResult>
|
||||
{
|
||||
|
||||
public GetScrappingStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetScrappingStatusListResult> Handle(GetScrappingStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(ScrappingStatus))
|
||||
.Cast<ScrappingStatus>()
|
||||
.Select(status => new GetScrappingStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetScrappingStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user