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.NegativeAdjustmentManager.Queries;
|
||||
|
||||
public record GetNegativeAdjustmentListDto
|
||||
{
|
||||
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 GetNegativeAdjustmentListProfile : Profile
|
||||
{
|
||||
public GetNegativeAdjustmentListProfile()
|
||||
{
|
||||
CreateMap<NegativeAdjustment, GetNegativeAdjustmentListDto>()
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentListResult
|
||||
{
|
||||
public List<GetNegativeAdjustmentListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentListRequest : IRequest<GetNegativeAdjustmentListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetNegativeAdjustmentListHandler : IRequestHandler<GetNegativeAdjustmentListRequest, GetNegativeAdjustmentListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetNegativeAdjustmentListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetNegativeAdjustmentListResult> Handle(GetNegativeAdjustmentListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.NegativeAdjustment
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetNegativeAdjustmentListDto>>(entities);
|
||||
|
||||
return new GetNegativeAdjustmentListResult
|
||||
{
|
||||
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.NegativeAdjustmentManager.Queries;
|
||||
|
||||
|
||||
public class GetNegativeAdjustmentSingleProfile : Profile
|
||||
{
|
||||
public GetNegativeAdjustmentSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentSingleResult
|
||||
{
|
||||
public NegativeAdjustment? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentSingleRequest : IRequest<GetNegativeAdjustmentSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentSingleValidator : AbstractValidator<GetNegativeAdjustmentSingleRequest>
|
||||
{
|
||||
public GetNegativeAdjustmentSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentSingleHandler : IRequestHandler<GetNegativeAdjustmentSingleRequest, GetNegativeAdjustmentSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetNegativeAdjustmentSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetNegativeAdjustmentSingleResult> Handle(GetNegativeAdjustmentSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.NegativeAdjustment
|
||||
.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(NegativeAdjustment))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetNegativeAdjustmentSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.NegativeAdjustmentManager.Queries;
|
||||
|
||||
public record GetNegativeAdjustmentStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentStatusListProfile : Profile
|
||||
{
|
||||
public GetNegativeAdjustmentStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentStatusListResult
|
||||
{
|
||||
public List<GetNegativeAdjustmentStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentStatusListRequest : IRequest<GetNegativeAdjustmentStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetNegativeAdjustmentStatusListHandler : IRequestHandler<GetNegativeAdjustmentStatusListRequest, GetNegativeAdjustmentStatusListResult>
|
||||
{
|
||||
|
||||
public GetNegativeAdjustmentStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetNegativeAdjustmentStatusListResult> Handle(GetNegativeAdjustmentStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(AdjustmentStatus))
|
||||
.Cast<AdjustmentStatus>()
|
||||
.Select(status => new GetNegativeAdjustmentStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetNegativeAdjustmentStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user