initial commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using Indotalent.Infrastructure.File;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class ChangeLeadContactAvatarRequest
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public byte[] FileData { get; set; } = Array.Empty<byte>();
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class ChangeLeadContactAvatarResponse
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public record ChangeLeadContactAvatarCommand(ChangeLeadContactAvatarRequest Data) : IRequest<ChangeLeadContactAvatarResponse>;
|
||||
|
||||
public class ChangeLeadContactAvatarHandler : IRequestHandler<ChangeLeadContactAvatarCommand, ChangeLeadContactAvatarResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
private readonly FileStorageService _fileStorage;
|
||||
|
||||
public ChangeLeadContactAvatarHandler(AppDbContext context, FileStorageService fileStorage)
|
||||
{
|
||||
_context = context;
|
||||
_fileStorage = fileStorage;
|
||||
}
|
||||
|
||||
public async Task<ChangeLeadContactAvatarResponse> Handle(ChangeLeadContactAvatarCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return new ChangeLeadContactAvatarResponse { IsSuccess = false, Message = "Lead Contact not found" };
|
||||
|
||||
try
|
||||
{
|
||||
var extension = Path.GetExtension(request.Data.FileName);
|
||||
|
||||
if (!string.IsNullOrEmpty(entity.AvatarName))
|
||||
{
|
||||
_fileStorage.DeleteOldAvatar(entity.AvatarName);
|
||||
}
|
||||
|
||||
var newFileName = await _fileStorage.SaveAvatarAsync(entity.Id, request.Data.FileData, extension);
|
||||
|
||||
entity.AvatarName = newFileName;
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new ChangeLeadContactAvatarResponse
|
||||
{
|
||||
IsSuccess = true,
|
||||
Message = "Lead Contact avatar updated successfully"
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ChangeLeadContactAvatarResponse { IsSuccess = false, Message = ex.Message };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class CreateLeadContactRequest
|
||||
{
|
||||
public string? LeadId { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? AddressStreet { get; set; }
|
||||
public string? AddressCity { get; set; }
|
||||
public string? AddressState { get; set; }
|
||||
public string? AddressZipCode { get; set; }
|
||||
public string? AddressCountry { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? MobileNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Twitter { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
}
|
||||
|
||||
public class CreateLeadContactResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
}
|
||||
|
||||
public record CreateLeadContactCommand(CreateLeadContactRequest Data) : IRequest<CreateLeadContactResponse>;
|
||||
|
||||
public class CreateLeadContactHandler : IRequestHandler<CreateLeadContactCommand, CreateLeadContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateLeadContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateLeadContactResponse> Handle(CreateLeadContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.LeadContact);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.LeadContact
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
LeadId = request.Data.LeadId,
|
||||
FullName = request.Data.FullName,
|
||||
Description = request.Data.Description,
|
||||
AddressStreet = request.Data.AddressStreet,
|
||||
AddressCity = request.Data.AddressCity,
|
||||
AddressState = request.Data.AddressState,
|
||||
AddressZipCode = request.Data.AddressZipCode,
|
||||
AddressCountry = request.Data.AddressCountry,
|
||||
PhoneNumber = request.Data.PhoneNumber,
|
||||
FaxNumber = request.Data.FaxNumber,
|
||||
MobileNumber = request.Data.MobileNumber,
|
||||
Email = request.Data.Email,
|
||||
Website = request.Data.Website,
|
||||
WhatsApp = request.Data.WhatsApp,
|
||||
LinkedIn = request.Data.LinkedIn,
|
||||
Facebook = request.Data.Facebook,
|
||||
Twitter = request.Data.Twitter,
|
||||
Instagram = request.Data.Instagram,
|
||||
AvatarName = request.Data.AvatarName
|
||||
};
|
||||
|
||||
_context.LeadContact.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateLeadContactResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
FullName = entity.FullName
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class CreateLeadContactValidator : AbstractValidator<CreateLeadContactRequest>
|
||||
{
|
||||
public CreateLeadContactValidator()
|
||||
{
|
||||
RuleFor(x => x.FullName)
|
||||
.NotEmpty().WithMessage("Full Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.Email))
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.LeadId)
|
||||
.NotEmpty().WithMessage("Lead association is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public record DeleteLeadContactByIdRequest(string Id);
|
||||
|
||||
public record DeleteLeadContactByIdCommand(DeleteLeadContactByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteLeadContactByIdHandler : IRequestHandler<DeleteLeadContactByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteLeadContactByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteLeadContactByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.LeadContact.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class GetLeadContactAvatarInfoResponse
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string? FullName { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadContactAvatarInfoQuery(string Id) : IRequest<GetLeadContactAvatarInfoResponse?>;
|
||||
|
||||
public class GetLeadContactAvatarInfoHandler : IRequestHandler<GetLeadContactAvatarInfoQuery, GetLeadContactAvatarInfoResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadContactAvatarInfoHandler(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLeadContactAvatarInfoResponse?> Handle(GetLeadContactAvatarInfoQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadContact
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return null;
|
||||
|
||||
return new GetLeadContactAvatarInfoResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
FullName = entity.FullName,
|
||||
AvatarName = entity.AvatarName
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class GetLeadContactByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? AddressStreet { get; set; }
|
||||
public string? AddressCity { get; set; }
|
||||
public string? AddressState { get; set; }
|
||||
public string? AddressZipCode { get; set; }
|
||||
public string? AddressCountry { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? MobileNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Twitter { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadContactByIdQuery(string Id) : IRequest<GetLeadContactByIdResponse?>;
|
||||
|
||||
public class GetLeadContactByIdHandler : IRequestHandler<GetLeadContactByIdQuery, GetLeadContactByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadContactByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetLeadContactByIdResponse?> Handle(GetLeadContactByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.LeadContact
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetLeadContactByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
LeadId = x.LeadId,
|
||||
AutoNumber = x.AutoNumber,
|
||||
FullName = x.FullName,
|
||||
Description = x.Description,
|
||||
AddressStreet = x.AddressStreet,
|
||||
AddressCity = x.AddressCity,
|
||||
AddressState = x.AddressState,
|
||||
AddressZipCode = x.AddressZipCode,
|
||||
AddressCountry = x.AddressCountry,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
FaxNumber = x.FaxNumber,
|
||||
MobileNumber = x.MobileNumber,
|
||||
Email = x.Email,
|
||||
Website = x.Website,
|
||||
WhatsApp = x.WhatsApp,
|
||||
LinkedIn = x.LinkedIn,
|
||||
Facebook = x.Facebook,
|
||||
Twitter = x.Twitter,
|
||||
Instagram = x.Instagram,
|
||||
AvatarName = x.AvatarName,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class GetLeadContactListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? MobileNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadContactListQuery() : IRequest<List<GetLeadContactListResponse>>;
|
||||
|
||||
public class GetLeadContactListHandler : IRequestHandler<GetLeadContactListQuery, List<GetLeadContactListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadContactListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetLeadContactListResponse>> Handle(GetLeadContactListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.LeadContact
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.FullName)
|
||||
.Select(x => new GetLeadContactListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
LeadId = x.LeadId,
|
||||
AutoNumber = x.AutoNumber,
|
||||
FullName = x.FullName,
|
||||
MobileNumber = x.MobileNumber,
|
||||
Email = x.Email,
|
||||
AvatarName = x.AvatarName,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class LeadContactLookupResponse
|
||||
{
|
||||
public List<LookupItem> Leads { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadContactLookupQuery() : IRequest<LeadContactLookupResponse>;
|
||||
|
||||
public class GetLeadContactLookupHandler : IRequestHandler<GetLeadContactLookupQuery, LeadContactLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadContactLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LeadContactLookupResponse> Handle(GetLeadContactLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new LeadContactLookupResponse();
|
||||
|
||||
response.Leads = await _context.Lead.AsNoTracking()
|
||||
.Select(x => new LookupItem
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Title
|
||||
}).ToListAsync(cancellationToken);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class UpdateLeadContactRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? AddressStreet { get; set; }
|
||||
public string? AddressCity { get; set; }
|
||||
public string? AddressState { get; set; }
|
||||
public string? AddressZipCode { get; set; }
|
||||
public string? AddressCountry { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? MobileNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Twitter { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateLeadContactResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateLeadContactCommand(UpdateLeadContactRequest Data) : IRequest<UpdateLeadContactResponse>;
|
||||
|
||||
public class UpdateLeadContactHandler : IRequestHandler<UpdateLeadContactCommand, UpdateLeadContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateLeadContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateLeadContactResponse> Handle(UpdateLeadContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateLeadContactResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.LeadId = request.Data.LeadId;
|
||||
entity.FullName = request.Data.FullName;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.AddressStreet = request.Data.AddressStreet;
|
||||
entity.AddressCity = request.Data.AddressCity;
|
||||
entity.AddressState = request.Data.AddressState;
|
||||
entity.AddressZipCode = request.Data.AddressZipCode;
|
||||
entity.AddressCountry = request.Data.AddressCountry;
|
||||
entity.PhoneNumber = request.Data.PhoneNumber;
|
||||
entity.FaxNumber = request.Data.FaxNumber;
|
||||
entity.MobileNumber = request.Data.MobileNumber;
|
||||
entity.Email = request.Data.Email;
|
||||
entity.Website = request.Data.Website;
|
||||
entity.WhatsApp = request.Data.WhatsApp;
|
||||
entity.LinkedIn = request.Data.LinkedIn;
|
||||
entity.Facebook = request.Data.Facebook;
|
||||
entity.Twitter = request.Data.Twitter;
|
||||
entity.Instagram = request.Data.Instagram;
|
||||
entity.AvatarName = request.Data.AvatarName;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateLeadContactResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class UpdateLeadContactValidator : AbstractValidator<UpdateLeadContactRequest>
|
||||
{
|
||||
public UpdateLeadContactValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required for update");
|
||||
|
||||
RuleFor(x => x.FullName)
|
||||
.NotEmpty().WithMessage("Full Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.Email))
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.LeadId)
|
||||
.NotEmpty().WithMessage("Lead association is required");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user