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.StockCountManager.Queries;
|
||||
|
||||
public record GetStockCountListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? CountDate { get; init; }
|
||||
public StockCountStatus? 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 GetStockCountListProfile : Profile
|
||||
{
|
||||
public GetStockCountListProfile()
|
||||
{
|
||||
CreateMap<StockCount, GetStockCountListDto>()
|
||||
.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 GetStockCountListResult
|
||||
{
|
||||
public List<GetStockCountListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetStockCountListRequest : IRequest<GetStockCountListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetStockCountListHandler : IRequestHandler<GetStockCountListRequest, GetStockCountListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetStockCountListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetStockCountListResult> Handle(GetStockCountListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.StockCount
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.Warehouse)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetStockCountListDto>>(entities);
|
||||
|
||||
return new GetStockCountListResult
|
||||
{
|
||||
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.StockCountManager.Queries;
|
||||
|
||||
|
||||
public class GetStockCountSingleProfile : Profile
|
||||
{
|
||||
public GetStockCountSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetStockCountSingleResult
|
||||
{
|
||||
public StockCount? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetStockCountSingleRequest : IRequest<GetStockCountSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetStockCountSingleValidator : AbstractValidator<GetStockCountSingleRequest>
|
||||
{
|
||||
public GetStockCountSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetStockCountSingleHandler : IRequestHandler<GetStockCountSingleRequest, GetStockCountSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetStockCountSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetStockCountSingleResult> Handle(GetStockCountSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.StockCount
|
||||
.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(StockCount))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetStockCountSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.StockCountManager.Queries;
|
||||
|
||||
public record GetStockCountStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetStockCountStatusListProfile : Profile
|
||||
{
|
||||
public GetStockCountStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetStockCountStatusListResult
|
||||
{
|
||||
public List<GetStockCountStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetStockCountStatusListRequest : IRequest<GetStockCountStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetStockCountStatusListHandler : IRequestHandler<GetStockCountStatusListRequest, GetStockCountStatusListResult>
|
||||
{
|
||||
|
||||
public GetStockCountStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetStockCountStatusListResult> Handle(GetStockCountStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(StockCountStatus))
|
||||
.Cast<StockCountStatus>()
|
||||
.Select(status => new GetStockCountStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetStockCountStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user