initial commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
*.css linguist-vendored
|
||||
*.html linguist-vendored
|
||||
*.htm linguist-vendored
|
||||
*.js linguist-vendored
|
||||
*.php linguist-vendored
|
||||
|
||||
*.cshtml linguist-language=C#
|
||||
*.css linguist-detectable=false
|
||||
@@ -0,0 +1,2 @@
|
||||
.vs/
|
||||
obj/
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Domain\Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
|
||||
<PackageReference Include="MediatR" Version="12.4.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,34 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Application.Common.Behaviors;
|
||||
|
||||
public class LoggingBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull
|
||||
{
|
||||
private readonly ILogger<TRequest> _logger;
|
||||
|
||||
public LoggingBehaviour(ILogger<TRequest> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
|
||||
{
|
||||
var requestName = typeof(TRequest).Name;
|
||||
|
||||
try
|
||||
{
|
||||
_logger.LogInformation($"Try executing {requestName} at {DateTime.UtcNow.ToString()}");
|
||||
|
||||
return await next();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
_logger.LogError(ex, $"Error executing {requestName} at {DateTime.UtcNow.ToString()}");
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Common.Behaviors;
|
||||
|
||||
public class ValidationBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
|
||||
where TRequest : notnull
|
||||
{
|
||||
private readonly IEnumerable<IValidator<TRequest>> _validators;
|
||||
|
||||
public ValidationBehaviour(IEnumerable<IValidator<TRequest>> validators)
|
||||
{
|
||||
_validators = validators;
|
||||
}
|
||||
|
||||
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_validators.Any())
|
||||
{
|
||||
var context = new ValidationContext<TRequest>(request);
|
||||
|
||||
var validationResults = await Task.WhenAll(
|
||||
_validators.Select(v =>
|
||||
v.ValidateAsync(context, cancellationToken)));
|
||||
|
||||
var failures = validationResults
|
||||
.Where(r => r.Errors.Any())
|
||||
.SelectMany(r => r.Errors)
|
||||
.ToList();
|
||||
|
||||
if (failures.Any())
|
||||
throw new ValidationException(failures);
|
||||
}
|
||||
return await next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Application.Common.CQS.Commands;
|
||||
|
||||
public interface ICommandContext
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Application.Common.Repositories;
|
||||
|
||||
namespace Application.Common.CQS.Queries;
|
||||
|
||||
public interface IQueryContext : IEntityDbSet
|
||||
{
|
||||
IQueryable<T> Set<T>() where T : class;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Application.Common.Extensions;
|
||||
|
||||
public static class EnumExtensions
|
||||
{
|
||||
public static string ToFriendlyName<TEnum>(this TEnum value) where TEnum : Enum
|
||||
{
|
||||
var memberInfo = typeof(TEnum).GetMember(value.ToString());
|
||||
var descriptionAttribute = memberInfo[0]
|
||||
.GetCustomAttribute<DescriptionAttribute>();
|
||||
|
||||
return descriptionAttribute?.Description ?? value.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Domain.Common;
|
||||
|
||||
namespace Application.Common.Extensions;
|
||||
|
||||
|
||||
public static class QueryableExtensions
|
||||
{
|
||||
public static IQueryable<T> ApplyIsDeletedFilter<T>(this IQueryable<T> query, bool isDeleted = false) where T : class
|
||||
{
|
||||
if (typeof(IHasIsDeleted).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
query = query.Where(x => (x as IHasIsDeleted)!.IsDeleted == isDeleted);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using Domain.Common;
|
||||
|
||||
namespace Application.Common.Repositories;
|
||||
|
||||
|
||||
public interface ICommandRepository<T> where T : BaseEntity
|
||||
{
|
||||
Task CreateAsync(T entity, CancellationToken cancellationToken = default);
|
||||
|
||||
void Create(T entity);
|
||||
|
||||
void Update(T entity);
|
||||
|
||||
void Delete(T entity);
|
||||
|
||||
void Purge(T entity);
|
||||
|
||||
Task<T?> GetAsync(string id, CancellationToken cancellationToken = default);
|
||||
|
||||
T? Get(string id);
|
||||
|
||||
IQueryable<T> GetQuery();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Common.Repositories;
|
||||
|
||||
|
||||
public interface IEntityDbSet
|
||||
{
|
||||
public DbSet<Token> Token { get; set; }
|
||||
public DbSet<Todo> Todo { get; set; }
|
||||
public DbSet<TodoItem> TodoItem { get; set; }
|
||||
public DbSet<Company> Company { get; set; }
|
||||
public DbSet<FileImage> FileImage { get; set; }
|
||||
public DbSet<FileDocument> FileDocument { get; set; }
|
||||
|
||||
public DbSet<NumberSequence> NumberSequence { get; set; }
|
||||
public DbSet<CustomerGroup> CustomerGroup { get; set; }
|
||||
public DbSet<CustomerCategory> CustomerCategory { get; set; }
|
||||
public DbSet<VendorGroup> VendorGroup { get; set; }
|
||||
public DbSet<VendorCategory> VendorCategory { get; set; }
|
||||
public DbSet<Warehouse> Warehouse { get; set; }
|
||||
public DbSet<Customer> Customer { get; set; }
|
||||
public DbSet<Vendor> Vendor { get; set; }
|
||||
public DbSet<UnitMeasure> UnitMeasure { get; set; }
|
||||
public DbSet<ProductGroup> ProductGroup { get; set; }
|
||||
public DbSet<Product> Product { get; set; }
|
||||
public DbSet<CustomerContact> CustomerContact { get; set; }
|
||||
public DbSet<VendorContact> VendorContact { get; set; }
|
||||
public DbSet<Tax> Tax { get; set; }
|
||||
public DbSet<SalesOrder> SalesOrder { get; set; }
|
||||
public DbSet<SalesOrderItem> SalesOrderItem { get; set; }
|
||||
public DbSet<PurchaseOrder> PurchaseOrder { get; set; }
|
||||
public DbSet<PurchaseOrderItem> PurchaseOrderItem { get; set; }
|
||||
public DbSet<InventoryTransaction> InventoryTransaction { get; set; }
|
||||
public DbSet<DeliveryOrder> DeliveryOrder { get; set; }
|
||||
public DbSet<GoodsReceive> GoodsReceive { get; set; }
|
||||
public DbSet<SalesReturn> SalesReturn { get; set; }
|
||||
public DbSet<PurchaseReturn> PurchaseReturn { get; set; }
|
||||
public DbSet<TransferIn> TransferIn { get; set; }
|
||||
public DbSet<TransferOut> TransferOut { get; set; }
|
||||
public DbSet<StockCount> StockCount { get; set; }
|
||||
public DbSet<NegativeAdjustment> NegativeAdjustment { get; set; }
|
||||
public DbSet<PositiveAdjustment> PositiveAdjustment { get; set; }
|
||||
public DbSet<Scrapping> Scrapping { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Common.Repositories;
|
||||
|
||||
public interface IUnitOfWork
|
||||
{
|
||||
Task SaveAsync(CancellationToken cancellationToken = default);
|
||||
void Save();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Common.Services.EmailManager;
|
||||
|
||||
public interface IEmailService
|
||||
{
|
||||
Task SendEmailAsync(string email, string subject, string htmlMessage);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Application.Common.Services.FileDocumentManager;
|
||||
public interface IFileDocumentService
|
||||
{
|
||||
Task<string> UploadAsync(
|
||||
string? originalFileName,
|
||||
string? docExtension,
|
||||
byte[]? fileData,
|
||||
long? size,
|
||||
string? description = "",
|
||||
string? createdById = "",
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
Task<byte[]> GetFileAsync(string fileName, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Application.Common.Services.FileImageManager;
|
||||
public interface IFileImageService
|
||||
{
|
||||
Task<string> UploadAsync(
|
||||
string? originalFileName,
|
||||
string? docExtension,
|
||||
byte[]? fileData,
|
||||
long? size,
|
||||
string? description = "",
|
||||
string? createdById = "",
|
||||
CancellationToken cancellationToken = default);
|
||||
Task<byte[]> GetFileAsync(string fileName, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public record CreateUserResultDto
|
||||
{
|
||||
public string? UserId { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public bool? EmailConfirmed { get; init; }
|
||||
public bool? IsBlocked { get; init; }
|
||||
public bool? IsDeleted { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public record DeleteUserResultDto
|
||||
{
|
||||
public string? UserId { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public bool? EmailConfirmed { get; init; }
|
||||
public bool? IsBlocked { get; init; }
|
||||
public bool? IsDeleted { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public record GetMyProfileListResultDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
public record GetRoleListResultDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
public record GetUserListResultDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public bool? EmailConfirmed { get; init; }
|
||||
public bool? IsBlocked { get; init; }
|
||||
public bool? IsDeleted { get; init; }
|
||||
public DateTime? CreatedAt { get; init; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public interface ISecurityService
|
||||
{
|
||||
public Task<LoginResultDto> LoginAsync(
|
||||
string email,
|
||||
string password,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<LogoutResultDto> LogoutAsync(
|
||||
string userId,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<RegisterResultDto> RegisterAsync(
|
||||
string email,
|
||||
string password,
|
||||
string confirmPassword,
|
||||
string firstName,
|
||||
string lastName,
|
||||
string companyName = "",
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<string> ConfirmEmailAsync(
|
||||
string email,
|
||||
string code,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<string> ForgotPasswordAsync(
|
||||
string email,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<string> ForgotPasswordConfirmationAsync(
|
||||
string email,
|
||||
string tempPassword,
|
||||
string code,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<RefreshTokenResultDto> RefreshTokenAsync(
|
||||
string refreshToken,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
public Task<List<GetMyProfileListResultDto>> GetMyProfileListAsync(
|
||||
string userId,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
public Task UpdateMyProfileAsync(
|
||||
string userId,
|
||||
string firstName,
|
||||
string lastName,
|
||||
string companyName,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
public Task ChangePasswordAsync(
|
||||
string userId,
|
||||
string oldPassword,
|
||||
string newPassword,
|
||||
string confirmNewPassword,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
public Task<List<GetRoleListResultDto>> GetRoleListAsync(
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
public Task<List<GetUserListResultDto>> GetUserListAsync(
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
public Task<CreateUserResultDto> CreateUserAsync(
|
||||
string email,
|
||||
string password,
|
||||
string confirmPassword,
|
||||
string firstName,
|
||||
string lastName,
|
||||
bool emailConfirmed = true,
|
||||
bool isBlocked = false,
|
||||
bool isDeleted = false,
|
||||
string createdById = "",
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<UpdateUserResultDto> UpdateUserAsync(
|
||||
string userId,
|
||||
string firstName,
|
||||
string lastName,
|
||||
bool emailConfirmed = true,
|
||||
bool isBlocked = false,
|
||||
bool isDeleted = false,
|
||||
string updatedById = "",
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<DeleteUserResultDto> DeleteUserAsync(
|
||||
string userId,
|
||||
string deletedById = "",
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task UpdatePasswordUserAsync(
|
||||
string userId,
|
||||
string newPassword,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
public Task<List<string>> GetUserRolesAsync(
|
||||
string userId,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task<List<string>> UpdateUserRoleAsync(
|
||||
string userId,
|
||||
string roleName,
|
||||
bool accessGranted,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public Task ChangeAvatarAsync(
|
||||
string userId,
|
||||
string avatar,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public record LoginResultDto
|
||||
{
|
||||
public string? AccessToken { get; init; }
|
||||
public string? RefreshToken { get; init; }
|
||||
public string? UserId { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public string? Avatar { get; init; }
|
||||
public List<MenuNavigationTreeNodeDto>? MenuNavigation { get; init; }
|
||||
public List<string>? Roles { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public record LogoutResultDto
|
||||
{
|
||||
public string? AccessToken { get; init; }
|
||||
public string? RefreshToken { get; init; }
|
||||
public string? UserId { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public List<string>? UserClaims { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public class MenuNavigationTreeNodeDto
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Pid { get; set; }
|
||||
public string? NavURL { get; set; }
|
||||
public bool HasChild { get; set; }
|
||||
public bool Expanded { get; set; }
|
||||
public bool IsSelected { get; set; }
|
||||
|
||||
public MenuNavigationTreeNodeDto(string param_id, string param_name, string? param_pid = null, string? param_navURL = null, bool param_hasChild = false, bool param_expanded = false, bool param_selected = false)
|
||||
{
|
||||
Id = param_id;
|
||||
Name = param_name;
|
||||
Pid = param_pid;
|
||||
NavURL = param_navURL;
|
||||
HasChild = param_hasChild;
|
||||
Expanded = param_expanded;
|
||||
IsSelected = param_selected;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public record RefreshTokenResultDto
|
||||
{
|
||||
public string? AccessToken { get; init; }
|
||||
public string? RefreshToken { get; init; }
|
||||
public string? UserId { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public string? Avatar { get; init; }
|
||||
public List<MenuNavigationTreeNodeDto>? MenuNavigation { get; init; }
|
||||
public List<string>? Roles { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public record RegisterResultDto
|
||||
{
|
||||
public string? UserId { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Application.Common.Services.SecurityManager;
|
||||
|
||||
public record UpdateUserResultDto
|
||||
{
|
||||
public string? UserId { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? FirstName { get; init; }
|
||||
public string? LastName { get; init; }
|
||||
public bool? EmailConfirmed { get; init; }
|
||||
public bool? IsBlocked { get; init; }
|
||||
public bool? IsDeleted { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Application.Common.Behaviors;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Application;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
|
||||
{
|
||||
//>>> AutoMapper
|
||||
services.AddAutoMapper(Assembly.GetExecutingAssembly());
|
||||
|
||||
//>>> FluentValidation
|
||||
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
||||
|
||||
//>>> MediatR
|
||||
services.AddMediatR(x =>
|
||||
{
|
||||
x.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
||||
x.AddBehavior(typeof(IPipelineBehavior<,>), typeof(LoggingBehaviour<,>));
|
||||
x.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
|
||||
});
|
||||
|
||||
//>>> Register services in Application.Features
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var featureTypes = assembly.GetTypes()
|
||||
.Where(type => type.IsClass && !type.IsAbstract)
|
||||
.Where(type => type.Namespace != null && type.Namespace.StartsWith("Application.Features"));
|
||||
|
||||
foreach (var type in featureTypes)
|
||||
{
|
||||
var interfaces = type.GetInterfaces();
|
||||
foreach (var serviceInterface in interfaces)
|
||||
{
|
||||
services.AddScoped(serviceInterface, type);
|
||||
}
|
||||
if (!interfaces.Any())
|
||||
{
|
||||
services.AddScoped(type);
|
||||
}
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CompanyManager.Commands;
|
||||
|
||||
public class UpdateCompanyResult
|
||||
{
|
||||
public Company? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateCompanyRequest : IRequest<UpdateCompanyResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? Currency { get; init; }
|
||||
public string? Street { get; init; }
|
||||
public string? City { get; init; }
|
||||
public string? State { get; init; }
|
||||
public string? ZipCode { get; init; }
|
||||
public string? Country { get; init; }
|
||||
public string? PhoneNumber { get; init; }
|
||||
public string? FaxNumber { get; init; }
|
||||
public string? EmailAddress { get; init; }
|
||||
public string? Website { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateCompanyValidator : AbstractValidator<UpdateCompanyRequest>
|
||||
{
|
||||
public UpdateCompanyValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
RuleFor(x => x.Currency).NotEmpty();
|
||||
RuleFor(x => x.Street).NotEmpty();
|
||||
RuleFor(x => x.City).NotEmpty();
|
||||
RuleFor(x => x.State).NotEmpty();
|
||||
RuleFor(x => x.ZipCode).NotEmpty();
|
||||
RuleFor(x => x.PhoneNumber).NotEmpty();
|
||||
RuleFor(x => x.EmailAddress).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateCompanyHandler : IRequestHandler<UpdateCompanyRequest, UpdateCompanyResult>
|
||||
{
|
||||
private readonly ICommandRepository<Company> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateCompanyHandler(
|
||||
ICommandRepository<Company> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<UpdateCompanyResult> Handle(UpdateCompanyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.Description = request.Description;
|
||||
entity.Currency = request.Currency;
|
||||
entity.Street = request.Street;
|
||||
entity.City = request.City;
|
||||
entity.State = request.State;
|
||||
entity.ZipCode = request.ZipCode;
|
||||
entity.Country = request.Country;
|
||||
entity.PhoneNumber = request.PhoneNumber;
|
||||
entity.FaxNumber = request.FaxNumber;
|
||||
entity.EmailAddress = request.EmailAddress;
|
||||
entity.Website = request.Website;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new UpdateCompanyResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CompanyManager.Queries;
|
||||
|
||||
public record GetCompanyListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? Currency { get; init; }
|
||||
public string? Street { get; init; }
|
||||
public string? City { get; init; }
|
||||
public string? State { get; init; }
|
||||
public string? ZipCode { get; init; }
|
||||
public string? Country { get; init; }
|
||||
public string? PhoneNumber { get; init; }
|
||||
public string? FaxNumber { get; init; }
|
||||
public string? EmailAddress { get; init; }
|
||||
public string? Website { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetCompanyListProfile : Profile
|
||||
{
|
||||
public GetCompanyListProfile()
|
||||
{
|
||||
CreateMap<Company, GetCompanyListDto>();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCompanyListResult
|
||||
{
|
||||
public List<GetCompanyListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCompanyListRequest : IRequest<GetCompanyListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetCompanyListHandler : IRequestHandler<GetCompanyListRequest, GetCompanyListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCompanyListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCompanyListResult> Handle(GetCompanyListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Company
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetCompanyListDto>>(entities);
|
||||
|
||||
return new GetCompanyListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CompanyManager.Queries;
|
||||
|
||||
public record GetCompanySingleDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? Currency { get; init; }
|
||||
public string? Street { get; init; }
|
||||
public string? City { get; init; }
|
||||
public string? State { get; init; }
|
||||
public string? ZipCode { get; init; }
|
||||
public string? Country { get; init; }
|
||||
public string? PhoneNumber { get; init; }
|
||||
public string? FaxNumber { get; init; }
|
||||
public string? EmailAddress { get; init; }
|
||||
public string? Website { get; init; }
|
||||
}
|
||||
|
||||
public class GetCompanySingleProfile : Profile
|
||||
{
|
||||
public GetCompanySingleProfile()
|
||||
{
|
||||
CreateMap<Company, GetCompanySingleDto>();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCompanySingleResult
|
||||
{
|
||||
public GetCompanySingleDto? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCompanySingleRequest : IRequest<GetCompanySingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetCompanySingleValidator : AbstractValidator<GetCompanySingleRequest>
|
||||
{
|
||||
public GetCompanySingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCompanySingleHandler : IRequestHandler<GetCompanySingleRequest, GetCompanySingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetCompanySingleHandler(
|
||||
IQueryContext context,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<GetCompanySingleResult> Handle(GetCompanySingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Company
|
||||
.AsNoTracking()
|
||||
.AsQueryable();
|
||||
|
||||
query = query
|
||||
.Where(x => x.Id == request.Id);
|
||||
|
||||
var entity = await query.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
var dto = _mapper.Map<GetCompanySingleDto>(entity);
|
||||
|
||||
return new GetCompanySingleResult
|
||||
{
|
||||
Data = dto
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerCategoryManager.Commands;
|
||||
|
||||
public class CreateCustomerCategoryResult
|
||||
{
|
||||
public CustomerCategory? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateCustomerCategoryRequest : IRequest<CreateCustomerCategoryResult>
|
||||
{
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateCustomerCategoryValidator : AbstractValidator<CreateCustomerCategoryRequest>
|
||||
{
|
||||
public CreateCustomerCategoryValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateCustomerCategoryHandler : IRequestHandler<CreateCustomerCategoryRequest, CreateCustomerCategoryResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerCategory> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CreateCustomerCategoryHandler(
|
||||
ICommandRepository<CustomerCategory> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<CreateCustomerCategoryResult> Handle(CreateCustomerCategoryRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new CustomerCategory();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.Description = request.Description;
|
||||
|
||||
await _repository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new CreateCustomerCategoryResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerCategoryManager.Commands;
|
||||
|
||||
public class DeleteCustomerCategoryResult
|
||||
{
|
||||
public CustomerCategory? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteCustomerCategoryRequest : IRequest<DeleteCustomerCategoryResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteCustomerCategoryValidator : AbstractValidator<DeleteCustomerCategoryRequest>
|
||||
{
|
||||
public DeleteCustomerCategoryValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteCustomerCategoryHandler : IRequestHandler<DeleteCustomerCategoryRequest, DeleteCustomerCategoryResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerCategory> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public DeleteCustomerCategoryHandler(
|
||||
ICommandRepository<CustomerCategory> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<DeleteCustomerCategoryResult> Handle(DeleteCustomerCategoryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.DeletedById;
|
||||
|
||||
_repository.Delete(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new DeleteCustomerCategoryResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerCategoryManager.Commands;
|
||||
|
||||
public class UpdateCustomerCategoryResult
|
||||
{
|
||||
public CustomerCategory? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerCategoryRequest : IRequest<UpdateCustomerCategoryResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerCategoryValidator : AbstractValidator<UpdateCustomerCategoryRequest>
|
||||
{
|
||||
public UpdateCustomerCategoryValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateCustomerCategoryHandler : IRequestHandler<UpdateCustomerCategoryRequest, UpdateCustomerCategoryResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerCategory> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateCustomerCategoryHandler(
|
||||
ICommandRepository<CustomerCategory> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<UpdateCustomerCategoryResult> Handle(UpdateCustomerCategoryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.Description = request.Description;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new UpdateCustomerCategoryResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CustomerCategoryManager.Queries;
|
||||
|
||||
public record GetCustomerCategoryListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerCategoryListProfile : Profile
|
||||
{
|
||||
public GetCustomerCategoryListProfile()
|
||||
{
|
||||
CreateMap<CustomerCategory, GetCustomerCategoryListDto>();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCustomerCategoryListResult
|
||||
{
|
||||
public List<GetCustomerCategoryListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerCategoryListRequest : IRequest<GetCustomerCategoryListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetCustomerCategoryListHandler : IRequestHandler<GetCustomerCategoryListRequest, GetCustomerCategoryListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCustomerCategoryListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCustomerCategoryListResult> Handle(GetCustomerCategoryListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.CustomerCategory
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetCustomerCategoryListDto>>(entities);
|
||||
|
||||
return new GetCustomerCategoryListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerContactManager.Commands;
|
||||
|
||||
public class CreateCustomerContactResult
|
||||
{
|
||||
public CustomerContact? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateCustomerContactRequest : IRequest<CreateCustomerContactResult>
|
||||
{
|
||||
public string? Name { get; init; }
|
||||
public string? JobTitle { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CustomerId { get; set; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateCustomerContactValidator : AbstractValidator<CreateCustomerContactRequest>
|
||||
{
|
||||
public CreateCustomerContactValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
RuleFor(x => x.JobTitle).NotEmpty();
|
||||
RuleFor(x => x.PhoneNumber).NotEmpty();
|
||||
RuleFor(x => x.EmailAddress).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateCustomerContactHandler : IRequestHandler<CreateCustomerContactRequest, CreateCustomerContactResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerContact> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
|
||||
public CreateCustomerContactHandler(
|
||||
ICommandRepository<CustomerContact> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
}
|
||||
|
||||
public async Task<CreateCustomerContactResult> Handle(CreateCustomerContactRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new CustomerContact();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(CustomerContact), "", "CC");
|
||||
entity.JobTitle = request.JobTitle;
|
||||
entity.PhoneNumber = request.PhoneNumber;
|
||||
entity.EmailAddress = request.EmailAddress;
|
||||
entity.Description = request.Description;
|
||||
entity.CustomerId = request.CustomerId;
|
||||
|
||||
await _repository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new CreateCustomerContactResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerContactManager.Commands;
|
||||
|
||||
public class DeleteCustomerContactResult
|
||||
{
|
||||
public CustomerContact? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteCustomerContactRequest : IRequest<DeleteCustomerContactResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteCustomerContactValidator : AbstractValidator<DeleteCustomerContactRequest>
|
||||
{
|
||||
public DeleteCustomerContactValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteCustomerContactHandler : IRequestHandler<DeleteCustomerContactRequest, DeleteCustomerContactResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerContact> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public DeleteCustomerContactHandler(
|
||||
ICommandRepository<CustomerContact> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<DeleteCustomerContactResult> Handle(DeleteCustomerContactRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.DeletedById;
|
||||
|
||||
_repository.Delete(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new DeleteCustomerContactResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerContactManager.Commands;
|
||||
|
||||
public class UpdateCustomerContactResult
|
||||
{
|
||||
public CustomerContact? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerContactRequest : IRequest<UpdateCustomerContactResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
public string? JobTitle { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CustomerId { get; set; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerContactValidator : AbstractValidator<UpdateCustomerContactRequest>
|
||||
{
|
||||
public UpdateCustomerContactValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
RuleFor(x => x.JobTitle).NotEmpty();
|
||||
RuleFor(x => x.PhoneNumber).NotEmpty();
|
||||
RuleFor(x => x.EmailAddress).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateCustomerContactHandler : IRequestHandler<UpdateCustomerContactRequest, UpdateCustomerContactResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerContact> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateCustomerContactHandler(
|
||||
ICommandRepository<CustomerContact> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<UpdateCustomerContactResult> Handle(UpdateCustomerContactRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.JobTitle = request.JobTitle;
|
||||
entity.PhoneNumber = request.PhoneNumber;
|
||||
entity.EmailAddress = request.EmailAddress;
|
||||
entity.Description = request.Description;
|
||||
entity.CustomerId = request.CustomerId;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new UpdateCustomerContactResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CustomerContactManager.Queries;
|
||||
|
||||
public record GetCustomerContactByCustomerIdListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; set; }
|
||||
public string? Number { get; set; }
|
||||
public string? JobTitle { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CustomerId { get; set; }
|
||||
public string? CustomerName { get; set; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerContactByCustomerIdListProfile : Profile
|
||||
{
|
||||
public GetCustomerContactByCustomerIdListProfile()
|
||||
{
|
||||
CreateMap<CustomerContact, GetCustomerContactByCustomerIdListDto>()
|
||||
.ForMember(
|
||||
dest => dest.CustomerName,
|
||||
opt => opt.MapFrom(src => src.Customer != null ? src.Customer.Name : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCustomerContactByCustomerIdListResult
|
||||
{
|
||||
public List<GetCustomerContactByCustomerIdListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerContactByCustomerIdListRequest : IRequest<GetCustomerContactByCustomerIdListResult>
|
||||
{
|
||||
public string? CustomerId { get; init; }
|
||||
}
|
||||
|
||||
|
||||
public class GetCustomerContactByCustomerIdListHandler : IRequestHandler<GetCustomerContactByCustomerIdListRequest, GetCustomerContactByCustomerIdListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCustomerContactByCustomerIdListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCustomerContactByCustomerIdListResult> Handle(GetCustomerContactByCustomerIdListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.CustomerContact
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.Customer)
|
||||
.Where(x => x.CustomerId == request.CustomerId)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetCustomerContactByCustomerIdListDto>>(entities);
|
||||
|
||||
return new GetCustomerContactByCustomerIdListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CustomerContactManager.Queries;
|
||||
|
||||
public record GetCustomerContactListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; set; }
|
||||
public string? Number { get; set; }
|
||||
public string? JobTitle { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CustomerId { get; set; }
|
||||
public string? CustomerName { get; set; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerContactListProfile : Profile
|
||||
{
|
||||
public GetCustomerContactListProfile()
|
||||
{
|
||||
CreateMap<CustomerContact, GetCustomerContactListDto>()
|
||||
.ForMember(
|
||||
dest => dest.CustomerName,
|
||||
opt => opt.MapFrom(src => src.Customer != null ? src.Customer.Name : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCustomerContactListResult
|
||||
{
|
||||
public List<GetCustomerContactListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerContactListRequest : IRequest<GetCustomerContactListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetCustomerContactListHandler : IRequestHandler<GetCustomerContactListRequest, GetCustomerContactListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCustomerContactListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCustomerContactListResult> Handle(GetCustomerContactListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.CustomerContact
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.Customer)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetCustomerContactListDto>>(entities);
|
||||
|
||||
return new GetCustomerContactListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerGroupManager.Commands;
|
||||
|
||||
public class CreateCustomerGroupResult
|
||||
{
|
||||
public CustomerGroup? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateCustomerGroupRequest : IRequest<CreateCustomerGroupResult>
|
||||
{
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateCustomerGroupValidator : AbstractValidator<CreateCustomerGroupRequest>
|
||||
{
|
||||
public CreateCustomerGroupValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateCustomerGroupHandler : IRequestHandler<CreateCustomerGroupRequest, CreateCustomerGroupResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerGroup> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CreateCustomerGroupHandler(
|
||||
ICommandRepository<CustomerGroup> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<CreateCustomerGroupResult> Handle(CreateCustomerGroupRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new CustomerGroup();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.Description = request.Description;
|
||||
|
||||
await _repository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new CreateCustomerGroupResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerGroupManager.Commands;
|
||||
|
||||
public class DeleteCustomerGroupResult
|
||||
{
|
||||
public CustomerGroup? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteCustomerGroupRequest : IRequest<DeleteCustomerGroupResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteCustomerGroupValidator : AbstractValidator<DeleteCustomerGroupRequest>
|
||||
{
|
||||
public DeleteCustomerGroupValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteCustomerGroupHandler : IRequestHandler<DeleteCustomerGroupRequest, DeleteCustomerGroupResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerGroup> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public DeleteCustomerGroupHandler(
|
||||
ICommandRepository<CustomerGroup> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<DeleteCustomerGroupResult> Handle(DeleteCustomerGroupRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.DeletedById;
|
||||
|
||||
_repository.Delete(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new DeleteCustomerGroupResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerGroupManager.Commands;
|
||||
|
||||
public class UpdateCustomerGroupResult
|
||||
{
|
||||
public CustomerGroup? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerGroupRequest : IRequest<UpdateCustomerGroupResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerGroupValidator : AbstractValidator<UpdateCustomerGroupRequest>
|
||||
{
|
||||
public UpdateCustomerGroupValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateCustomerGroupHandler : IRequestHandler<UpdateCustomerGroupRequest, UpdateCustomerGroupResult>
|
||||
{
|
||||
private readonly ICommandRepository<CustomerGroup> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateCustomerGroupHandler(
|
||||
ICommandRepository<CustomerGroup> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<UpdateCustomerGroupResult> Handle(UpdateCustomerGroupRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.Description = request.Description;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new UpdateCustomerGroupResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CustomerGroupManager.Queries;
|
||||
|
||||
public record GetCustomerGroupListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerGroupListProfile : Profile
|
||||
{
|
||||
public GetCustomerGroupListProfile()
|
||||
{
|
||||
CreateMap<CustomerGroup, GetCustomerGroupListDto>();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCustomerGroupListResult
|
||||
{
|
||||
public List<GetCustomerGroupListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerGroupListRequest : IRequest<GetCustomerGroupListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetCustomerGroupListHandler : IRequestHandler<GetCustomerGroupListRequest, GetCustomerGroupListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCustomerGroupListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCustomerGroupListResult> Handle(GetCustomerGroupListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.CustomerGroup
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetCustomerGroupListDto>>(entities);
|
||||
|
||||
return new GetCustomerGroupListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerManager.Commands;
|
||||
|
||||
public class CreateCustomerResult
|
||||
{
|
||||
public Customer? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateCustomerRequest : IRequest<CreateCustomerResult>
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Street { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? State { get; set; }
|
||||
public string? ZipCode { get; set; }
|
||||
public string? Country { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? TwitterX { get; set; }
|
||||
public string? TikTok { get; set; }
|
||||
public string? CustomerGroupId { get; set; }
|
||||
public string? CustomerCategoryId { get; set; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateCustomerValidator : AbstractValidator<CreateCustomerRequest>
|
||||
{
|
||||
public CreateCustomerValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
RuleFor(x => x.Street).NotEmpty();
|
||||
RuleFor(x => x.City).NotEmpty();
|
||||
RuleFor(x => x.State).NotEmpty();
|
||||
RuleFor(x => x.ZipCode).NotEmpty();
|
||||
RuleFor(x => x.PhoneNumber).NotEmpty();
|
||||
RuleFor(x => x.EmailAddress).NotEmpty();
|
||||
RuleFor(x => x.CustomerGroupId).NotEmpty();
|
||||
RuleFor(x => x.CustomerCategoryId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateCustomerHandler : IRequestHandler<CreateCustomerRequest, CreateCustomerResult>
|
||||
{
|
||||
private readonly ICommandRepository<Customer> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
|
||||
public CreateCustomerHandler(
|
||||
ICommandRepository<Customer> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
}
|
||||
|
||||
public async Task<CreateCustomerResult> Handle(CreateCustomerRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new Customer();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(Customer), "", "CST");
|
||||
entity.Description = request.Description;
|
||||
entity.Street = request.Street;
|
||||
entity.City = request.City;
|
||||
entity.State = request.State;
|
||||
entity.ZipCode = request.ZipCode;
|
||||
entity.Country = request.Country;
|
||||
entity.PhoneNumber = request.PhoneNumber;
|
||||
entity.FaxNumber = request.FaxNumber;
|
||||
entity.EmailAddress = request.EmailAddress;
|
||||
entity.Website = request.Website;
|
||||
entity.WhatsApp = request.WhatsApp;
|
||||
entity.LinkedIn = request.LinkedIn;
|
||||
entity.Facebook = request.Facebook;
|
||||
entity.Instagram = request.Instagram;
|
||||
entity.TwitterX = request.TwitterX;
|
||||
entity.TikTok = request.TikTok;
|
||||
entity.CustomerGroupId = request.CustomerGroupId;
|
||||
entity.CustomerCategoryId = request.CustomerCategoryId;
|
||||
|
||||
await _repository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new CreateCustomerResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerManager.Commands;
|
||||
|
||||
public class DeleteCustomerResult
|
||||
{
|
||||
public Customer? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteCustomerRequest : IRequest<DeleteCustomerResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteCustomerValidator : AbstractValidator<DeleteCustomerRequest>
|
||||
{
|
||||
public DeleteCustomerValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteCustomerHandler : IRequestHandler<DeleteCustomerRequest, DeleteCustomerResult>
|
||||
{
|
||||
private readonly ICommandRepository<Customer> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public DeleteCustomerHandler(
|
||||
ICommandRepository<Customer> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<DeleteCustomerResult> Handle(DeleteCustomerRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.DeletedById;
|
||||
|
||||
_repository.Delete(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new DeleteCustomerResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CustomerManager.Commands;
|
||||
|
||||
public class UpdateCustomerResult
|
||||
{
|
||||
public Customer? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerRequest : IRequest<UpdateCustomerResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Street { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? State { get; set; }
|
||||
public string? ZipCode { get; set; }
|
||||
public string? Country { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? TwitterX { get; set; }
|
||||
public string? TikTok { get; set; }
|
||||
public string? CustomerGroupId { get; set; }
|
||||
public string? CustomerCategoryId { get; set; }
|
||||
public string? CreatedById { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerValidator : AbstractValidator<UpdateCustomerRequest>
|
||||
{
|
||||
public UpdateCustomerValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Name).NotEmpty();
|
||||
RuleFor(x => x.Street).NotEmpty();
|
||||
RuleFor(x => x.City).NotEmpty();
|
||||
RuleFor(x => x.State).NotEmpty();
|
||||
RuleFor(x => x.ZipCode).NotEmpty();
|
||||
RuleFor(x => x.PhoneNumber).NotEmpty();
|
||||
RuleFor(x => x.EmailAddress).NotEmpty();
|
||||
RuleFor(x => x.CustomerGroupId).NotEmpty();
|
||||
RuleFor(x => x.CustomerCategoryId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateCustomerHandler : IRequestHandler<UpdateCustomerRequest, UpdateCustomerResult>
|
||||
{
|
||||
private readonly ICommandRepository<Customer> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateCustomerHandler(
|
||||
ICommandRepository<Customer> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<UpdateCustomerResult> Handle(UpdateCustomerRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.Description = request.Description;
|
||||
entity.Street = request.Street;
|
||||
entity.City = request.City;
|
||||
entity.State = request.State;
|
||||
entity.ZipCode = request.ZipCode;
|
||||
entity.Country = request.Country;
|
||||
entity.PhoneNumber = request.PhoneNumber;
|
||||
entity.FaxNumber = request.FaxNumber;
|
||||
entity.EmailAddress = request.EmailAddress;
|
||||
entity.Website = request.Website;
|
||||
entity.WhatsApp = request.WhatsApp;
|
||||
entity.LinkedIn = request.LinkedIn;
|
||||
entity.Facebook = request.Facebook;
|
||||
entity.Instagram = request.Instagram;
|
||||
entity.TwitterX = request.TwitterX;
|
||||
entity.TikTok = request.TikTok;
|
||||
entity.CustomerGroupId = request.CustomerGroupId;
|
||||
entity.CustomerCategoryId = request.CustomerCategoryId;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new UpdateCustomerResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.CustomerManager.Queries;
|
||||
|
||||
public record GetCustomerListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; set; }
|
||||
public string? Number { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Street { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? State { get; set; }
|
||||
public string? ZipCode { get; set; }
|
||||
public string? Country { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? TwitterX { get; set; }
|
||||
public string? TikTok { get; set; }
|
||||
public string? CustomerGroupId { get; set; }
|
||||
public string? CustomerGroupName { get; set; }
|
||||
public string? CustomerCategoryId { get; set; }
|
||||
public string? CustomerCategoryName { get; set; }
|
||||
public string? CreatedById { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerListProfile : Profile
|
||||
{
|
||||
public GetCustomerListProfile()
|
||||
{
|
||||
CreateMap<Customer, GetCustomerListDto>()
|
||||
.ForMember(
|
||||
dest => dest.CustomerGroupName,
|
||||
opt => opt.MapFrom(src => src.CustomerGroup != null ? src.CustomerGroup.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.CustomerCategoryName,
|
||||
opt => opt.MapFrom(src => src.CustomerCategory != null ? src.CustomerCategory.Name : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetCustomerListResult
|
||||
{
|
||||
public List<GetCustomerListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCustomerListRequest : IRequest<GetCustomerListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetCustomerListHandler : IRequestHandler<GetCustomerListRequest, GetCustomerListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCustomerListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCustomerListResult> Handle(GetCustomerListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Customer
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.CustomerGroup)
|
||||
.Include(x => x.CustomerCategory)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetCustomerListDto>>(entities);
|
||||
|
||||
return new GetCustomerListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Application.Features.DashboardManager.Queries;
|
||||
|
||||
public class BarDataItem
|
||||
{
|
||||
public string X { get; set; } = string.Empty;
|
||||
public int Y { get; set; }
|
||||
public string TooltipMappingName { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Application.Features.DashboardManager.Queries;
|
||||
|
||||
public class BarSeries
|
||||
{
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public string XName { get; set; } = string.Empty;
|
||||
public int Width { get; set; }
|
||||
public string YName { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double ColumnSpacing { get; set; }
|
||||
public string TooltipMappingName { get; set; } = string.Empty;
|
||||
public List<BarDataItem> DataSource { get; set; } = new List<BarDataItem>();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Application.Features.DashboardManager.Queries;
|
||||
|
||||
public class CardsItem
|
||||
{
|
||||
public double? SalesTotal { get; init; }
|
||||
public double? SalesReturnTotal { get; init; }
|
||||
public double? PurchaseTotal { get; init; }
|
||||
public double? PurchaseReturnTotal { get; init; }
|
||||
public double? DeliveryOrderTotal { get; init; }
|
||||
public double? GoodsReceiveTotal { get; init; }
|
||||
public double? TransferOutTotal { get; init; }
|
||||
public double? TransferInTotal { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.DashboardManager.Queries;
|
||||
|
||||
|
||||
public class GetCardsDashboardDto
|
||||
{
|
||||
public CardsItem? CardsDashboard { get; init; }
|
||||
}
|
||||
|
||||
public class GetCardsDashboardResult
|
||||
{
|
||||
public GetCardsDashboardDto? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetCardsDashboardRequest : IRequest<GetCardsDashboardResult>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetCardsDashboardHandler : IRequestHandler<GetCardsDashboardRequest, GetCardsDashboardResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetCardsDashboardHandler(IQueryContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetCardsDashboardResult> Handle(GetCardsDashboardRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var salesTotal = await _context.SalesOrderItem
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.SumAsync(x => (double?)x.Quantity, cancellationToken);
|
||||
|
||||
var salesReturnTotal = await _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.ModuleName == nameof(SalesReturn) && x.Status == InventoryTransactionStatus.Confirmed && x.Warehouse!.SystemWarehouse == false)
|
||||
.SumAsync(x => (double?)x.Movement, cancellationToken);
|
||||
|
||||
var purchaseTotal = await _context.PurchaseOrderItem
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.SumAsync(x => (double?)x.Quantity, cancellationToken);
|
||||
|
||||
var purchaseReturnTotal = await _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.ModuleName == nameof(PurchaseReturn) && x.Status == InventoryTransactionStatus.Confirmed && x.Warehouse!.SystemWarehouse == false)
|
||||
.SumAsync(x => (double?)x.Movement, cancellationToken);
|
||||
|
||||
var deliveryOrderTotal = await _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.ModuleName == nameof(DeliveryOrder) && x.Status == InventoryTransactionStatus.Confirmed && x.Warehouse!.SystemWarehouse == false)
|
||||
.SumAsync(x => (double?)x.Movement, cancellationToken);
|
||||
|
||||
var goodsReceiveTotal = await _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.ModuleName == nameof(GoodsReceive) && x.Status == InventoryTransactionStatus.Confirmed && x.Warehouse!.SystemWarehouse == false)
|
||||
.SumAsync(x => (double?)x.Movement, cancellationToken);
|
||||
|
||||
var transferOutTotal = await _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.ModuleName == nameof(TransferOut) && x.Status == InventoryTransactionStatus.Confirmed && x.Warehouse!.SystemWarehouse == false)
|
||||
.SumAsync(x => (double?)x.Movement, cancellationToken);
|
||||
|
||||
var transferInTotal = await _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.ModuleName == nameof(TransferIn) && x.Status == InventoryTransactionStatus.Confirmed && x.Warehouse!.SystemWarehouse == false)
|
||||
.SumAsync(x => (double?)x.Movement, cancellationToken);
|
||||
|
||||
var cardsDashboardData = new CardsItem
|
||||
{
|
||||
SalesTotal = salesTotal,
|
||||
SalesReturnTotal = salesReturnTotal,
|
||||
PurchaseTotal = purchaseTotal,
|
||||
PurchaseReturnTotal = purchaseReturnTotal,
|
||||
DeliveryOrderTotal = deliveryOrderTotal,
|
||||
GoodsReceiveTotal = goodsReceiveTotal,
|
||||
TransferOutTotal = transferOutTotal,
|
||||
TransferInTotal = transferInTotal
|
||||
};
|
||||
|
||||
|
||||
|
||||
var result = new GetCardsDashboardResult
|
||||
{
|
||||
Data = new GetCardsDashboardDto
|
||||
{
|
||||
CardsDashboard = cardsDashboardData
|
||||
}
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.DashboardManager.Queries;
|
||||
|
||||
|
||||
public class GetInventoryDashboardDto
|
||||
{
|
||||
public List<InventoryTransaction>? InventoryTransactionDashboard { get; init; }
|
||||
public List<BarSeries>? InventoryStockDashboard { get; init; }
|
||||
}
|
||||
|
||||
public class GetInventoryDashboardResult
|
||||
{
|
||||
public GetInventoryDashboardDto? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetInventoryDashboardRequest : IRequest<GetInventoryDashboardResult>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetInventoryDashboardHandler : IRequestHandler<GetInventoryDashboardRequest, GetInventoryDashboardResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetInventoryDashboardHandler(IQueryContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetInventoryDashboardResult> Handle(GetInventoryDashboardRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var inventoryTransactionData = await _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.Warehouse)
|
||||
.Include(x => x.Product)
|
||||
.Include(x => x.WarehouseFrom)
|
||||
.Include(x => x.WarehouseTo)
|
||||
.Where(x =>
|
||||
x.Product!.Physical == true &&
|
||||
x.Warehouse!.SystemWarehouse == false &&
|
||||
x.Status == InventoryTransactionStatus.Confirmed
|
||||
)
|
||||
.OrderByDescending(x => x.CreatedAtUtc)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
|
||||
var inventoryStockData = _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.Warehouse)
|
||||
.Include(x => x.Product)
|
||||
.Where(x =>
|
||||
x.Status == InventoryTransactionStatus.Confirmed &&
|
||||
x.Warehouse!.SystemWarehouse == false &&
|
||||
x.Product!.Physical == true
|
||||
)
|
||||
.GroupBy(x => new { x.WarehouseId, x.ProductId })
|
||||
.Select(group => new
|
||||
{
|
||||
WarehouseId = group.Key.WarehouseId,
|
||||
ProductId = group.Key.ProductId,
|
||||
Warehouse = group.Max(x => x.Warehouse!.Name),
|
||||
Product = group.Max(x => x.Product!.Name),
|
||||
Stock = group.Sum(x => x.Stock),
|
||||
Id = group.Max(x => x.Id),
|
||||
CreatedAtUtc = group.Max(x => x.CreatedAtUtc)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var warehouseData = _context.Warehouse
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.SystemWarehouse == false)
|
||||
.Select(x => x.Name)
|
||||
.ToList();
|
||||
|
||||
|
||||
var result = new GetInventoryDashboardResult
|
||||
{
|
||||
Data = new GetInventoryDashboardDto
|
||||
{
|
||||
InventoryTransactionDashboard = inventoryTransactionData,
|
||||
InventoryStockDashboard =
|
||||
warehouseData
|
||||
.Select(wh => new BarSeries
|
||||
{
|
||||
Type = "Column",
|
||||
XName = "x",
|
||||
Width = 2,
|
||||
YName = "y",
|
||||
Name = wh ?? "",
|
||||
ColumnSpacing = 0.1,
|
||||
TooltipMappingName = "tooltipMappingName",
|
||||
DataSource = inventoryStockData
|
||||
.Where(x => x.Warehouse == wh)
|
||||
.Select(x => new BarDataItem
|
||||
{
|
||||
X = x.Product ?? string.Empty,
|
||||
TooltipMappingName = x.Product ?? string.Empty,
|
||||
Y = (int)(x.Stock ?? 0.0)
|
||||
}).ToList()
|
||||
})
|
||||
.ToList()
|
||||
}
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.DashboardManager.Queries;
|
||||
|
||||
|
||||
public class GetPurchaseDashboardDto
|
||||
{
|
||||
public List<PurchaseOrderItem>? PurchaseOrderDashboard { get; init; }
|
||||
public List<BarSeries>? PurchaseByVendorGroupDashboard { get; init; }
|
||||
public List<BarSeries>? PurchaseByVendorCategoryDashboard { get; init; }
|
||||
}
|
||||
|
||||
public class GetPurchaseDashboardResult
|
||||
{
|
||||
public GetPurchaseDashboardDto? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetPurchaseDashboardRequest : IRequest<GetPurchaseDashboardResult>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetPurchaseDashboardHandler : IRequestHandler<GetPurchaseDashboardRequest, GetPurchaseDashboardResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetPurchaseDashboardHandler(IQueryContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetPurchaseDashboardResult> Handle(GetPurchaseDashboardRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var purchaseOrderItemData = await _context.PurchaseOrderItem
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.PurchaseOrder)
|
||||
.Include(x => x.Product)
|
||||
.Where(x => x.PurchaseOrder!.OrderStatus == PurchaseOrderStatus.Confirmed)
|
||||
.OrderByDescending(x => x.PurchaseOrder!.OrderDate)
|
||||
.Take(30)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var purchaseByVendorGroupData = _context.PurchaseOrderItem
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.PurchaseOrder)
|
||||
.ThenInclude(x => x!.Vendor)
|
||||
.ThenInclude(x => x!.VendorGroup)
|
||||
.Include(x => x.Product)
|
||||
.Where(x => x.Product!.Physical == true)
|
||||
.Select(x => new
|
||||
{
|
||||
Status = x.PurchaseOrder!.OrderStatus,
|
||||
VendorGroupName = x.PurchaseOrder!.Vendor!.VendorGroup!.Name,
|
||||
Quantity = x.Quantity
|
||||
})
|
||||
.GroupBy(x => new { x.Status, x.VendorGroupName })
|
||||
.Select(g => new
|
||||
{
|
||||
Status = g.Key.Status,
|
||||
VendorGroupName = g.Key.VendorGroupName,
|
||||
Quantity = g.Sum(x => x.Quantity)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var purchaseByVendorCategoryDate = _context.PurchaseOrderItem
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.PurchaseOrder)
|
||||
.ThenInclude(x => x!.Vendor)
|
||||
.ThenInclude(x => x!.VendorCategory)
|
||||
.Include(x => x.Product)
|
||||
.Where(x => x.Product!.Physical == true)
|
||||
.Select(x => new
|
||||
{
|
||||
Status = x.PurchaseOrder!.OrderStatus,
|
||||
VendorCategoryName = x.PurchaseOrder!.Vendor!.VendorCategory!.Name,
|
||||
Quantity = x.Quantity
|
||||
})
|
||||
.GroupBy(x => new { x.Status, x.VendorCategoryName })
|
||||
.Select(g => new
|
||||
{
|
||||
Status = g.Key.Status,
|
||||
VendorCategoryName = g.Key.VendorCategoryName,
|
||||
Quantity = g.Sum(x => x.Quantity)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
var result = new GetPurchaseDashboardResult
|
||||
{
|
||||
Data = new GetPurchaseDashboardDto
|
||||
{
|
||||
PurchaseOrderDashboard = purchaseOrderItemData,
|
||||
PurchaseByVendorGroupDashboard =
|
||||
Enum.GetValues(typeof(PurchaseOrderStatus))
|
||||
.Cast<PurchaseOrderStatus>()
|
||||
.Select(status => new BarSeries
|
||||
{
|
||||
Type = "Bar",
|
||||
XName = "x",
|
||||
Width = 2,
|
||||
YName = "y",
|
||||
Name = Enum.GetName(typeof(PurchaseOrderStatus), status)!,
|
||||
ColumnSpacing = 0.1,
|
||||
TooltipMappingName = "tooltipMappingName",
|
||||
DataSource = purchaseByVendorGroupData
|
||||
.Where(x => x.Status == status)
|
||||
.Select(x => new BarDataItem
|
||||
{
|
||||
X = x.VendorGroupName ?? "",
|
||||
TooltipMappingName = x.VendorGroupName ?? "",
|
||||
Y = (int)x.Quantity!.Value
|
||||
}).ToList()
|
||||
})
|
||||
.ToList(),
|
||||
PurchaseByVendorCategoryDashboard =
|
||||
Enum.GetValues(typeof(PurchaseOrderStatus))
|
||||
.Cast<PurchaseOrderStatus>()
|
||||
.Select(status => new BarSeries
|
||||
{
|
||||
Type = "Column",
|
||||
XName = "x",
|
||||
Width = 2,
|
||||
YName = "y",
|
||||
Name = Enum.GetName(typeof(PurchaseOrderStatus), status)!,
|
||||
ColumnSpacing = 0.1,
|
||||
TooltipMappingName = "tooltipMappingName",
|
||||
DataSource = purchaseByVendorCategoryDate
|
||||
.Where(x => x.Status == status)
|
||||
.Select(x => new BarDataItem
|
||||
{
|
||||
X = x.VendorCategoryName ?? "",
|
||||
TooltipMappingName = x.VendorCategoryName ?? "",
|
||||
Y = (int)x.Quantity!.Value
|
||||
}).ToList()
|
||||
})
|
||||
.ToList(),
|
||||
}
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.DashboardManager.Queries;
|
||||
|
||||
|
||||
public class GetSalesDashboardDto
|
||||
{
|
||||
public List<SalesOrderItem>? SalesOrderDashboard { get; init; }
|
||||
public List<BarSeries>? SalesByCustomerGroupDashboard { get; init; }
|
||||
public List<BarSeries>? SalesByCustomerCategoryDashboard { get; init; }
|
||||
}
|
||||
|
||||
public class GetSalesDashboardResult
|
||||
{
|
||||
public GetSalesDashboardDto? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetSalesDashboardRequest : IRequest<GetSalesDashboardResult>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetSalesDashboardHandler : IRequestHandler<GetSalesDashboardRequest, GetSalesDashboardResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetSalesDashboardHandler(IQueryContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetSalesDashboardResult> Handle(GetSalesDashboardRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var salesOrderItemData = await _context.SalesOrderItem
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.SalesOrder)
|
||||
.Include(x => x.Product)
|
||||
.Where(x => x.SalesOrder!.OrderStatus == SalesOrderStatus.Confirmed)
|
||||
.OrderByDescending(x => x.SalesOrder!.OrderDate)
|
||||
.Take(30)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var salesByCustomerGroupData = _context.SalesOrderItem
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.SalesOrder)
|
||||
.ThenInclude(x => x!.Customer)
|
||||
.ThenInclude(x => x!.CustomerGroup)
|
||||
.Include(x => x.Product)
|
||||
.Where(x => x.Product!.Physical == true)
|
||||
.Select(x => new
|
||||
{
|
||||
Status = x.SalesOrder!.OrderStatus,
|
||||
CustomerGroupName = x.SalesOrder!.Customer!.CustomerGroup!.Name,
|
||||
Quantity = x.Quantity
|
||||
})
|
||||
.GroupBy(x => new { x.Status, x.CustomerGroupName })
|
||||
.Select(g => new
|
||||
{
|
||||
Status = g.Key.Status,
|
||||
CustomerGroupName = g.Key.CustomerGroupName,
|
||||
Quantity = g.Sum(x => x.Quantity)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var salesByCustomerCategoryData = _context.SalesOrderItem
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.SalesOrder)
|
||||
.ThenInclude(x => x!.Customer)
|
||||
.ThenInclude(x => x!.CustomerCategory)
|
||||
.Include(x => x.Product)
|
||||
.Where(x => x.Product!.Physical == true)
|
||||
.Select(x => new
|
||||
{
|
||||
Status = x.SalesOrder!.OrderStatus,
|
||||
CustomerCategoryName = x.SalesOrder!.Customer!.CustomerCategory!.Name,
|
||||
Quantity = x.Quantity
|
||||
})
|
||||
.GroupBy(x => new { x.Status, x.CustomerCategoryName })
|
||||
.Select(g => new
|
||||
{
|
||||
Status = g.Key.Status,
|
||||
CustomerCategoryName = g.Key.CustomerCategoryName,
|
||||
Quantity = g.Sum(x => x.Quantity)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
var result = new GetSalesDashboardResult
|
||||
{
|
||||
Data = new GetSalesDashboardDto
|
||||
{
|
||||
SalesOrderDashboard = salesOrderItemData,
|
||||
SalesByCustomerGroupDashboard =
|
||||
Enum.GetValues(typeof(SalesOrderStatus))
|
||||
.Cast<SalesOrderStatus>()
|
||||
.Select(status => new BarSeries
|
||||
{
|
||||
Type = "Column",
|
||||
XName = "x",
|
||||
Width = 2,
|
||||
YName = "y",
|
||||
Name = Enum.GetName(typeof(SalesOrderStatus), status)!,
|
||||
ColumnSpacing = 0.1,
|
||||
TooltipMappingName = "tooltipMappingName",
|
||||
DataSource = salesByCustomerGroupData
|
||||
.Where(x => x.Status == status)
|
||||
.Select(x => new BarDataItem
|
||||
{
|
||||
X = x.CustomerGroupName ?? "",
|
||||
TooltipMappingName = x.CustomerGroupName ?? "",
|
||||
Y = (int)x.Quantity!.Value
|
||||
}).ToList()
|
||||
})
|
||||
.ToList(),
|
||||
SalesByCustomerCategoryDashboard =
|
||||
Enum.GetValues(typeof(SalesOrderStatus))
|
||||
.Cast<SalesOrderStatus>()
|
||||
.Select(status => new BarSeries
|
||||
{
|
||||
Type = "Bar",
|
||||
XName = "x",
|
||||
Width = 2,
|
||||
YName = "y",
|
||||
Name = Enum.GetName(typeof(SalesOrderStatus), status)!,
|
||||
ColumnSpacing = 0.1,
|
||||
TooltipMappingName = "tooltipMappingName",
|
||||
DataSource = salesByCustomerCategoryData
|
||||
.Where(x => x.Status == status)
|
||||
.Select(x => new BarDataItem
|
||||
{
|
||||
X = x.CustomerCategoryName ?? "",
|
||||
TooltipMappingName = x.CustomerCategoryName ?? "",
|
||||
Y = (int)x.Quantity!.Value
|
||||
}).ToList()
|
||||
})
|
||||
.ToList()
|
||||
}
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using Application.Common.Extensions;
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.DeliveryOrderManager.Commands;
|
||||
|
||||
public class CreateDeliveryOrderResult
|
||||
{
|
||||
public DeliveryOrder? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateDeliveryOrderRequest : IRequest<CreateDeliveryOrderResult>
|
||||
{
|
||||
public DateTime? DeliveryDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? SalesOrderId { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateDeliveryOrderValidator : AbstractValidator<CreateDeliveryOrderRequest>
|
||||
{
|
||||
public CreateDeliveryOrderValidator()
|
||||
{
|
||||
RuleFor(x => x.DeliveryDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.SalesOrderId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateDeliveryOrderHandler : IRequestHandler<CreateDeliveryOrderRequest, CreateDeliveryOrderResult>
|
||||
{
|
||||
private readonly ICommandRepository<DeliveryOrder> _deliveryOrderRepository;
|
||||
private readonly ICommandRepository<SalesOrderItem> _salesOrderItemRepository;
|
||||
private readonly ICommandRepository<Warehouse> _warehouseRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public CreateDeliveryOrderHandler(
|
||||
ICommandRepository<DeliveryOrder> deliveryOrderRepository,
|
||||
ICommandRepository<SalesOrderItem> salesOrderItemRepository,
|
||||
ICommandRepository<Warehouse> warehouseRepository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_deliveryOrderRepository = deliveryOrderRepository;
|
||||
_salesOrderItemRepository = salesOrderItemRepository;
|
||||
_warehouseRepository = warehouseRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<CreateDeliveryOrderResult> Handle(CreateDeliveryOrderRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new DeliveryOrder();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(DeliveryOrder), "", "DO");
|
||||
entity.DeliveryDate = request.DeliveryDate;
|
||||
entity.Status = (DeliveryOrderStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.SalesOrderId = request.SalesOrderId;
|
||||
|
||||
await _deliveryOrderRepository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
var defaultWarehouse = await _warehouseRepository
|
||||
.GetQuery()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.SystemWarehouse == false)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (defaultWarehouse != null)
|
||||
{
|
||||
var items = await _salesOrderItemRepository
|
||||
.GetQuery()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.SalesOrderId == entity.SalesOrderId)
|
||||
.Include(x => x.Product)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item?.Product?.Physical ?? false)
|
||||
{
|
||||
await _inventoryTransactionService.DeliveryOrderCreateInvenTrans(
|
||||
entity.Id,
|
||||
defaultWarehouse.Id,
|
||||
item.ProductId,
|
||||
item.Quantity,
|
||||
entity.CreatedById,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new CreateDeliveryOrderResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.DeliveryOrderManager.Commands;
|
||||
|
||||
public class DeleteDeliveryOrderResult
|
||||
{
|
||||
public DeliveryOrder? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteDeliveryOrderRequest : IRequest<DeleteDeliveryOrderResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteDeliveryOrderValidator : AbstractValidator<DeleteDeliveryOrderRequest>
|
||||
{
|
||||
public DeleteDeliveryOrderValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteDeliveryOrderHandler : IRequestHandler<DeleteDeliveryOrderRequest, DeleteDeliveryOrderResult>
|
||||
{
|
||||
private readonly ICommandRepository<DeliveryOrder> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeleteDeliveryOrderHandler(
|
||||
ICommandRepository<DeliveryOrder> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeleteDeliveryOrderResult> Handle(DeleteDeliveryOrderRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.DeletedById;
|
||||
|
||||
_repository.Delete(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(DeliveryOrder),
|
||||
entity.DeliveryDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new DeleteDeliveryOrderResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.DeliveryOrderManager.Commands;
|
||||
|
||||
public class UpdateDeliveryOrderResult
|
||||
{
|
||||
public DeliveryOrder? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateDeliveryOrderRequest : IRequest<UpdateDeliveryOrderResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public DateTime? DeliveryDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? SalesOrderId { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateDeliveryOrderValidator : AbstractValidator<UpdateDeliveryOrderRequest>
|
||||
{
|
||||
public UpdateDeliveryOrderValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeliveryDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.SalesOrderId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateDeliveryOrderHandler : IRequestHandler<UpdateDeliveryOrderRequest, UpdateDeliveryOrderResult>
|
||||
{
|
||||
private readonly ICommandRepository<DeliveryOrder> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public UpdateDeliveryOrderHandler(
|
||||
ICommandRepository<DeliveryOrder> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<UpdateDeliveryOrderResult> Handle(UpdateDeliveryOrderRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.DeliveryDate = request.DeliveryDate;
|
||||
entity.Status = (DeliveryOrderStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.SalesOrderId = request.SalesOrderId;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(DeliveryOrder),
|
||||
entity.DeliveryDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new UpdateDeliveryOrderResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.DeliveryOrderManager.Queries;
|
||||
|
||||
public record GetDeliveryOrderListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? DeliveryDate { get; init; }
|
||||
public DeliveryOrderStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? SalesOrderId { get; init; }
|
||||
public string? SalesOrderNumber { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderListProfile : Profile
|
||||
{
|
||||
public GetDeliveryOrderListProfile()
|
||||
{
|
||||
CreateMap<DeliveryOrder, GetDeliveryOrderListDto>()
|
||||
.ForMember(
|
||||
dest => dest.SalesOrderNumber,
|
||||
opt => opt.MapFrom(src => src.SalesOrder != null ? src.SalesOrder.Number : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderListResult
|
||||
{
|
||||
public List<GetDeliveryOrderListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderListRequest : IRequest<GetDeliveryOrderListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetDeliveryOrderListHandler : IRequestHandler<GetDeliveryOrderListRequest, GetDeliveryOrderListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetDeliveryOrderListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetDeliveryOrderListResult> Handle(GetDeliveryOrderListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.DeliveryOrder
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.SalesOrder)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetDeliveryOrderListDto>>(entities);
|
||||
|
||||
return new GetDeliveryOrderListResult
|
||||
{
|
||||
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.DeliveryOrderManager.Queries;
|
||||
|
||||
|
||||
public class GetDeliveryOrderSingleProfile : Profile
|
||||
{
|
||||
public GetDeliveryOrderSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderSingleResult
|
||||
{
|
||||
public DeliveryOrder? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderSingleRequest : IRequest<GetDeliveryOrderSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderSingleValidator : AbstractValidator<GetDeliveryOrderSingleRequest>
|
||||
{
|
||||
public GetDeliveryOrderSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderSingleHandler : IRequestHandler<GetDeliveryOrderSingleRequest, GetDeliveryOrderSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetDeliveryOrderSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetDeliveryOrderSingleResult> Handle(GetDeliveryOrderSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.DeliveryOrder
|
||||
.AsNoTracking()
|
||||
.Include(x => x.SalesOrder)
|
||||
.ThenInclude(x => x.Customer)
|
||||
.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(DeliveryOrder))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetDeliveryOrderSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.DeliveryOrderManager.Queries;
|
||||
|
||||
public record GetDeliveryOrderStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderStatusListProfile : Profile
|
||||
{
|
||||
public GetDeliveryOrderStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderStatusListResult
|
||||
{
|
||||
public List<GetDeliveryOrderStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetDeliveryOrderStatusListRequest : IRequest<GetDeliveryOrderStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetDeliveryOrderStatusListHandler : IRequestHandler<GetDeliveryOrderStatusListRequest, GetDeliveryOrderStatusListResult>
|
||||
{
|
||||
|
||||
public GetDeliveryOrderStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetDeliveryOrderStatusListResult> Handle(GetDeliveryOrderStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(DeliveryOrderStatus))
|
||||
.Cast<DeliveryOrderStatus>()
|
||||
.Select(status => new GetDeliveryOrderStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetDeliveryOrderStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using Application.Common.Services.FileDocumentManager;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.FileDocumentManager.Commands;
|
||||
|
||||
public class CreateDocumentResult
|
||||
{
|
||||
public string? DocumentName { get; init; }
|
||||
}
|
||||
|
||||
public class CreateDocumentRequest : IRequest<CreateDocumentResult>
|
||||
{
|
||||
public string? OriginalFileName { get; init; }
|
||||
public string? Extension { get; init; }
|
||||
public byte[]? Data { get; init; }
|
||||
public long? Size { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
public string? Description { get; init; }
|
||||
}
|
||||
|
||||
public class CreateDocumentValidator : AbstractValidator<CreateDocumentRequest>
|
||||
{
|
||||
public CreateDocumentValidator()
|
||||
{
|
||||
RuleFor(x => x.OriginalFileName)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Extension)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Data)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Size)
|
||||
.NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateDocumentHandler : IRequestHandler<CreateDocumentRequest, CreateDocumentResult>
|
||||
{
|
||||
private readonly IFileDocumentService _uploadDocument;
|
||||
|
||||
public CreateDocumentHandler(IFileDocumentService uploadDocument)
|
||||
{
|
||||
_uploadDocument = uploadDocument;
|
||||
}
|
||||
|
||||
public async Task<CreateDocumentResult> Handle(CreateDocumentRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _uploadDocument.UploadAsync(
|
||||
request.OriginalFileName,
|
||||
request.Extension,
|
||||
request.Data,
|
||||
request.Size,
|
||||
request.Description,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new CreateDocumentResult { DocumentName = result };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using Application.Common.Services.FileDocumentManager;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.FileDocumentManager.Queries;
|
||||
|
||||
|
||||
public class GetDocumentResult
|
||||
{
|
||||
public byte[]? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetDocumentRequest : IRequest<GetDocumentResult>
|
||||
{
|
||||
public string? DocumentName { get; init; }
|
||||
}
|
||||
|
||||
public class GetDocumentValidator : AbstractValidator<GetDocumentRequest>
|
||||
{
|
||||
public GetDocumentValidator()
|
||||
{
|
||||
RuleFor(x => x.DocumentName)
|
||||
.NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetDocumentHandler : IRequestHandler<GetDocumentRequest, GetDocumentResult>
|
||||
{
|
||||
private readonly IFileDocumentService _documentService;
|
||||
|
||||
public GetDocumentHandler(IFileDocumentService documentService)
|
||||
{
|
||||
_documentService = documentService;
|
||||
}
|
||||
|
||||
public async Task<GetDocumentResult> Handle(GetDocumentRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _documentService.GetFileAsync(request.DocumentName ?? "", cancellationToken);
|
||||
|
||||
return new GetDocumentResult { Data = result };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using Application.Common.Services.FileImageManager;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.FileImageManager.Commands;
|
||||
|
||||
public class CreateImageResult
|
||||
{
|
||||
public string? ImageName { get; init; }
|
||||
}
|
||||
|
||||
public class CreateImageRequest : IRequest<CreateImageResult>
|
||||
{
|
||||
public string? OriginalFileName { get; init; }
|
||||
public string? Extension { get; init; }
|
||||
public byte[]? Data { get; init; }
|
||||
public long? Size { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
public string? Description { get; init; }
|
||||
}
|
||||
|
||||
public class CreateImageValidator : AbstractValidator<CreateImageRequest>
|
||||
{
|
||||
public CreateImageValidator()
|
||||
{
|
||||
RuleFor(x => x.OriginalFileName)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Extension)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Data)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Size)
|
||||
.NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateImageHandler : IRequestHandler<CreateImageRequest, CreateImageResult>
|
||||
{
|
||||
private readonly IFileImageService _uploadImage;
|
||||
|
||||
public CreateImageHandler(IFileImageService uploadImage)
|
||||
{
|
||||
_uploadImage = uploadImage;
|
||||
}
|
||||
|
||||
public async Task<CreateImageResult> Handle(CreateImageRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _uploadImage.UploadAsync(
|
||||
request.OriginalFileName,
|
||||
request.Extension,
|
||||
request.Data,
|
||||
request.Size,
|
||||
request.Description,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new CreateImageResult { ImageName = result };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using Application.Common.Services.FileImageManager;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.FileImageManager.Queries;
|
||||
|
||||
|
||||
public class GetImageResult
|
||||
{
|
||||
public byte[]? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetImageRequest : IRequest<GetImageResult>
|
||||
{
|
||||
public string? ImageName { get; init; }
|
||||
}
|
||||
|
||||
public class GetImageValidator : AbstractValidator<GetImageRequest>
|
||||
{
|
||||
public GetImageValidator()
|
||||
{
|
||||
RuleFor(x => x.ImageName)
|
||||
.NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetImageHandler : IRequestHandler<GetImageRequest, GetImageResult>
|
||||
{
|
||||
private readonly IFileImageService _imageService;
|
||||
|
||||
public GetImageHandler(IFileImageService imageService)
|
||||
{
|
||||
_imageService = imageService;
|
||||
}
|
||||
|
||||
public async Task<GetImageResult> Handle(GetImageRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _imageService.GetFileAsync(request.ImageName ?? "", cancellationToken);
|
||||
|
||||
return new GetImageResult { Data = result };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
using Application.Common.Extensions;
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.GoodsReceiveManager.Commands;
|
||||
|
||||
public class CreateGoodsReceiveResult
|
||||
{
|
||||
public GoodsReceive? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateGoodsReceiveRequest : IRequest<CreateGoodsReceiveResult>
|
||||
{
|
||||
public DateTime? ReceiveDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? PurchaseOrderId { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateGoodsReceiveValidator : AbstractValidator<CreateGoodsReceiveRequest>
|
||||
{
|
||||
public CreateGoodsReceiveValidator()
|
||||
{
|
||||
RuleFor(x => x.ReceiveDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.PurchaseOrderId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateGoodsReceiveHandler : IRequestHandler<CreateGoodsReceiveRequest, CreateGoodsReceiveResult>
|
||||
{
|
||||
private readonly ICommandRepository<GoodsReceive> _deliveryOrderRepository;
|
||||
private readonly ICommandRepository<PurchaseOrderItem> _purchaseOrderItemRepository;
|
||||
private readonly ICommandRepository<Warehouse> _warehouseRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public CreateGoodsReceiveHandler(
|
||||
ICommandRepository<GoodsReceive> deliveryOrderRepository,
|
||||
ICommandRepository<PurchaseOrderItem> purchaseOrderItemRepository,
|
||||
ICommandRepository<Warehouse> warehouseRepository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_deliveryOrderRepository = deliveryOrderRepository;
|
||||
_purchaseOrderItemRepository = purchaseOrderItemRepository;
|
||||
_warehouseRepository = warehouseRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<CreateGoodsReceiveResult> Handle(CreateGoodsReceiveRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new GoodsReceive();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(GoodsReceive), "", "GR");
|
||||
entity.ReceiveDate = request.ReceiveDate;
|
||||
entity.Status = (GoodsReceiveStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.PurchaseOrderId = request.PurchaseOrderId;
|
||||
|
||||
await _deliveryOrderRepository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
var defaultWarehouse = await _warehouseRepository
|
||||
.GetQuery()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.SystemWarehouse == false)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (defaultWarehouse != null)
|
||||
{
|
||||
var items = await _purchaseOrderItemRepository
|
||||
.GetQuery()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.PurchaseOrderId == entity.PurchaseOrderId)
|
||||
.Include(x => x.Product)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item?.Product?.Physical ?? false)
|
||||
{
|
||||
await _inventoryTransactionService.GoodsReceiveCreateInvenTrans(
|
||||
entity.Id,
|
||||
defaultWarehouse.Id,
|
||||
item.ProductId,
|
||||
item.Quantity,
|
||||
entity.CreatedById,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new CreateGoodsReceiveResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.GoodsReceiveManager.Commands;
|
||||
|
||||
public class DeleteGoodsReceiveResult
|
||||
{
|
||||
public GoodsReceive? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteGoodsReceiveRequest : IRequest<DeleteGoodsReceiveResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteGoodsReceiveValidator : AbstractValidator<DeleteGoodsReceiveRequest>
|
||||
{
|
||||
public DeleteGoodsReceiveValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteGoodsReceiveHandler : IRequestHandler<DeleteGoodsReceiveRequest, DeleteGoodsReceiveResult>
|
||||
{
|
||||
private readonly ICommandRepository<GoodsReceive> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeleteGoodsReceiveHandler(
|
||||
ICommandRepository<GoodsReceive> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
public async Task<DeleteGoodsReceiveResult> Handle(DeleteGoodsReceiveRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.DeletedById;
|
||||
|
||||
_repository.Delete(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(GoodsReceive),
|
||||
entity.ReceiveDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new DeleteGoodsReceiveResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.GoodsReceiveManager.Commands;
|
||||
|
||||
public class UpdateGoodsReceiveResult
|
||||
{
|
||||
public GoodsReceive? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateGoodsReceiveRequest : IRequest<UpdateGoodsReceiveResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public DateTime? ReceiveDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? PurchaseOrderId { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateGoodsReceiveValidator : AbstractValidator<UpdateGoodsReceiveRequest>
|
||||
{
|
||||
public UpdateGoodsReceiveValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.ReceiveDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.PurchaseOrderId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateGoodsReceiveHandler : IRequestHandler<UpdateGoodsReceiveRequest, UpdateGoodsReceiveResult>
|
||||
{
|
||||
private readonly ICommandRepository<GoodsReceive> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public UpdateGoodsReceiveHandler(
|
||||
ICommandRepository<GoodsReceive> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<UpdateGoodsReceiveResult> Handle(UpdateGoodsReceiveRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.ReceiveDate = request.ReceiveDate;
|
||||
entity.Status = (GoodsReceiveStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.PurchaseOrderId = request.PurchaseOrderId;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(GoodsReceive),
|
||||
entity.ReceiveDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new UpdateGoodsReceiveResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.GoodsReceiveManager.Queries;
|
||||
|
||||
public record GetGoodsReceiveListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? ReceiveDate { get; init; }
|
||||
public GoodsReceiveStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? PurchaseOrderId { get; init; }
|
||||
public string? PurchaseOrderNumber { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveListProfile : Profile
|
||||
{
|
||||
public GetGoodsReceiveListProfile()
|
||||
{
|
||||
CreateMap<GoodsReceive, GetGoodsReceiveListDto>()
|
||||
.ForMember(
|
||||
dest => dest.PurchaseOrderNumber,
|
||||
opt => opt.MapFrom(src => src.PurchaseOrder != null ? src.PurchaseOrder.Number : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveListResult
|
||||
{
|
||||
public List<GetGoodsReceiveListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveListRequest : IRequest<GetGoodsReceiveListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetGoodsReceiveListHandler : IRequestHandler<GetGoodsReceiveListRequest, GetGoodsReceiveListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetGoodsReceiveListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetGoodsReceiveListResult> Handle(GetGoodsReceiveListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.GoodsReceive
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.PurchaseOrder)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetGoodsReceiveListDto>>(entities);
|
||||
|
||||
return new GetGoodsReceiveListResult
|
||||
{
|
||||
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.GoodsReceiveManager.Queries;
|
||||
|
||||
|
||||
public class GetGoodsReceiveSingleProfile : Profile
|
||||
{
|
||||
public GetGoodsReceiveSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveSingleResult
|
||||
{
|
||||
public GoodsReceive? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveSingleRequest : IRequest<GetGoodsReceiveSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveSingleValidator : AbstractValidator<GetGoodsReceiveSingleRequest>
|
||||
{
|
||||
public GetGoodsReceiveSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveSingleHandler : IRequestHandler<GetGoodsReceiveSingleRequest, GetGoodsReceiveSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetGoodsReceiveSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetGoodsReceiveSingleResult> Handle(GetGoodsReceiveSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.GoodsReceive
|
||||
.AsNoTracking()
|
||||
.Include(x => x.PurchaseOrder)
|
||||
.ThenInclude(x => x.Vendor)
|
||||
.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(GoodsReceive))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetGoodsReceiveSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.GoodsReceiveManager.Queries;
|
||||
|
||||
public record GetGoodsReceiveStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveStatusListProfile : Profile
|
||||
{
|
||||
public GetGoodsReceiveStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveStatusListResult
|
||||
{
|
||||
public List<GetGoodsReceiveStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetGoodsReceiveStatusListRequest : IRequest<GetGoodsReceiveStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetGoodsReceiveStatusListHandler : IRequestHandler<GetGoodsReceiveStatusListRequest, GetGoodsReceiveStatusListResult>
|
||||
{
|
||||
|
||||
public GetGoodsReceiveStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetGoodsReceiveStatusListResult> Handle(GetGoodsReceiveStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(GoodsReceiveStatus))
|
||||
.Cast<GoodsReceiveStatus>()
|
||||
.Select(status => new GetGoodsReceiveStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetGoodsReceiveStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class DeliveryOrderCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeliveryOrderCreateInvenTransRequest : IRequest<DeliveryOrderCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeliveryOrderCreateInvenTransValidator : AbstractValidator<DeliveryOrderCreateInvenTransRequest>
|
||||
{
|
||||
public DeliveryOrderCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeliveryOrderCreateInvenTransHandler : IRequestHandler<DeliveryOrderCreateInvenTransRequest, DeliveryOrderCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeliveryOrderCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeliveryOrderCreateInvenTransResult> Handle(DeliveryOrderCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.DeliveryOrderCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new DeliveryOrderCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class DeliveryOrderDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeliveryOrderDeleteInvenTransRequest : IRequest<DeliveryOrderDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class DeliveryOrderDeleteInvenTransValidator : AbstractValidator<DeliveryOrderDeleteInvenTransRequest>
|
||||
{
|
||||
public DeliveryOrderDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeliveryOrderDeleteInvenTransHandler : IRequestHandler<DeliveryOrderDeleteInvenTransRequest, DeliveryOrderDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeliveryOrderDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeliveryOrderDeleteInvenTransResult> Handle(DeliveryOrderDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.DeliveryOrderDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new DeliveryOrderDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class DeliveryOrderUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeliveryOrderUpdateInvenTransRequest : IRequest<DeliveryOrderUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class DeliveryOrderUpdateInvenTransValidator : AbstractValidator<DeliveryOrderUpdateInvenTransRequest>
|
||||
{
|
||||
public DeliveryOrderUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeliveryOrderUpdateInvenTransHandler : IRequestHandler<DeliveryOrderUpdateInvenTransRequest, DeliveryOrderUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeliveryOrderUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeliveryOrderUpdateInvenTransResult> Handle(DeliveryOrderUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.DeliveryOrderUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new DeliveryOrderUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class GoodsReceiveCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class GoodsReceiveCreateInvenTransRequest : IRequest<GoodsReceiveCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class GoodsReceiveCreateInvenTransValidator : AbstractValidator<GoodsReceiveCreateInvenTransRequest>
|
||||
{
|
||||
public GoodsReceiveCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GoodsReceiveCreateInvenTransHandler : IRequestHandler<GoodsReceiveCreateInvenTransRequest, GoodsReceiveCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public GoodsReceiveCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<GoodsReceiveCreateInvenTransResult> Handle(GoodsReceiveCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.GoodsReceiveCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new GoodsReceiveCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class GoodsReceiveDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class GoodsReceiveDeleteInvenTransRequest : IRequest<GoodsReceiveDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class GoodsReceiveDeleteInvenTransValidator : AbstractValidator<GoodsReceiveDeleteInvenTransRequest>
|
||||
{
|
||||
public GoodsReceiveDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GoodsReceiveDeleteInvenTransHandler : IRequestHandler<GoodsReceiveDeleteInvenTransRequest, GoodsReceiveDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public GoodsReceiveDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<GoodsReceiveDeleteInvenTransResult> Handle(GoodsReceiveDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.GoodsReceiveDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new GoodsReceiveDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class GoodsReceiveUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class GoodsReceiveUpdateInvenTransRequest : IRequest<GoodsReceiveUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class GoodsReceiveUpdateInvenTransValidator : AbstractValidator<GoodsReceiveUpdateInvenTransRequest>
|
||||
{
|
||||
public GoodsReceiveUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GoodsReceiveUpdateInvenTransHandler : IRequestHandler<GoodsReceiveUpdateInvenTransRequest, GoodsReceiveUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public GoodsReceiveUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<GoodsReceiveUpdateInvenTransResult> Handle(GoodsReceiveUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.GoodsReceiveUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new GoodsReceiveUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class NegativeAdjustmentCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentCreateInvenTransRequest : IRequest<NegativeAdjustmentCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentCreateInvenTransValidator : AbstractValidator<NegativeAdjustmentCreateInvenTransRequest>
|
||||
{
|
||||
public NegativeAdjustmentCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentCreateInvenTransHandler : IRequestHandler<NegativeAdjustmentCreateInvenTransRequest, NegativeAdjustmentCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public NegativeAdjustmentCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<NegativeAdjustmentCreateInvenTransResult> Handle(NegativeAdjustmentCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.NegativeAdjustmentCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new NegativeAdjustmentCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class NegativeAdjustmentDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentDeleteInvenTransRequest : IRequest<NegativeAdjustmentDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentDeleteInvenTransValidator : AbstractValidator<NegativeAdjustmentDeleteInvenTransRequest>
|
||||
{
|
||||
public NegativeAdjustmentDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentDeleteInvenTransHandler : IRequestHandler<NegativeAdjustmentDeleteInvenTransRequest, NegativeAdjustmentDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public NegativeAdjustmentDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<NegativeAdjustmentDeleteInvenTransResult> Handle(NegativeAdjustmentDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.NegativeAdjustmentDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new NegativeAdjustmentDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class NegativeAdjustmentUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentUpdateInvenTransRequest : IRequest<NegativeAdjustmentUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentUpdateInvenTransValidator : AbstractValidator<NegativeAdjustmentUpdateInvenTransRequest>
|
||||
{
|
||||
public NegativeAdjustmentUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class NegativeAdjustmentUpdateInvenTransHandler : IRequestHandler<NegativeAdjustmentUpdateInvenTransRequest, NegativeAdjustmentUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public NegativeAdjustmentUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<NegativeAdjustmentUpdateInvenTransResult> Handle(NegativeAdjustmentUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.NegativeAdjustmentUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new NegativeAdjustmentUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class PositiveAdjustmentCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentCreateInvenTransRequest : IRequest<PositiveAdjustmentCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentCreateInvenTransValidator : AbstractValidator<PositiveAdjustmentCreateInvenTransRequest>
|
||||
{
|
||||
public PositiveAdjustmentCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentCreateInvenTransHandler : IRequestHandler<PositiveAdjustmentCreateInvenTransRequest, PositiveAdjustmentCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public PositiveAdjustmentCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<PositiveAdjustmentCreateInvenTransResult> Handle(PositiveAdjustmentCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.PositiveAdjustmentCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new PositiveAdjustmentCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class PositiveAdjustmentDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentDeleteInvenTransRequest : IRequest<PositiveAdjustmentDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentDeleteInvenTransValidator : AbstractValidator<PositiveAdjustmentDeleteInvenTransRequest>
|
||||
{
|
||||
public PositiveAdjustmentDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentDeleteInvenTransHandler : IRequestHandler<PositiveAdjustmentDeleteInvenTransRequest, PositiveAdjustmentDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public PositiveAdjustmentDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<PositiveAdjustmentDeleteInvenTransResult> Handle(PositiveAdjustmentDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.PositiveAdjustmentDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new PositiveAdjustmentDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class PositiveAdjustmentUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentUpdateInvenTransRequest : IRequest<PositiveAdjustmentUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentUpdateInvenTransValidator : AbstractValidator<PositiveAdjustmentUpdateInvenTransRequest>
|
||||
{
|
||||
public PositiveAdjustmentUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class PositiveAdjustmentUpdateInvenTransHandler : IRequestHandler<PositiveAdjustmentUpdateInvenTransRequest, PositiveAdjustmentUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public PositiveAdjustmentUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<PositiveAdjustmentUpdateInvenTransResult> Handle(PositiveAdjustmentUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.PositiveAdjustmentUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new PositiveAdjustmentUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class PurchaseReturnCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class PurchaseReturnCreateInvenTransRequest : IRequest<PurchaseReturnCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class PurchaseReturnCreateInvenTransValidator : AbstractValidator<PurchaseReturnCreateInvenTransRequest>
|
||||
{
|
||||
public PurchaseReturnCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class PurchaseReturnCreateInvenTransHandler : IRequestHandler<PurchaseReturnCreateInvenTransRequest, PurchaseReturnCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public PurchaseReturnCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<PurchaseReturnCreateInvenTransResult> Handle(PurchaseReturnCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.PurchaseReturnCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new PurchaseReturnCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class PurchaseReturnDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class PurchaseReturnDeleteInvenTransRequest : IRequest<PurchaseReturnDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class PurchaseReturnDeleteInvenTransValidator : AbstractValidator<PurchaseReturnDeleteInvenTransRequest>
|
||||
{
|
||||
public PurchaseReturnDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class PurchaseReturnDeleteInvenTransHandler : IRequestHandler<PurchaseReturnDeleteInvenTransRequest, PurchaseReturnDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public PurchaseReturnDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<PurchaseReturnDeleteInvenTransResult> Handle(PurchaseReturnDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.PurchaseReturnDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new PurchaseReturnDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class PurchaseReturnUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class PurchaseReturnUpdateInvenTransRequest : IRequest<PurchaseReturnUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class PurchaseReturnUpdateInvenTransValidator : AbstractValidator<PurchaseReturnUpdateInvenTransRequest>
|
||||
{
|
||||
public PurchaseReturnUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class PurchaseReturnUpdateInvenTransHandler : IRequestHandler<PurchaseReturnUpdateInvenTransRequest, PurchaseReturnUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public PurchaseReturnUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<PurchaseReturnUpdateInvenTransResult> Handle(PurchaseReturnUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.PurchaseReturnUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new PurchaseReturnUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class SalesReturnCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class SalesReturnCreateInvenTransRequest : IRequest<SalesReturnCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class SalesReturnCreateInvenTransValidator : AbstractValidator<SalesReturnCreateInvenTransRequest>
|
||||
{
|
||||
public SalesReturnCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class SalesReturnCreateInvenTransHandler : IRequestHandler<SalesReturnCreateInvenTransRequest, SalesReturnCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public SalesReturnCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<SalesReturnCreateInvenTransResult> Handle(SalesReturnCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.SalesReturnCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new SalesReturnCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class SalesReturnDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class SalesReturnDeleteInvenTransRequest : IRequest<SalesReturnDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class SalesReturnDeleteInvenTransValidator : AbstractValidator<SalesReturnDeleteInvenTransRequest>
|
||||
{
|
||||
public SalesReturnDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class SalesReturnDeleteInvenTransHandler : IRequestHandler<SalesReturnDeleteInvenTransRequest, SalesReturnDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public SalesReturnDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<SalesReturnDeleteInvenTransResult> Handle(SalesReturnDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.SalesReturnDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new SalesReturnDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class SalesReturnUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class SalesReturnUpdateInvenTransRequest : IRequest<SalesReturnUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class SalesReturnUpdateInvenTransValidator : AbstractValidator<SalesReturnUpdateInvenTransRequest>
|
||||
{
|
||||
public SalesReturnUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class SalesReturnUpdateInvenTransHandler : IRequestHandler<SalesReturnUpdateInvenTransRequest, SalesReturnUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public SalesReturnUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<SalesReturnUpdateInvenTransResult> Handle(SalesReturnUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.SalesReturnUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.WarehouseId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new SalesReturnUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class ScrappingCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class ScrappingCreateInvenTransRequest : IRequest<ScrappingCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class ScrappingCreateInvenTransValidator : AbstractValidator<ScrappingCreateInvenTransRequest>
|
||||
{
|
||||
public ScrappingCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class ScrappingCreateInvenTransHandler : IRequestHandler<ScrappingCreateInvenTransRequest, ScrappingCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public ScrappingCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<ScrappingCreateInvenTransResult> Handle(ScrappingCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.ScrappingCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new ScrappingCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class ScrappingDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class ScrappingDeleteInvenTransRequest : IRequest<ScrappingDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class ScrappingDeleteInvenTransValidator : AbstractValidator<ScrappingDeleteInvenTransRequest>
|
||||
{
|
||||
public ScrappingDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class ScrappingDeleteInvenTransHandler : IRequestHandler<ScrappingDeleteInvenTransRequest, ScrappingDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public ScrappingDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<ScrappingDeleteInvenTransResult> Handle(ScrappingDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.ScrappingDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new ScrappingDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class ScrappingUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class ScrappingUpdateInvenTransRequest : IRequest<ScrappingUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class ScrappingUpdateInvenTransValidator : AbstractValidator<ScrappingUpdateInvenTransRequest>
|
||||
{
|
||||
public ScrappingUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class ScrappingUpdateInvenTransHandler : IRequestHandler<ScrappingUpdateInvenTransRequest, ScrappingUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public ScrappingUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<ScrappingUpdateInvenTransResult> Handle(ScrappingUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.ScrappingUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new ScrappingUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class StockCountCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class StockCountCreateInvenTransRequest : IRequest<StockCountCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? QtySCCount { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class StockCountCreateInvenTransValidator : AbstractValidator<StockCountCreateInvenTransRequest>
|
||||
{
|
||||
public StockCountCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.QtySCCount).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class StockCountCreateInvenTransHandler : IRequestHandler<StockCountCreateInvenTransRequest, StockCountCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public StockCountCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<StockCountCreateInvenTransResult> Handle(StockCountCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.StockCountCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.ProductId,
|
||||
request.QtySCCount,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new StockCountCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class StockCountDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class StockCountDeleteInvenTransRequest : IRequest<StockCountDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class StockCountDeleteInvenTransValidator : AbstractValidator<StockCountDeleteInvenTransRequest>
|
||||
{
|
||||
public StockCountDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class StockCountDeleteInvenTransHandler : IRequestHandler<StockCountDeleteInvenTransRequest, StockCountDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public StockCountDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<StockCountDeleteInvenTransResult> Handle(StockCountDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.StockCountDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new StockCountDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class StockCountUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class StockCountUpdateInvenTransRequest : IRequest<StockCountUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? QtySCCount { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class StockCountUpdateInvenTransValidator : AbstractValidator<StockCountUpdateInvenTransRequest>
|
||||
{
|
||||
public StockCountUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.QtySCCount).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class StockCountUpdateInvenTransHandler : IRequestHandler<StockCountUpdateInvenTransRequest, StockCountUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public StockCountUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<StockCountUpdateInvenTransResult> Handle(StockCountUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.StockCountUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.ProductId,
|
||||
request.QtySCCount,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new StockCountUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class TransferInCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class TransferInCreateInvenTransRequest : IRequest<TransferInCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class TransferInCreateInvenTransValidator : AbstractValidator<TransferInCreateInvenTransRequest>
|
||||
{
|
||||
public TransferInCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class TransferInCreateInvenTransHandler : IRequestHandler<TransferInCreateInvenTransRequest, TransferInCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public TransferInCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<TransferInCreateInvenTransResult> Handle(TransferInCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.TransferInCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new TransferInCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class TransferInDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class TransferInDeleteInvenTransRequest : IRequest<TransferInDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class TransferInDeleteInvenTransValidator : AbstractValidator<TransferInDeleteInvenTransRequest>
|
||||
{
|
||||
public TransferInDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class TransferInDeleteInvenTransHandler : IRequestHandler<TransferInDeleteInvenTransRequest, TransferInDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public TransferInDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<TransferInDeleteInvenTransResult> Handle(TransferInDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.TransferInDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new TransferInDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class TransferInUpdateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class TransferInUpdateInvenTransRequest : IRequest<TransferInUpdateInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class TransferInUpdateInvenTransValidator : AbstractValidator<TransferInUpdateInvenTransRequest>
|
||||
{
|
||||
public TransferInUpdateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.UpdatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class TransferInUpdateInvenTransHandler : IRequestHandler<TransferInUpdateInvenTransRequest, TransferInUpdateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public TransferInUpdateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<TransferInUpdateInvenTransResult> Handle(TransferInUpdateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.TransferInUpdateInvenTrans(
|
||||
request.Id,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.UpdatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new TransferInUpdateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class TransferOutCreateInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class TransferOutCreateInvenTransRequest : IRequest<TransferOutCreateInvenTransResult>
|
||||
{
|
||||
public string? ModuleId { get; init; }
|
||||
public string? ProductId { get; init; }
|
||||
public double? Movement { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class TransferOutCreateInvenTransValidator : AbstractValidator<TransferOutCreateInvenTransRequest>
|
||||
{
|
||||
public TransferOutCreateInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.ModuleId).NotEmpty();
|
||||
RuleFor(x => x.ProductId).NotEmpty();
|
||||
RuleFor(x => x.Movement).NotEmpty();
|
||||
RuleFor(x => x.CreatedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class TransferOutCreateInvenTransHandler : IRequestHandler<TransferOutCreateInvenTransRequest, TransferOutCreateInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public TransferOutCreateInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<TransferOutCreateInvenTransResult> Handle(TransferOutCreateInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.TransferOutCreateInvenTrans(
|
||||
request.ModuleId,
|
||||
request.ProductId,
|
||||
request.Movement,
|
||||
request.CreatedById,
|
||||
cancellationToken);
|
||||
|
||||
return new TransferOutCreateInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.InventoryTransactionManager.Commands;
|
||||
|
||||
public class TransferOutDeleteInvenTransResult
|
||||
{
|
||||
public InventoryTransaction? Data { get; set; }
|
||||
}
|
||||
|
||||
public class TransferOutDeleteInvenTransRequest : IRequest<TransferOutDeleteInvenTransResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public class TransferOutDeleteInvenTransValidator : AbstractValidator<TransferOutDeleteInvenTransRequest>
|
||||
{
|
||||
public TransferOutDeleteInvenTransValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.DeletedById).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class TransferOutDeleteInvenTransHandler : IRequestHandler<TransferOutDeleteInvenTransRequest, TransferOutDeleteInvenTransResult>
|
||||
{
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public TransferOutDeleteInvenTransHandler(
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<TransferOutDeleteInvenTransResult> Handle(TransferOutDeleteInvenTransRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _inventoryTransactionService.TransferOutDeleteInvenTrans(
|
||||
request.Id,
|
||||
request.DeletedById,
|
||||
cancellationToken);
|
||||
|
||||
return new TransferOutDeleteInvenTransResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user