initial commit
This commit is contained in:
@@ -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.LeadContactManager.Queries;
|
||||
|
||||
public record GetLeadContactByLeadIdListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public string? FullName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? AddressStreet { get; init; }
|
||||
public string? AddressCity { get; init; }
|
||||
public string? AddressState { get; init; }
|
||||
public string? AddressZipCode { get; init; }
|
||||
public string? AddressCountry { get; init; }
|
||||
public string? PhoneNumber { get; init; }
|
||||
public string? FaxNumber { get; init; }
|
||||
public string? MobileNumber { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? Website { get; init; }
|
||||
public string? WhatsApp { get; init; }
|
||||
public string? LinkedIn { get; init; }
|
||||
public string? Facebook { get; init; }
|
||||
public string? Twitter { get; init; }
|
||||
public string? Instagram { get; init; }
|
||||
public string? AvatarName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadContactByLeadIdListProfile : Profile
|
||||
{
|
||||
public GetLeadContactByLeadIdListProfile()
|
||||
{
|
||||
CreateMap<LeadContact, GetLeadContactByLeadIdListDto>();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetLeadContactByLeadIdListResult
|
||||
{
|
||||
public List<GetLeadContactByLeadIdListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadContactByLeadIdListRequest : IRequest<GetLeadContactByLeadIdListResult>
|
||||
{
|
||||
public string? LeadId { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadContactByLeadIdListHandler : IRequestHandler<GetLeadContactByLeadIdListRequest, GetLeadContactByLeadIdListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetLeadContactByLeadIdListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLeadContactByLeadIdListResult> Handle(GetLeadContactByLeadIdListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.LeadContact
|
||||
.AsNoTracking()
|
||||
.IsDeletedEqualTo(false) // Assuming contacts aren't soft-deleted or this method filters out deleted contacts
|
||||
.Where(x => x.LeadId == request.LeadId)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetLeadContactByLeadIdListDto>>(entities);
|
||||
|
||||
return new GetLeadContactByLeadIdListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.LeadContactManager.Queries;
|
||||
|
||||
public record GetLeadContactListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public string? FullName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? AddressStreet { get; init; }
|
||||
public string? AddressCity { get; init; }
|
||||
public string? AddressState { get; init; }
|
||||
public string? AddressZipCode { get; init; }
|
||||
public string? AddressCountry { get; init; }
|
||||
public string? PhoneNumber { get; init; }
|
||||
public string? FaxNumber { get; init; }
|
||||
public string? MobileNumber { get; init; }
|
||||
public string? Email { get; init; }
|
||||
public string? Website { get; init; }
|
||||
public string? WhatsApp { get; init; }
|
||||
public string? LinkedIn { get; init; }
|
||||
public string? Facebook { get; init; }
|
||||
public string? Twitter { get; init; }
|
||||
public string? Instagram { get; init; }
|
||||
public string? AvatarName { get; init; }
|
||||
public string? LeadId { get; init; }
|
||||
public string? LeadTitle { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadContactListProfile : Profile
|
||||
{
|
||||
public GetLeadContactListProfile()
|
||||
{
|
||||
CreateMap<LeadContact, GetLeadContactListDto>()
|
||||
.ForMember(
|
||||
dest => dest.LeadTitle,
|
||||
opt => opt.MapFrom(src => src.Lead != null ? src.Lead.Title : string.Empty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class GetLeadContactListResult
|
||||
{
|
||||
public List<GetLeadContactListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadContactListRequest : IRequest<GetLeadContactListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
public class GetLeadContactListHandler : IRequestHandler<GetLeadContactListRequest, GetLeadContactListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetLeadContactListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLeadContactListResult> Handle(GetLeadContactListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.LeadContact
|
||||
.Include(x => x.Lead)
|
||||
.AsNoTracking()
|
||||
.IsDeletedEqualTo(request.IsDeleted)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetLeadContactListDto>>(entities);
|
||||
|
||||
return new GetLeadContactListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.LeadContactManager.Queries;
|
||||
|
||||
public class GetLeadContactSingleProfile : Profile
|
||||
{
|
||||
public GetLeadContactSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetLeadContactSingleResult
|
||||
{
|
||||
public LeadContact? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadContactSingleRequest : IRequest<GetLeadContactSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetLeadContactSingleValidator : AbstractValidator<GetLeadContactSingleRequest>
|
||||
{
|
||||
public GetLeadContactSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetLeadContactSingleHandler : IRequestHandler<GetLeadContactSingleRequest, GetLeadContactSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetLeadContactSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLeadContactSingleResult> Handle(GetLeadContactSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.LeadContact
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.AsQueryable();
|
||||
|
||||
var entity = await query.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
return new GetLeadContactSingleResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user