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.Customer.Cqrs;
|
||||
|
||||
public class CreateCustomerContactRequest
|
||||
{
|
||||
public string? CustomerId { 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 CreateCustomerContactResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateCustomerContactCommand(CreateCustomerContactRequest Data) : IRequest<CreateCustomerContactResponse>;
|
||||
|
||||
public class CreateCustomerContactHandler : IRequestHandler<CreateCustomerContactCommand, CreateCustomerContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateCustomerContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateCustomerContactResponse> Handle(CreateCustomerContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.CustomerContact);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.CustomerContact
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
CustomerId = request.Data.CustomerId,
|
||||
Name = request.Data.Name,
|
||||
JobTitle = request.Data.JobTitle,
|
||||
PhoneNumber = request.Data.PhoneNumber,
|
||||
EmailAddress = request.Data.EmailAddress,
|
||||
Description = request.Data.Description
|
||||
};
|
||||
|
||||
_context.CustomerContact.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateCustomerContactResponse
|
||||
{
|
||||
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.Customer.Cqrs;
|
||||
|
||||
public class CreateCustomerRequest
|
||||
{
|
||||
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? CustomerGroupId { get; set; }
|
||||
public string? CustomerCategoryId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateCustomerResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateCustomerCommand(CreateCustomerRequest Data) : IRequest<CreateCustomerResponse>;
|
||||
|
||||
public class CreateCustomerHandler : IRequestHandler<CreateCustomerCommand, CreateCustomerResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateCustomerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateCustomerResponse> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isExists = await _context.Customer
|
||||
.AnyAsync(x => x.Name == request.Data.Name, cancellationToken);
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
throw new AlreadyExistsException("Customer", request.Data.Name ?? string.Empty);
|
||||
}
|
||||
|
||||
var entityName = nameof(Data.Entities.Customer);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Customer
|
||||
{
|
||||
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,
|
||||
CustomerGroupId = request.Data.CustomerGroupId,
|
||||
CustomerCategoryId = request.Data.CustomerCategoryId
|
||||
};
|
||||
|
||||
_context.Customer.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateCustomerResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Customer.Cqrs;
|
||||
|
||||
public class CreateCustomerValidator : AbstractValidator<CreateCustomerRequest>
|
||||
{
|
||||
public CreateCustomerValidator()
|
||||
{
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Customer Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.EmailAddress)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
|
||||
|
||||
RuleFor(x => x.CustomerGroupId)
|
||||
.NotEmpty().WithMessage("Customer Group is required");
|
||||
|
||||
RuleFor(x => x.CustomerCategoryId)
|
||||
.NotEmpty().WithMessage("Customer Category is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Customer.Cqrs;
|
||||
|
||||
public record DeleteCustomerByIdRequest(string Id);
|
||||
|
||||
public record DeleteCustomerByIdCommand(DeleteCustomerByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteCustomerByIdHandler : IRequestHandler<DeleteCustomerByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteCustomerByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteCustomerByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Customer
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Customer.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.Customer.Cqrs;
|
||||
|
||||
public record DeleteCustomerContactCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteCustomerContactHandler : IRequestHandler<DeleteCustomerContactCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteCustomerContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteCustomerContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.CustomerContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_context.CustomerContact.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.Customer.Cqrs;
|
||||
|
||||
public class CustomerContactItemResponse
|
||||
{
|
||||
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 GetCustomerByIdResponse
|
||||
{
|
||||
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? CustomerGroupId { get; set; }
|
||||
public string? CustomerCategoryId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
public List<CustomerContactItemResponse> Contacts { get; set; } = new();
|
||||
}
|
||||
|
||||
public record GetCustomerByIdQuery(string Id) : IRequest<GetCustomerByIdResponse?>;
|
||||
|
||||
public class GetCustomerByIdHandler : IRequestHandler<GetCustomerByIdQuery, GetCustomerByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetCustomerByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetCustomerByIdResponse?> Handle(GetCustomerByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Customer
|
||||
.AsNoTracking()
|
||||
.Include(x => x.CustomerContactList)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetCustomerByIdResponse
|
||||
{
|
||||
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,
|
||||
CustomerGroupId = x.CustomerGroupId,
|
||||
CustomerCategoryId = x.CustomerCategoryId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy,
|
||||
Contacts = x.CustomerContactList
|
||||
.OrderBy(c => c.Name)
|
||||
.Select(c => new CustomerContactItemResponse
|
||||
{
|
||||
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.Customer.Cqrs;
|
||||
|
||||
public class GetCustomerListResponse
|
||||
{
|
||||
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? CustomerGroupName { get; set; }
|
||||
public string? CustomerCategoryName { get; set; }
|
||||
}
|
||||
|
||||
public record GetCustomerListQuery() : IRequest<List<GetCustomerListResponse>>;
|
||||
|
||||
public class GetCustomerListHandler : IRequestHandler<GetCustomerListQuery, List<GetCustomerListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetCustomerListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetCustomerListResponse>> Handle(GetCustomerListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Customer
|
||||
.AsNoTracking()
|
||||
.Include(x => x.CustomerGroup)
|
||||
.Include(x => x.CustomerCategory)
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new GetCustomerListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Name = x.Name,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
EmailAddress = x.EmailAddress,
|
||||
CustomerGroupName = x.CustomerGroup != null ? x.CustomerGroup.Name : string.Empty,
|
||||
CustomerCategoryName = x.CustomerCategory != null ? x.CustomerCategory.Name : string.Empty
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Customer.Cqrs;
|
||||
|
||||
public class LookupCustomerResponse
|
||||
{
|
||||
public List<LookupItem> CustomerGroups { get; set; } = new();
|
||||
public List<LookupItem> CustomerCategories { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record LookupCustomerQuery() : IRequest<LookupCustomerResponse>;
|
||||
|
||||
public class LookupCustomerHandler : IRequestHandler<LookupCustomerQuery, LookupCustomerResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public LookupCustomerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LookupCustomerResponse> Handle(LookupCustomerQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new LookupCustomerResponse();
|
||||
|
||||
result.CustomerGroups = await _context.CustomerGroup
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
result.CustomerCategories = await _context.CustomerCategory
|
||||
.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.Customer.Cqrs;
|
||||
|
||||
public class UpdateCustomerContactRequest
|
||||
{
|
||||
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 UpdateCustomerContactResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateCustomerContactCommand(UpdateCustomerContactRequest Data) : IRequest<UpdateCustomerContactResponse>;
|
||||
|
||||
public class UpdateCustomerContactHandler : IRequestHandler<UpdateCustomerContactCommand, UpdateCustomerContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateCustomerContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateCustomerContactResponse> Handle(UpdateCustomerContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.CustomerContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateCustomerContactResponse
|
||||
{
|
||||
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 UpdateCustomerContactResponse
|
||||
{
|
||||
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.Customer.Cqrs;
|
||||
|
||||
public class UpdateCustomerRequest
|
||||
{
|
||||
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? CustomerGroupId { get; set; }
|
||||
public string? CustomerCategoryId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateCustomerResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateCustomerCommand(UpdateCustomerRequest Data) : IRequest<UpdateCustomerResponse>;
|
||||
|
||||
public class UpdateCustomerHandler : IRequestHandler<UpdateCustomerCommand, UpdateCustomerResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateCustomerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateCustomerResponse> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isExists = await _context.Customer
|
||||
.AnyAsync(x => x.Name == request.Data.Name && x.Id != request.Data.Id, cancellationToken);
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
throw new AlreadyExistsException("Customer", request.Data.Name ?? string.Empty);
|
||||
}
|
||||
|
||||
var entity = await _context.Customer
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateCustomerResponse { 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.CustomerGroupId = request.Data.CustomerGroupId;
|
||||
entity.CustomerCategoryId = request.Data.CustomerCategoryId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateCustomerResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.Customer.Cqrs;
|
||||
|
||||
public class UpdateCustomerValidator : AbstractValidator<UpdateCustomerRequest>
|
||||
{
|
||||
public UpdateCustomerValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required for update");
|
||||
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Customer Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.EmailAddress)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
|
||||
|
||||
RuleFor(x => x.CustomerGroupId)
|
||||
.NotEmpty().WithMessage("Customer Group is required");
|
||||
|
||||
RuleFor(x => x.CustomerCategoryId)
|
||||
.NotEmpty().WithMessage("Customer Category is required");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user