initial commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class CreateVendorContactRequest
|
||||
{
|
||||
public string? VendorId { get; set; }
|
||||
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 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,
|
||||
VendorId = request.Data.VendorId,
|
||||
Name = request.Data.Name,
|
||||
JobTitle = request.Data.JobTitle,
|
||||
PhoneNumber = request.Data.PhoneNumber,
|
||||
EmailAddress = request.Data.EmailAddress,
|
||||
Description = request.Data.Description
|
||||
};
|
||||
|
||||
_context.VendorContact.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateVendorContactResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class CreateVendorRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Street { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? State { get; set; }
|
||||
public string? ZipCode { get; set; }
|
||||
public string? Country { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? TwitterX { get; set; }
|
||||
public string? TikTok { get; set; }
|
||||
public string? VendorGroupId { get; set; }
|
||||
public string? VendorCategoryId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateVendorResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateVendorCommand(CreateVendorRequest Data) : IRequest<CreateVendorResponse>;
|
||||
|
||||
public class CreateVendorHandler : IRequestHandler<CreateVendorCommand, CreateVendorResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateVendorHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateVendorResponse> Handle(CreateVendorCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isExists = await _context.Vendor
|
||||
.AnyAsync(x => x.Name == request.Data.Name, cancellationToken);
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
throw new AlreadyExistsException("Vendor", request.Data.Name ?? string.Empty);
|
||||
}
|
||||
|
||||
var entityName = nameof(Data.Entities.Vendor);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Vendor
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
Name = request.Data.Name,
|
||||
Description = request.Data.Description,
|
||||
Street = request.Data.Street,
|
||||
City = request.Data.City,
|
||||
State = request.Data.State,
|
||||
ZipCode = request.Data.ZipCode,
|
||||
Country = request.Data.Country,
|
||||
PhoneNumber = request.Data.PhoneNumber,
|
||||
FaxNumber = request.Data.FaxNumber,
|
||||
EmailAddress = request.Data.EmailAddress,
|
||||
Website = request.Data.Website,
|
||||
WhatsApp = request.Data.WhatsApp,
|
||||
LinkedIn = request.Data.LinkedIn,
|
||||
Facebook = request.Data.Facebook,
|
||||
Instagram = request.Data.Instagram,
|
||||
TwitterX = request.Data.TwitterX,
|
||||
TikTok = request.Data.TikTok,
|
||||
VendorGroupId = request.Data.VendorGroupId,
|
||||
VendorCategoryId = request.Data.VendorCategoryId
|
||||
};
|
||||
|
||||
_context.Vendor.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateVendorResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class CreateVendorValidator : AbstractValidator<CreateVendorRequest>
|
||||
{
|
||||
public CreateVendorValidator()
|
||||
{
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Vendor Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.VendorGroupId)
|
||||
.NotEmpty().WithMessage("Vendor Group is required");
|
||||
|
||||
RuleFor(x => x.VendorCategoryId)
|
||||
.NotEmpty().WithMessage("Vendor Category is required");
|
||||
|
||||
RuleFor(x => x.EmailAddress)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public record DeleteVendorByIdRequest(string Id);
|
||||
|
||||
public record DeleteVendorByIdCommand(DeleteVendorByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteVendorByIdHandler : IRequestHandler<DeleteVendorByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteVendorByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteVendorByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Vendor
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Vendor.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public record DeleteVendorContactCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteVendorContactHandler : IRequestHandler<DeleteVendorContactCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteVendorContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteVendorContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.VendorContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_context.VendorContact.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class VendorContactItemResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? JobTitle { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public class GetVendorByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Street { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? State { get; set; }
|
||||
public string? ZipCode { get; set; }
|
||||
public string? Country { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? TwitterX { get; set; }
|
||||
public string? TikTok { get; set; }
|
||||
public string? VendorGroupId { get; set; }
|
||||
public string? VendorCategoryId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
public List<VendorContactItemResponse> Contacts { get; set; } = new();
|
||||
}
|
||||
|
||||
public record GetVendorByIdQuery(string Id) : IRequest<GetVendorByIdResponse?>;
|
||||
|
||||
public class GetVendorByIdHandler : IRequestHandler<GetVendorByIdQuery, GetVendorByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetVendorByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetVendorByIdResponse?> Handle(GetVendorByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Vendor
|
||||
.AsNoTracking()
|
||||
.Include(x => x.VendorContactList)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetVendorByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
Street = x.Street,
|
||||
City = x.City,
|
||||
State = x.State,
|
||||
ZipCode = x.ZipCode,
|
||||
Country = x.Country,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
FaxNumber = x.FaxNumber,
|
||||
EmailAddress = x.EmailAddress,
|
||||
Website = x.Website,
|
||||
WhatsApp = x.WhatsApp,
|
||||
LinkedIn = x.LinkedIn,
|
||||
Facebook = x.Facebook,
|
||||
Instagram = x.Instagram,
|
||||
TwitterX = x.TwitterX,
|
||||
TikTok = x.TikTok,
|
||||
VendorGroupId = x.VendorGroupId,
|
||||
VendorCategoryId = x.VendorCategoryId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy,
|
||||
Contacts = x.VendorContactList
|
||||
.OrderBy(c => c.Name)
|
||||
.Select(c => new VendorContactItemResponse
|
||||
{
|
||||
Id = c.Id,
|
||||
Name = c.Name,
|
||||
AutoNumber = c.AutoNumber,
|
||||
JobTitle = c.JobTitle,
|
||||
PhoneNumber = c.PhoneNumber,
|
||||
EmailAddress = c.EmailAddress,
|
||||
Description = c.Description
|
||||
}).ToList()
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class GetVendorListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? VendorGroupName { get; set; }
|
||||
public string? VendorCategoryName { get; set; }
|
||||
}
|
||||
|
||||
public record GetVendorListQuery() : IRequest<List<GetVendorListResponse>>;
|
||||
|
||||
public class GetVendorListHandler : IRequestHandler<GetVendorListQuery, List<GetVendorListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetVendorListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetVendorListResponse>> Handle(GetVendorListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Vendor
|
||||
.AsNoTracking()
|
||||
.Include(x => x.VendorGroup)
|
||||
.Include(x => x.VendorCategory)
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new GetVendorListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Name = x.Name,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
EmailAddress = x.EmailAddress,
|
||||
VendorGroupName = x.VendorGroup != null ? x.VendorGroup.Name : string.Empty,
|
||||
VendorCategoryName = x.VendorCategory != null ? x.VendorCategory.Name : string.Empty
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class LookupVendorResponse
|
||||
{
|
||||
public List<LookupItem> VendorGroups { get; set; } = new();
|
||||
public List<LookupItem> VendorCategories { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record LookupVendorQuery() : IRequest<LookupVendorResponse>;
|
||||
|
||||
public class LookupVendorHandler : IRequestHandler<LookupVendorQuery, LookupVendorResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public LookupVendorHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LookupVendorResponse> Handle(LookupVendorQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new LookupVendorResponse();
|
||||
|
||||
result.VendorGroups = await _context.VendorGroup
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
result.VendorCategories = await _context.VendorCategory
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class UpdateVendorContactRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
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 class UpdateVendorContactResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateVendorContactCommand(UpdateVendorContactRequest Data) : IRequest<UpdateVendorContactResponse>;
|
||||
|
||||
public class UpdateVendorContactHandler : IRequestHandler<UpdateVendorContactCommand, UpdateVendorContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateVendorContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateVendorContactResponse> Handle(UpdateVendorContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.VendorContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateVendorContactResponse
|
||||
{
|
||||
Id = request.Data.Id,
|
||||
Success = false
|
||||
};
|
||||
}
|
||||
|
||||
entity.Name = request.Data.Name;
|
||||
entity.JobTitle = request.Data.JobTitle;
|
||||
entity.PhoneNumber = request.Data.PhoneNumber;
|
||||
entity.EmailAddress = request.Data.EmailAddress;
|
||||
entity.Description = request.Data.Description;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateVendorContactResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class UpdateVendorRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Street { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? State { get; set; }
|
||||
public string? ZipCode { get; set; }
|
||||
public string? Country { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? TwitterX { get; set; }
|
||||
public string? TikTok { get; set; }
|
||||
public string? VendorGroupId { get; set; }
|
||||
public string? VendorCategoryId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateVendorResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateVendorCommand(UpdateVendorRequest Data) : IRequest<UpdateVendorResponse>;
|
||||
|
||||
public class UpdateVendorHandler : IRequestHandler<UpdateVendorCommand, UpdateVendorResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateVendorHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateVendorResponse> Handle(UpdateVendorCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isExists = await _context.Vendor
|
||||
.AnyAsync(x => x.Name == request.Data.Name && x.Id != request.Data.Id, cancellationToken);
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
throw new AlreadyExistsException("Vendor", request.Data.Name ?? string.Empty);
|
||||
}
|
||||
|
||||
var entity = await _context.Vendor
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateVendorResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Name = request.Data.Name;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.Street = request.Data.Street;
|
||||
entity.City = request.Data.City;
|
||||
entity.State = request.Data.State;
|
||||
entity.ZipCode = request.Data.ZipCode;
|
||||
entity.Country = request.Data.Country;
|
||||
entity.PhoneNumber = request.Data.PhoneNumber;
|
||||
entity.FaxNumber = request.Data.FaxNumber;
|
||||
entity.EmailAddress = request.Data.EmailAddress;
|
||||
entity.Website = request.Data.Website;
|
||||
entity.WhatsApp = request.Data.WhatsApp;
|
||||
entity.LinkedIn = request.Data.LinkedIn;
|
||||
entity.Facebook = request.Data.Facebook;
|
||||
entity.Instagram = request.Data.Instagram;
|
||||
entity.TwitterX = request.Data.TwitterX;
|
||||
entity.TikTok = request.Data.TikTok;
|
||||
entity.VendorGroupId = request.Data.VendorGroupId;
|
||||
entity.VendorCategoryId = request.Data.VendorCategoryId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateVendorResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Vendor.Cqrs;
|
||||
|
||||
public class UpdateVendorValidator : AbstractValidator<UpdateVendorRequest>
|
||||
{
|
||||
public UpdateVendorValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required for update");
|
||||
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Vendor Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.VendorGroupId)
|
||||
.NotEmpty().WithMessage("Vendor Group is required");
|
||||
|
||||
RuleFor(x => x.VendorCategoryId)
|
||||
.NotEmpty().WithMessage("Vendor Category is required");
|
||||
|
||||
RuleFor(x => x.EmailAddress)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user