initial commit
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
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.PositiveAdjustmentManager.Queries;
|
||||
|
||||
public record GetPositiveAdjustmentListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? AdjustmentDate { get; init; }
|
||||
public AdjustmentStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentListProfile : Profile
|
||||
{
|
||||
public GetPositiveAdjustmentListProfile()
|
||||
{
|
||||
CreateMap<PositiveAdjustment, GetPositiveAdjustmentListDto>()
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentListResult
|
||||
{
|
||||
public List<GetPositiveAdjustmentListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentListRequest : IRequest<GetPositiveAdjustmentListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetPositiveAdjustmentListHandler : IRequestHandler<GetPositiveAdjustmentListRequest, GetPositiveAdjustmentListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetPositiveAdjustmentListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetPositiveAdjustmentListResult> Handle(GetPositiveAdjustmentListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.PositiveAdjustment
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetPositiveAdjustmentListDto>>(entities);
|
||||
|
||||
return new GetPositiveAdjustmentListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.PositiveAdjustmentManager.Queries;
|
||||
|
||||
|
||||
public class GetPositiveAdjustmentSingleProfile : Profile
|
||||
{
|
||||
public GetPositiveAdjustmentSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentSingleResult
|
||||
{
|
||||
public PositiveAdjustment? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentSingleRequest : IRequest<GetPositiveAdjustmentSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentSingleValidator : AbstractValidator<GetPositiveAdjustmentSingleRequest>
|
||||
{
|
||||
public GetPositiveAdjustmentSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentSingleHandler : IRequestHandler<GetPositiveAdjustmentSingleRequest, GetPositiveAdjustmentSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetPositiveAdjustmentSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetPositiveAdjustmentSingleResult> Handle(GetPositiveAdjustmentSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.PositiveAdjustment
|
||||
.AsNoTracking()
|
||||
.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(PositiveAdjustment))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetPositiveAdjustmentSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.PositiveAdjustmentManager.Queries;
|
||||
|
||||
public record GetPositiveAdjustmentStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentStatusListProfile : Profile
|
||||
{
|
||||
public GetPositiveAdjustmentStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentStatusListResult
|
||||
{
|
||||
public List<GetPositiveAdjustmentStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentStatusListRequest : IRequest<GetPositiveAdjustmentStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetPositiveAdjustmentStatusListHandler : IRequestHandler<GetPositiveAdjustmentStatusListRequest, GetPositiveAdjustmentStatusListResult>
|
||||
{
|
||||
|
||||
public GetPositiveAdjustmentStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetPositiveAdjustmentStatusListResult> Handle(GetPositiveAdjustmentStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(AdjustmentStatus))
|
||||
.Cast<AdjustmentStatus>()
|
||||
.Select(status => new GetPositiveAdjustmentStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetPositiveAdjustmentStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user