initial commit
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.LeadManager.Commands;
|
||||
|
||||
public class CreateLeadResult
|
||||
{
|
||||
public Lead? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateLeadRequest : IRequest<CreateLeadResult>
|
||||
{
|
||||
public string? Title { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public string? CompanyAddressStreet { get; init; }
|
||||
public string? CompanyAddressCity { get; init; }
|
||||
public string? CompanyAddressState { get; init; }
|
||||
public string? CompanyPhoneNumber { get; init; }
|
||||
public string? CompanyEmail { get; init; }
|
||||
public DateTime? DateProspecting { get; init; }
|
||||
public DateTime? DateClosingEstimation { get; init; }
|
||||
public DateTime? DateClosingActual { get; init; }
|
||||
public double? AmountTargeted { get; init; }
|
||||
public double? AmountClosed { get; init; }
|
||||
public double? BudgetScore { get; init; }
|
||||
public double? AuthorityScore { get; init; }
|
||||
public double? NeedScore { get; init; }
|
||||
public double? TimelineScore { get; init; }
|
||||
public string? PipelineStage { get; init; }
|
||||
public string? ClosingStatus { get; init; }
|
||||
public string? CampaignId { get; init; }
|
||||
public string? SalesTeamId { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateLeadValidator : AbstractValidator<CreateLeadRequest>
|
||||
{
|
||||
public CreateLeadValidator()
|
||||
{
|
||||
RuleFor(x => x.Title).NotEmpty();
|
||||
RuleFor(x => x.SalesTeamId).NotEmpty();
|
||||
RuleFor(x => x.CompanyName).NotEmpty();
|
||||
RuleFor(x => x.CompanyAddressStreet).NotEmpty();
|
||||
RuleFor(x => x.CompanyAddressCity).NotEmpty();
|
||||
RuleFor(x => x.CompanyAddressState).NotEmpty();
|
||||
RuleFor(x => x.CompanyPhoneNumber).NotEmpty();
|
||||
RuleFor(x => x.CompanyEmail).NotEmpty();
|
||||
RuleFor(x => x.DateProspecting).NotNull();
|
||||
RuleFor(x => x.DateClosingEstimation).NotNull();
|
||||
RuleFor(x => x.AmountTargeted).NotNull();
|
||||
RuleFor(x => x.AmountClosed).NotNull();
|
||||
RuleFor(x => x.BudgetScore).NotNull();
|
||||
RuleFor(x => x.AuthorityScore).NotNull();
|
||||
RuleFor(x => x.NeedScore).NotNull();
|
||||
RuleFor(x => x.TimelineScore).NotNull();
|
||||
RuleFor(x => x.PipelineStage).NotEmpty();
|
||||
RuleFor(x => x.CampaignId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateLeadHandler : IRequestHandler<CreateLeadRequest, CreateLeadResult>
|
||||
{
|
||||
private readonly ICommandRepository<Lead> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
|
||||
public CreateLeadHandler(
|
||||
ICommandRepository<Lead> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
}
|
||||
|
||||
public async Task<CreateLeadResult> Handle(CreateLeadRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new Lead
|
||||
{
|
||||
CreatedById = request.CreatedById,
|
||||
Number = _numberSequenceService.GenerateNumber(nameof(Lead), "", "LEA"),
|
||||
Title = request.Title,
|
||||
SalesTeamId = request.SalesTeamId,
|
||||
Description = request.Description,
|
||||
CompanyName = request.CompanyName,
|
||||
CompanyAddressStreet = request.CompanyAddressStreet,
|
||||
CompanyAddressCity = request.CompanyAddressCity,
|
||||
CompanyAddressState = request.CompanyAddressState,
|
||||
CompanyPhoneNumber = request.CompanyPhoneNumber,
|
||||
CompanyEmail = request.CompanyEmail,
|
||||
DateProspecting = request.DateProspecting,
|
||||
DateClosingEstimation = request.DateClosingEstimation,
|
||||
DateClosingActual = request.DateClosingActual,
|
||||
AmountTargeted = request.AmountTargeted,
|
||||
AmountClosed = request.AmountClosed,
|
||||
BudgetScore = request.BudgetScore,
|
||||
AuthorityScore = request.AuthorityScore,
|
||||
NeedScore = request.NeedScore,
|
||||
TimelineScore = request.TimelineScore,
|
||||
PipelineStage = (PipelineStage)int.Parse(request.PipelineStage!),
|
||||
CampaignId = request.CampaignId
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(request.ClosingStatus))
|
||||
{
|
||||
entity.ClosingStatus = (ClosingStatus)int.Parse(request.ClosingStatus!);
|
||||
}
|
||||
|
||||
await _repository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new CreateLeadResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.LeadManager.Commands;
|
||||
|
||||
public class DeleteLeadResult
|
||||
{
|
||||
public Lead? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteLeadRequest : IRequest<DeleteLeadResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteLeadValidator : AbstractValidator<DeleteLeadRequest>
|
||||
{
|
||||
public DeleteLeadValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteLeadHandler : IRequestHandler<DeleteLeadRequest, DeleteLeadResult>
|
||||
{
|
||||
private readonly ICommandRepository<Lead> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public DeleteLeadHandler(
|
||||
ICommandRepository<Lead> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<DeleteLeadResult> Handle(DeleteLeadRequest 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 DeleteLeadResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using Application.Common.Repositories;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.LeadManager.Commands;
|
||||
|
||||
public class UpdateLeadResult
|
||||
{
|
||||
public Lead? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateLeadRequest : IRequest<UpdateLeadResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Title { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public string? CompanyAddressStreet { get; init; }
|
||||
public string? CompanyAddressCity { get; init; }
|
||||
public string? CompanyAddressState { get; init; }
|
||||
public string? CompanyPhoneNumber { get; init; }
|
||||
public string? CompanyEmail { get; init; }
|
||||
public DateTime? DateProspecting { get; init; }
|
||||
public DateTime? DateClosingEstimation { get; init; }
|
||||
public DateTime? DateClosingActual { get; init; }
|
||||
public double? AmountTargeted { get; init; }
|
||||
public double? AmountClosed { get; init; }
|
||||
public double? BudgetScore { get; init; }
|
||||
public double? AuthorityScore { get; init; }
|
||||
public double? NeedScore { get; init; }
|
||||
public double? TimelineScore { get; init; }
|
||||
public string? PipelineStage { get; init; }
|
||||
public string? ClosingStatus { get; init; }
|
||||
public string? CampaignId { get; init; }
|
||||
public string? SalesTeamId { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateLeadValidator : AbstractValidator<UpdateLeadRequest>
|
||||
{
|
||||
public UpdateLeadValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Title).NotEmpty();
|
||||
RuleFor(x => x.SalesTeamId).NotEmpty();
|
||||
RuleFor(x => x.CompanyName).NotEmpty();
|
||||
RuleFor(x => x.CompanyAddressStreet).NotEmpty();
|
||||
RuleFor(x => x.CompanyAddressCity).NotEmpty();
|
||||
RuleFor(x => x.CompanyAddressState).NotEmpty();
|
||||
RuleFor(x => x.CompanyPhoneNumber).NotEmpty();
|
||||
RuleFor(x => x.CompanyEmail).NotEmpty();
|
||||
RuleFor(x => x.DateProspecting).NotNull();
|
||||
RuleFor(x => x.DateClosingEstimation).NotNull();
|
||||
RuleFor(x => x.AmountTargeted).NotNull();
|
||||
RuleFor(x => x.AmountClosed).NotNull();
|
||||
RuleFor(x => x.BudgetScore).NotNull();
|
||||
RuleFor(x => x.AuthorityScore).NotNull();
|
||||
RuleFor(x => x.NeedScore).NotNull();
|
||||
RuleFor(x => x.TimelineScore).NotNull();
|
||||
RuleFor(x => x.PipelineStage).NotEmpty();
|
||||
RuleFor(x => x.CampaignId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateLeadHandler : IRequestHandler<UpdateLeadRequest, UpdateLeadResult>
|
||||
{
|
||||
private readonly ICommandRepository<Lead> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateLeadHandler(
|
||||
ICommandRepository<Lead> repository,
|
||||
IUnitOfWork unitOfWork
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<UpdateLeadResult> Handle(UpdateLeadRequest 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.Title = request.Title;
|
||||
entity.SalesTeamId = request.SalesTeamId;
|
||||
entity.Description = request.Description;
|
||||
entity.CompanyName = request.CompanyName;
|
||||
entity.CompanyAddressStreet = request.CompanyAddressStreet;
|
||||
entity.CompanyAddressCity = request.CompanyAddressCity;
|
||||
entity.CompanyAddressState = request.CompanyAddressState;
|
||||
entity.CompanyPhoneNumber = request.CompanyPhoneNumber;
|
||||
entity.CompanyEmail = request.CompanyEmail;
|
||||
entity.DateProspecting = request.DateProspecting;
|
||||
entity.DateClosingEstimation = request.DateClosingEstimation;
|
||||
entity.DateClosingActual = request.DateClosingActual;
|
||||
entity.AmountTargeted = request.AmountTargeted;
|
||||
entity.AmountClosed = request.AmountClosed;
|
||||
entity.BudgetScore = request.BudgetScore;
|
||||
entity.AuthorityScore = request.AuthorityScore;
|
||||
entity.NeedScore = request.NeedScore;
|
||||
entity.TimelineScore = request.TimelineScore;
|
||||
entity.PipelineStage = (PipelineStage)int.Parse(request.PipelineStage!);
|
||||
entity.CampaignId = request.CampaignId;
|
||||
|
||||
if (!string.IsNullOrEmpty(request.ClosingStatus))
|
||||
{
|
||||
entity.ClosingStatus = (ClosingStatus)int.Parse(request.ClosingStatus!);
|
||||
}
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new UpdateLeadResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CampaignManager.Queries;
|
||||
|
||||
public record GetClosingStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetClosingStatusListProfile : Profile
|
||||
{
|
||||
public GetClosingStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetClosingStatusListResult
|
||||
{
|
||||
public List<GetClosingStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetClosingStatusListRequest : IRequest<GetClosingStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetClosingStatusListHandler : IRequestHandler<GetClosingStatusListRequest, GetClosingStatusListResult>
|
||||
{
|
||||
public GetClosingStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetClosingStatusListResult> Handle(GetClosingStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(ClosingStatus))
|
||||
.Cast<ClosingStatus>()
|
||||
.Select(status => new GetClosingStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetClosingStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.LeadManager.Queries;
|
||||
|
||||
public record GetLeadByCampaignIdListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public string? Title { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public string? CompanyAddressStreet { get; init; }
|
||||
public string? CompanyAddressCity { get; init; }
|
||||
public string? CompanyAddressState { get; init; }
|
||||
public string? CompanyPhoneNumber { get; init; }
|
||||
public string? CompanyEmail { get; init; }
|
||||
public DateTime? DateProspecting { get; init; }
|
||||
public DateTime? DateClosingEstimation { get; init; }
|
||||
public double? AmountTargeted { get; init; }
|
||||
public double? AmountClosed { get; init; }
|
||||
public double? BudgetScore { get; init; }
|
||||
public double? AuthorityScore { get; init; }
|
||||
public double? NeedScore { get; init; }
|
||||
public double? TimelineScore { get; init; }
|
||||
public string? PipelineStage { get; init; }
|
||||
public string? CampaignId { get; init; }
|
||||
public string? CampaignName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadByCampaignIdListProfile : Profile
|
||||
{
|
||||
public GetLeadByCampaignIdListProfile()
|
||||
{
|
||||
CreateMap<Lead, GetLeadByCampaignIdListDto>()
|
||||
.ForMember(
|
||||
dest => dest.CampaignName,
|
||||
opt => opt.MapFrom(src => src.Campaign != null ? src.Campaign.Title : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.PipelineStage,
|
||||
opt => opt.MapFrom(src => src.PipelineStage.HasValue ? src.PipelineStage.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class GetLeadByCampaignIdListResult
|
||||
{
|
||||
public List<GetLeadByCampaignIdListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadByCampaignIdListRequest : IRequest<GetLeadByCampaignIdListResult>
|
||||
{
|
||||
public string? CampaignId { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadByCampaignIdListHandler : IRequestHandler<GetLeadByCampaignIdListRequest, GetLeadByCampaignIdListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetLeadByCampaignIdListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLeadByCampaignIdListResult> Handle(GetLeadByCampaignIdListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Lead
|
||||
.AsNoTracking()
|
||||
.IsDeletedEqualTo(false)
|
||||
.Include(x => x.Campaign)
|
||||
.Where(x => x.CampaignId == request.CampaignId)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetLeadByCampaignIdListDto>>(entities);
|
||||
|
||||
return new GetLeadByCampaignIdListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
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.LeadManager.Queries;
|
||||
|
||||
public record GetLeadListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public string? Title { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public string? CompanyDescription { get; init; }
|
||||
public string? CompanyAddressStreet { get; init; }
|
||||
public string? CompanyAddressCity { get; init; }
|
||||
public string? CompanyAddressState { get; init; }
|
||||
public string? CompanyAddressZipCode { get; init; }
|
||||
public string? CompanyAddressCountry { get; init; }
|
||||
public string? CompanyPhoneNumber { get; init; }
|
||||
public string? CompanyFaxNumber { get; init; }
|
||||
public string? CompanyEmail { get; init; }
|
||||
public string? CompanyWebsite { get; init; }
|
||||
public string? CompanyWhatsApp { get; init; }
|
||||
public string? CompanyLinkedIn { get; init; }
|
||||
public string? CompanyFacebook { get; init; }
|
||||
public string? CompanyInstagram { get; init; }
|
||||
public string? CompanyTwitter { get; init; }
|
||||
public DateTime? DateProspecting { get; init; }
|
||||
public DateTime? DateClosingEstimation { get; init; }
|
||||
public DateTime? DateClosingActual { get; init; }
|
||||
public double? AmountTargeted { get; init; }
|
||||
public double? AmountClosed { get; init; }
|
||||
public double? BudgetScore { get; init; }
|
||||
public double? AuthorityScore { get; init; }
|
||||
public double? NeedScore { get; init; }
|
||||
public double? TimelineScore { get; init; }
|
||||
public PipelineStage? PipelineStage { get; init; }
|
||||
public string? PipelineStageName { get; init; }
|
||||
public ClosingStatus? ClosingStatus { get; init; }
|
||||
public string? ClosingStatusName { get; init; }
|
||||
public string? ClosingNote { get; init; }
|
||||
public string? CampaignId { get; init; }
|
||||
public Campaign? Campaign { get; init; }
|
||||
public string? CampaignName { get; init; }
|
||||
public string? SalesTeamId { get; init; }
|
||||
public string? SalesTeamName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadListProfile : Profile
|
||||
{
|
||||
public GetLeadListProfile()
|
||||
{
|
||||
CreateMap<Lead, GetLeadListDto>()
|
||||
.ForMember(
|
||||
dest => dest.CampaignName,
|
||||
opt => opt.MapFrom(src => src.Campaign != null ? src.Campaign.Title : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.PipelineStageName,
|
||||
opt => opt.MapFrom(src => src.PipelineStage.HasValue ? src.PipelineStage.Value.ToFriendlyName() : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.ClosingStatusName,
|
||||
opt => opt.MapFrom(src => src.ClosingStatus.HasValue ? src.ClosingStatus.Value.ToFriendlyName() : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.SalesTeamName,
|
||||
opt => opt.MapFrom(src => src.SalesTeam != null ? src.SalesTeam.Name : string.Empty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class GetLeadListResult
|
||||
{
|
||||
public List<GetLeadListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadListRequest : IRequest<GetLeadListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
public class GetLeadListHandler : IRequestHandler<GetLeadListRequest, GetLeadListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetLeadListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLeadListResult> Handle(GetLeadListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Lead
|
||||
.AsNoTracking()
|
||||
.IsDeletedEqualTo(request.IsDeleted)
|
||||
.Include(x => x.Campaign)
|
||||
.Include(x => x.SalesTeam)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetLeadListDto>>(entities);
|
||||
|
||||
return new GetLeadListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.LeadManager.Queries;
|
||||
|
||||
public class GetLeadSingleProfile : Profile
|
||||
{
|
||||
public GetLeadSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetLeadSingleResult
|
||||
{
|
||||
public Lead? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadSingleRequest : IRequest<GetLeadSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadSingleValidator : AbstractValidator<GetLeadSingleRequest>
|
||||
{
|
||||
public GetLeadSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetLeadSingleHandler : IRequestHandler<GetLeadSingleRequest, GetLeadSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetLeadSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLeadSingleResult> Handle(GetLeadSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.Lead
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Campaign)
|
||||
.Include(x => x.LeadContacts)
|
||||
.Include(x => x.LeadActivities)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.AsQueryable();
|
||||
|
||||
var entity = await query.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
return new GetLeadSingleResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.CampaignManager.Queries;
|
||||
|
||||
public record GetPipelineStageListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetPipelineStageListProfile : Profile
|
||||
{
|
||||
public GetPipelineStageListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPipelineStageListResult
|
||||
{
|
||||
public List<GetPipelineStageListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetPipelineStageListRequest : IRequest<GetPipelineStageListResult>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetPipelineStageListHandler : IRequestHandler<GetPipelineStageListRequest, GetPipelineStageListResult>
|
||||
{
|
||||
public GetPipelineStageListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetPipelineStageListResult> Handle(GetPipelineStageListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(PipelineStage))
|
||||
.Cast<PipelineStage>()
|
||||
.Select(status => new GetPipelineStageListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetPipelineStageListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user