initial commit
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.Data.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class CreateLeadRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CompanyDescription { get; set; }
|
||||
public string? CompanyAddressStreet { get; set; }
|
||||
public string? CompanyAddressCity { get; set; }
|
||||
public string? CompanyAddressState { get; set; }
|
||||
public string? CompanyAddressZipCode { get; set; }
|
||||
public string? CompanyAddressCountry { get; set; }
|
||||
public string? CompanyPhoneNumber { get; set; }
|
||||
public string? CompanyFaxNumber { get; set; }
|
||||
public string? CompanyEmail { get; set; }
|
||||
public string? CompanyWebsite { get; set; }
|
||||
public string? CompanyWhatsApp { get; set; }
|
||||
public string? CompanyLinkedIn { get; set; }
|
||||
public string? CompanyFacebook { get; set; }
|
||||
public string? CompanyInstagram { get; set; }
|
||||
public string? CompanyTwitter { get; set; }
|
||||
public DateTime? DateProspecting { get; set; } = DateTime.Today;
|
||||
public DateTime? DateClosingEstimation { get; set; }
|
||||
public DateTime? DateClosingActual { get; set; }
|
||||
public decimal? AmountTargeted { get; set; }
|
||||
public decimal? AmountClosed { get; set; }
|
||||
public decimal? BudgetScore { get; set; }
|
||||
public decimal? AuthorityScore { get; set; }
|
||||
public decimal? NeedScore { get; set; }
|
||||
public decimal? TimelineScore { get; set; }
|
||||
public PipelineStage PipelineStage { get; set; } = PipelineStage.Prospecting;
|
||||
public ClosingStatus ClosingStatus { get; set; } = ClosingStatus.ClosedWon;
|
||||
public string? ClosingNote { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateLeadResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Code { get; set; }
|
||||
}
|
||||
|
||||
public record CreateLeadCommand(CreateLeadRequest Data) : IRequest<CreateLeadResponse>;
|
||||
|
||||
public class CreateLeadHandler : IRequestHandler<CreateLeadCommand, CreateLeadResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateLeadHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateLeadResponse> Handle(CreateLeadCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.Lead);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Lead
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
Title = request.Data.Title,
|
||||
Description = request.Data.Description,
|
||||
CompanyName = request.Data.CompanyName,
|
||||
CompanyDescription = request.Data.CompanyDescription,
|
||||
CompanyAddressStreet = request.Data.CompanyAddressStreet,
|
||||
CompanyAddressCity = request.Data.CompanyAddressCity,
|
||||
CompanyAddressState = request.Data.CompanyAddressState,
|
||||
CompanyAddressZipCode = request.Data.CompanyAddressZipCode,
|
||||
CompanyAddressCountry = request.Data.CompanyAddressCountry,
|
||||
CompanyPhoneNumber = request.Data.CompanyPhoneNumber,
|
||||
CompanyFaxNumber = request.Data.CompanyFaxNumber,
|
||||
CompanyEmail = request.Data.CompanyEmail,
|
||||
CompanyWebsite = request.Data.CompanyWebsite,
|
||||
CompanyWhatsApp = request.Data.CompanyWhatsApp,
|
||||
CompanyLinkedIn = request.Data.CompanyLinkedIn,
|
||||
CompanyFacebook = request.Data.CompanyFacebook,
|
||||
CompanyInstagram = request.Data.CompanyInstagram,
|
||||
CompanyTwitter = request.Data.CompanyTwitter,
|
||||
DateProspecting = request.Data.DateProspecting,
|
||||
DateClosingEstimation = request.Data.DateClosingEstimation,
|
||||
DateClosingActual = request.Data.DateClosingActual,
|
||||
AmountTargeted = request.Data.AmountTargeted,
|
||||
AmountClosed = request.Data.AmountClosed,
|
||||
BudgetScore = request.Data.BudgetScore,
|
||||
AuthorityScore = request.Data.AuthorityScore,
|
||||
NeedScore = request.Data.NeedScore,
|
||||
TimelineScore = request.Data.TimelineScore,
|
||||
PipelineStage = request.Data.PipelineStage,
|
||||
ClosingStatus = request.Data.ClosingStatus,
|
||||
ClosingNote = request.Data.ClosingNote,
|
||||
CampaignId = request.Data.CampaignId,
|
||||
SalesTeamId = request.Data.SalesTeamId
|
||||
};
|
||||
|
||||
_context.Lead.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateLeadResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Code = entity.AutoNumber
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class CreateLeadValidator : AbstractValidator<CreateLeadRequest>
|
||||
{
|
||||
public CreateLeadValidator()
|
||||
{
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty().WithMessage("Lead Title is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.CompanyName)
|
||||
.NotEmpty().WithMessage("Company Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.CompanyEmail)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.CompanyEmail));
|
||||
|
||||
RuleFor(x => x.CampaignId)
|
||||
.NotEmpty().WithMessage("Campaign is required");
|
||||
|
||||
RuleFor(x => x.SalesTeamId)
|
||||
.NotEmpty().WithMessage("Sales Team is required");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CreateLeadRequest>.CreateWithOptions((CreateLeadRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid) return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public record DeleteLeadByIdRequest(string Id);
|
||||
|
||||
public record DeleteLeadByIdCommand(DeleteLeadByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteLeadByIdHandler : IRequestHandler<DeleteLeadByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteLeadByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteLeadByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Lead.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Lead.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class GetLeadByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CompanyDescription { get; set; }
|
||||
public string? CompanyAddressStreet { get; set; }
|
||||
public string? CompanyAddressCity { get; set; }
|
||||
public string? CompanyAddressState { get; set; }
|
||||
public string? CompanyAddressZipCode { get; set; }
|
||||
public string? CompanyAddressCountry { get; set; }
|
||||
public string? CompanyPhoneNumber { get; set; }
|
||||
public string? CompanyFaxNumber { get; set; }
|
||||
public string? CompanyEmail { get; set; }
|
||||
public string? CompanyWebsite { get; set; }
|
||||
public string? CompanyWhatsApp { get; set; }
|
||||
public string? CompanyLinkedIn { get; set; }
|
||||
public string? CompanyFacebook { get; set; }
|
||||
public string? CompanyInstagram { get; set; }
|
||||
public string? CompanyTwitter { get; set; }
|
||||
public DateTime? DateProspecting { get; set; }
|
||||
public DateTime? DateClosingEstimation { get; set; }
|
||||
public DateTime? DateClosingActual { get; set; }
|
||||
public decimal? AmountTargeted { get; set; }
|
||||
public decimal? AmountClosed { get; set; }
|
||||
public decimal? BudgetScore { get; set; }
|
||||
public decimal? AuthorityScore { get; set; }
|
||||
public decimal? NeedScore { get; set; }
|
||||
public decimal? TimelineScore { get; set; }
|
||||
public PipelineStage PipelineStage { get; set; }
|
||||
public ClosingStatus ClosingStatus { get; set; }
|
||||
public string? ClosingNote { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadByIdQuery(string Id) : IRequest<GetLeadByIdResponse?>;
|
||||
|
||||
public class GetLeadByIdHandler : IRequestHandler<GetLeadByIdQuery, GetLeadByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetLeadByIdResponse?> Handle(GetLeadByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Lead
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetLeadByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
Description = x.Description,
|
||||
CompanyName = x.CompanyName,
|
||||
CompanyDescription = x.CompanyDescription,
|
||||
CompanyAddressStreet = x.CompanyAddressStreet,
|
||||
CompanyAddressCity = x.CompanyAddressCity,
|
||||
CompanyAddressState = x.CompanyAddressState,
|
||||
CompanyAddressZipCode = x.CompanyAddressZipCode,
|
||||
CompanyAddressCountry = x.CompanyAddressCountry,
|
||||
CompanyPhoneNumber = x.CompanyPhoneNumber,
|
||||
CompanyFaxNumber = x.CompanyFaxNumber,
|
||||
CompanyEmail = x.CompanyEmail,
|
||||
CompanyWebsite = x.CompanyWebsite,
|
||||
CompanyWhatsApp = x.CompanyWhatsApp,
|
||||
CompanyLinkedIn = x.CompanyLinkedIn,
|
||||
CompanyFacebook = x.CompanyFacebook,
|
||||
CompanyInstagram = x.CompanyInstagram,
|
||||
CompanyTwitter = x.CompanyTwitter,
|
||||
DateProspecting = x.DateProspecting,
|
||||
DateClosingEstimation = x.DateClosingEstimation,
|
||||
DateClosingActual = x.DateClosingActual,
|
||||
AmountTargeted = x.AmountTargeted,
|
||||
AmountClosed = x.AmountClosed,
|
||||
BudgetScore = x.BudgetScore,
|
||||
AuthorityScore = x.AuthorityScore,
|
||||
NeedScore = x.NeedScore,
|
||||
TimelineScore = x.TimelineScore,
|
||||
PipelineStage = x.PipelineStage,
|
||||
ClosingStatus = x.ClosingStatus,
|
||||
ClosingNote = x.ClosingNote,
|
||||
CampaignId = x.CampaignId,
|
||||
SalesTeamId = x.SalesTeamId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class GetLeadListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CampaignTitle { get; set; }
|
||||
public string? SalesTeamName { get; set; }
|
||||
public PipelineStage PipelineStage { get; set; }
|
||||
public ClosingStatus ClosingStatus { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadListQuery() : IRequest<List<GetLeadListResponse>>;
|
||||
|
||||
public class GetLeadListHandler : IRequestHandler<GetLeadListQuery, List<GetLeadListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetLeadListResponse>> Handle(GetLeadListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Lead
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Campaign)
|
||||
.Include(x => x.SalesTeam)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetLeadListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
CompanyName = x.CompanyName,
|
||||
CampaignTitle = x.Campaign != null ? x.Campaign.Title : string.Empty,
|
||||
SalesTeamName = x.SalesTeam != null ? x.SalesTeam.Name : string.Empty,
|
||||
PipelineStage = x.PipelineStage,
|
||||
ClosingStatus = x.ClosingStatus
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class LeadLookupResponse
|
||||
{
|
||||
public List<LookupItem> Campaigns { get; set; } = new();
|
||||
public List<LookupItem> SalesTeams { get; set; } = new();
|
||||
public List<LookupItem> PipelineStages { get; set; } = new();
|
||||
public List<LookupItem> ClosingStatuses { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadLookupQuery() : IRequest<LeadLookupResponse>;
|
||||
|
||||
public class GetLeadLookupHandler : IRequestHandler<GetLeadLookupQuery, LeadLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LeadLookupResponse> Handle(GetLeadLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new LeadLookupResponse();
|
||||
|
||||
response.Campaigns = await _context.Campaign.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Title }).ToListAsync(cancellationToken);
|
||||
|
||||
response.SalesTeams = await _context.SalesTeam.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name }).ToListAsync(cancellationToken);
|
||||
|
||||
response.PipelineStages = Enum.GetValues(typeof(PipelineStage)).Cast<PipelineStage>()
|
||||
.Select(x => new LookupItem { Value = (int)x, Name = x.ToString() }).ToList();
|
||||
|
||||
response.ClosingStatuses = Enum.GetValues(typeof(ClosingStatus)).Cast<ClosingStatus>()
|
||||
.Select(x => new LookupItem { Value = (int)x, Name = x.ToString() }).ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class UpdateLeadRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CompanyDescription { get; set; }
|
||||
public string? CompanyAddressStreet { get; set; }
|
||||
public string? CompanyAddressCity { get; set; }
|
||||
public string? CompanyAddressState { get; set; }
|
||||
public string? CompanyAddressZipCode { get; set; }
|
||||
public string? CompanyAddressCountry { get; set; }
|
||||
public string? CompanyPhoneNumber { get; set; }
|
||||
public string? CompanyFaxNumber { get; set; }
|
||||
public string? CompanyEmail { get; set; }
|
||||
public string? CompanyWebsite { get; set; }
|
||||
public string? CompanyWhatsApp { get; set; }
|
||||
public string? CompanyLinkedIn { get; set; }
|
||||
public string? CompanyFacebook { get; set; }
|
||||
public string? CompanyInstagram { get; set; }
|
||||
public string? CompanyTwitter { get; set; }
|
||||
public DateTime? DateProspecting { get; set; }
|
||||
public DateTime? DateClosingEstimation { get; set; }
|
||||
public DateTime? DateClosingActual { get; set; }
|
||||
public decimal? AmountTargeted { get; set; }
|
||||
public decimal? AmountClosed { get; set; }
|
||||
public decimal? BudgetScore { get; set; }
|
||||
public decimal? AuthorityScore { get; set; }
|
||||
public decimal? NeedScore { get; set; }
|
||||
public decimal? TimelineScore { get; set; }
|
||||
public PipelineStage PipelineStage { get; set; }
|
||||
public ClosingStatus ClosingStatus { get; set; }
|
||||
public string? ClosingNote { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateLeadResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateLeadCommand(UpdateLeadRequest Data) : IRequest<UpdateLeadResponse>;
|
||||
|
||||
public class UpdateLeadHandler : IRequestHandler<UpdateLeadCommand, UpdateLeadResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateLeadHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateLeadResponse> Handle(UpdateLeadCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Lead
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return new UpdateLeadResponse { Id = request.Data.Id, Success = false };
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.CompanyName = request.Data.CompanyName;
|
||||
entity.CompanyDescription = request.Data.CompanyDescription;
|
||||
entity.CompanyAddressStreet = request.Data.CompanyAddressStreet;
|
||||
entity.CompanyAddressCity = request.Data.CompanyAddressCity;
|
||||
entity.CompanyAddressState = request.Data.CompanyAddressState;
|
||||
entity.CompanyAddressZipCode = request.Data.CompanyAddressZipCode;
|
||||
entity.CompanyAddressCountry = request.Data.CompanyAddressCountry;
|
||||
entity.CompanyPhoneNumber = request.Data.CompanyPhoneNumber;
|
||||
entity.CompanyFaxNumber = request.Data.CompanyFaxNumber;
|
||||
entity.CompanyEmail = request.Data.CompanyEmail;
|
||||
entity.CompanyWebsite = request.Data.CompanyWebsite;
|
||||
entity.CompanyWhatsApp = request.Data.CompanyWhatsApp;
|
||||
entity.CompanyLinkedIn = request.Data.CompanyLinkedIn;
|
||||
entity.CompanyFacebook = request.Data.CompanyFacebook;
|
||||
entity.CompanyInstagram = request.Data.CompanyInstagram;
|
||||
entity.CompanyTwitter = request.Data.CompanyTwitter;
|
||||
entity.DateProspecting = request.Data.DateProspecting;
|
||||
entity.DateClosingEstimation = request.Data.DateClosingEstimation;
|
||||
entity.DateClosingActual = request.Data.DateClosingActual;
|
||||
entity.AmountTargeted = request.Data.AmountTargeted;
|
||||
entity.AmountClosed = request.Data.AmountClosed;
|
||||
entity.BudgetScore = request.Data.BudgetScore;
|
||||
entity.AuthorityScore = request.Data.AuthorityScore;
|
||||
entity.NeedScore = request.Data.NeedScore;
|
||||
entity.TimelineScore = request.Data.TimelineScore;
|
||||
entity.PipelineStage = request.Data.PipelineStage;
|
||||
entity.ClosingStatus = request.Data.ClosingStatus;
|
||||
entity.ClosingNote = request.Data.ClosingNote;
|
||||
entity.CampaignId = request.Data.CampaignId;
|
||||
entity.SalesTeamId = request.Data.SalesTeamId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateLeadResponse { Id = entity.Id, Success = true };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class UpdateLeadValidator : AbstractValidator<UpdateLeadRequest>
|
||||
{
|
||||
public UpdateLeadValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
|
||||
RuleFor(x => x.CompanyName).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
|
||||
RuleFor(x => x.CampaignId).NotEmpty();
|
||||
RuleFor(x => x.SalesTeamId).NotEmpty();
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdateLeadRequest>.CreateWithOptions((UpdateLeadRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid) return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user