Commit 89ab6587 authored by hasan khaddour's avatar hasan khaddour

add cqrs for cutomers domain

parent 86ff4de9
using PSManagement.SharedKernel.Entities;
using System;
namespace PSManagement.Application.Contracts.Authentication
{
public class User :BaseEntity
{
public String Email { get; set; }
public String LastName { get; set; }
public String FirstName { get; set; }
public String Password { get; set; }
public String Token { get; set; }
}
}
\ No newline at end of file
using FluentResults;
using PSManagement.Domain.Customers.Aggregate;
using PSManagement.Domain.Customers.ValueObjects;
using PSManagement.SharedKernel.CQRS.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
{
public record CreateCustomerCommand (
String CustomerName ,
Address Address
) : ICommand<Result<int>>;
}
using FluentResults;
using PSManagement.Domain.Customers.Aggregate;
using PSManagement.Domain.Customers.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
{
public class CreateCustomerCommandHandler : ICommandHandler<CreateCustomerCommand, Result<int>>
{
private readonly ICustomersRepository _customerRepository;
public CreateCustomerCommandHandler()
{
}
public async Task<Result<int>> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
{
Customer customer = new Customer(request.CustomerName ,request.Address);
await _customerRepository.AddAsync(customer);
return Result.Ok(customer.Id);
}
}
}
using PSManagement.SharedKernel.Repositories; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace PSManagement.Application.Contracts.Authentication namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
{ {
public interface IUsersRepository : IRepository<User> class CreateCustomerCommandValidator
{ {
public Task<User> GetByEmail(String email);
} }
} }
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
<Folder Include="Abstraction\" /> <Folder Include="Abstraction\" />
<Folder Include="Behaviors\AuthorizationBehavior\" /> <Folder Include="Behaviors\AuthorizationBehavior\" />
<Folder Include="Services\" /> <Folder Include="Services\" />
<Folder Include="UseCases\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
...@@ -18,6 +17,7 @@ ...@@ -18,6 +17,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\PSManagement.Domain\PSManagement.Domain.csproj" />
<ProjectReference Include="..\PSManagement.SharedKernel\PSManagement.SharedKernel.csproj" /> <ProjectReference Include="..\PSManagement.SharedKernel\PSManagement.SharedKernel.csproj" />
</ItemGroup> </ItemGroup>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment