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.Thirdparty.VendorContact.Cqrs;
|
||||
|
||||
public class CreateVendorContactRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? JobTitle { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? VendorId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateVendorContactResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateVendorContactCommand(CreateVendorContactRequest Data) : IRequest<CreateVendorContactResponse>;
|
||||
|
||||
public class CreateVendorContactHandler : IRequestHandler<CreateVendorContactCommand, CreateVendorContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateVendorContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateVendorContactResponse> Handle(CreateVendorContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.VendorContact);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.VendorContact
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
Name = request.Data.Name,
|
||||
JobTitle = request.Data.JobTitle,
|
||||
PhoneNumber = request.Data.PhoneNumber,
|
||||
EmailAddress = request.Data.EmailAddress,
|
||||
Description = request.Data.Description,
|
||||
VendorId = request.Data.VendorId
|
||||
};
|
||||
|
||||
_context.VendorContact.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateVendorContactResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user