initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class CreateLeadActivityRequest
|
||||
{
|
||||
public string? LeadId { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? FromDate { get; set; }
|
||||
public DateTime? ToDate { get; set; }
|
||||
public Data.Enums.LeadActivityType Type { get; set; }
|
||||
}
|
||||
|
||||
public class CreateLeadActivityResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
|
||||
public record CreateLeadActivityCommand(CreateLeadActivityRequest Data) : IRequest<CreateLeadActivityResponse>;
|
||||
|
||||
public class CreateLeadActivityHandler : IRequestHandler<CreateLeadActivityCommand, CreateLeadActivityResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateLeadActivityHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateLeadActivityResponse> Handle(CreateLeadActivityCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.LeadActivity);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.LeadActivity
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
LeadId = request.Data.LeadId,
|
||||
Summary = request.Data.Summary,
|
||||
Description = request.Data.Description,
|
||||
FromDate = request.Data.FromDate,
|
||||
ToDate = request.Data.ToDate,
|
||||
Type = request.Data.Type
|
||||
};
|
||||
|
||||
_context.LeadActivity.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateLeadActivityResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Summary = entity.Summary
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class CreateLeadActivityValidator : AbstractValidator<CreateLeadActivityRequest>
|
||||
{
|
||||
public CreateLeadActivityValidator()
|
||||
{
|
||||
RuleFor(x => x.Summary)
|
||||
.NotEmpty().WithMessage("Summary is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.LeadId)
|
||||
.NotEmpty().WithMessage("Lead association is required");
|
||||
|
||||
RuleFor(x => x.FromDate)
|
||||
.NotEmpty().WithMessage("From Date is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public record DeleteLeadActivityByIdRequest(string Id);
|
||||
public record DeleteLeadActivityByIdCommand(DeleteLeadActivityByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteLeadActivityByIdHandler : IRequestHandler<DeleteLeadActivityByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteLeadActivityByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteLeadActivityByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadActivity
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.LeadActivity.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class GetLeadActivityByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? FromDate { get; set; }
|
||||
public DateTime? ToDate { get; set; }
|
||||
public Data.Enums.LeadActivityType Type { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadActivityByIdQuery(string Id) : IRequest<GetLeadActivityByIdResponse?>;
|
||||
|
||||
public class GetLeadActivityByIdHandler : IRequestHandler<GetLeadActivityByIdQuery, GetLeadActivityByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadActivityByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetLeadActivityByIdResponse?> Handle(GetLeadActivityByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.LeadActivity
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetLeadActivityByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
LeadId = x.LeadId,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Summary = x.Summary,
|
||||
Description = x.Description,
|
||||
FromDate = x.FromDate,
|
||||
ToDate = x.ToDate,
|
||||
Type = x.Type,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class GetLeadActivityListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public DateTime? FromDate { get; set; }
|
||||
public Data.Enums.LeadActivityType Type { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadActivityListQuery() : IRequest<List<GetLeadActivityListResponse>>;
|
||||
|
||||
public class GetLeadActivityListHandler : IRequestHandler<GetLeadActivityListQuery, List<GetLeadActivityListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadActivityListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetLeadActivityListResponse>> Handle(GetLeadActivityListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.LeadActivity
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.FromDate)
|
||||
.Select(x => new GetLeadActivityListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Summary = x.Summary,
|
||||
FromDate = x.FromDate,
|
||||
Type = x.Type
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class LeadActivityLookupResponse
|
||||
{
|
||||
public List<LookupItem> Leads { get; set; } = new();
|
||||
public List<LookupItem> ActivityTypes { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadActivityLookupQuery() : IRequest<LeadActivityLookupResponse>;
|
||||
|
||||
public class GetLeadActivityLookupHandler : IRequestHandler<GetLeadActivityLookupQuery, LeadActivityLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadActivityLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LeadActivityLookupResponse> Handle(GetLeadActivityLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new LeadActivityLookupResponse();
|
||||
|
||||
response.Leads = await _context.Lead.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Title }).ToListAsync(cancellationToken);
|
||||
|
||||
response.ActivityTypes = Enum.GetValues(typeof(LeadActivityType)).Cast<LeadActivityType>()
|
||||
.Select(x => new LookupItem { Value = (int)x, Name = x.ToString() }).ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class UpdateLeadActivityRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? FromDate { get; set; }
|
||||
public DateTime? ToDate { get; set; }
|
||||
public Data.Enums.LeadActivityType Type { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateLeadActivityResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateLeadActivityCommand(UpdateLeadActivityRequest Data) : IRequest<UpdateLeadActivityResponse>;
|
||||
|
||||
public class UpdateLeadActivityHandler : IRequestHandler<UpdateLeadActivityCommand, UpdateLeadActivityResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateLeadActivityHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateLeadActivityResponse> Handle(UpdateLeadActivityCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadActivity
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateLeadActivityResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.LeadId = request.Data.LeadId;
|
||||
entity.Summary = request.Data.Summary;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.FromDate = request.Data.FromDate;
|
||||
entity.ToDate = request.Data.ToDate;
|
||||
entity.Type = request.Data.Type;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateLeadActivityResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class UpdateLeadActivityValidator : AbstractValidator<UpdateLeadActivityRequest>
|
||||
{
|
||||
public UpdateLeadActivityValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
|
||||
RuleFor(x => x.Summary)
|
||||
.NotEmpty().WithMessage("Summary is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.LeadId)
|
||||
.NotEmpty().WithMessage("Lead association is required");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user