Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
ProjectsStatusManagement
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
ProjectsStatusManagement
Commits
5e219566
Commit
5e219566
authored
Aug 11, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor result pattern
parent
69af1fba
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
157 additions
and
77 deletions
+157
-77
CustomerMapperConfiguration.cs
...ion/ApplicationDTOsMappers/CustomerMapperConfiguration.cs
+0
-1
ValidationBehavior.cs
...cation/Behaviors/ValidationBehavior/ValidationBehavior.cs
+33
-12
IAuthenticationService.cs
...cation/Contracts/Authentication/IAuthenticationService.cs
+1
-1
IRoleService.cs
...ement.Application/Contracts/Authorization/IRoleService.cs
+1
-1
IUserRoleService.cs
...t.Application/Contracts/Authorization/IUserRoleService.cs
+4
-5
IDepartmentsProvider.cs
...t.Application/Contracts/Providers/IDepartmentsProvider.cs
+2
-1
IEmployeesProvider.cs
...ent.Application/Contracts/Providers/IEmployeesProvider.cs
+1
-1
IFileService.cs
PSManagement.Application/Contracts/Storage/IFileService.cs
+1
-1
ISyncDepartmentsService.cs
...Application/Contracts/SyncData/ISyncDepartmentsService.cs
+10
-0
ISyncEmployeesService.cs
...t.Application/Contracts/SyncData/ISyncEmployeesService.cs
+5
-5
IJwtTokenGenerator.cs
...gement.Application/Contracts/Tokens/IJwtTokenGenerator.cs
+2
-2
CustomerCreatedEventHandler.cs
...plication/Customers/Events/CustomerCreatedEventHandler.cs
+3
-2
AddContactInfoCommand.cs
...UseCases/Commands/AddContactInfo/AddContactInfoCommand.cs
+5
-2
AddContactInfoCommandHandler.cs
...s/Commands/AddContactInfo/AddContactInfoCommandHandler.cs
+3
-4
CreateCustomerCommand.cs
...UseCases/Commands/CreateCustomer/CreateCustomerCommand.cs
+1
-3
CreateCustomerCommandHandler.cs
...s/Commands/CreateCustomer/CreateCustomerCommandHandler.cs
+4
-4
DeleteCustomerCommand.cs
...UseCases/Commands/DeleteCustomer/DeleteCustomerCommand.cs
+2
-1
DeleteCustomerCommandHandler.cs
...s/Commands/DeleteCustomer/DeleteCustomerCommandHandler.cs
+4
-4
UpdateCustomerCommand.cs
...UseCases/Commands/UpdateCustomer/UpdateCustomerCommand.cs
+1
-3
UpdateCustomerCommandHandler.cs
...s/Commands/UpdateCustomer/UpdateCustomerCommandHandler.cs
+5
-4
GetCustomerQuery.cs
...ustomers/UseCases/Queries/GetCustomer/GetCustomerQuery.cs
+1
-1
GetCustomerQueryHandler.cs
...s/UseCases/Queries/GetCustomer/GetCustomerQueryHandler.cs
+5
-5
ListAllCustomersQuery.cs
...seCases/Queries/ListAllCustomers/ListAllCustomersQuery.cs
+1
-1
ListAllCustomersQueryHandler.cs
.../Queries/ListAllCustomers/ListAllCustomersQueryHandler.cs
+3
-3
PSManagement.Application.csproj
PSManagement.Application/PSManagement.Application.csproj
+3
-0
CreateProjectCommand.cs
...s/UseCases/Commands/CreateProject/CreateProjectCommand.cs
+5
-4
CreateProjectCommandHandler.cs
...ses/Commands/CreateProject/CreateProjectCommandHandler.cs
+37
-6
CreateProjectResponse.cs
.../UseCases/Commands/CreateProject/CreateProjectResponse.cs
+14
-0
No files found.
PSManagement.Application/ApplicationDTOsMappers/CustomerMapperConfiguration.cs
View file @
5e219566
using
AutoMapper
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.Entities
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
System
;
...
...
PSManagement.Application/Behaviors/ValidationBehavior/ValidationBehavior.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
FluentValidation
;
using
MediatR
;
...
...
@@ -13,7 +13,7 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
{
public
class
ValidationBehavior
<
TRequest
,
TResponse
>
:
IPipelineBehavior
<
TRequest
,
TResponse
>
where
TRequest
:
IRequest
<
TResponse
>
where
TResponse
:
ResultBase
where
TRequest
:
IRequest
<
TResponse
>
{
private
readonly
IEnumerable
<
IValidator
<
TRequest
>>
_validators
;
...
...
@@ -23,29 +23,50 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
}
public
async
Task
<
TResponse
>
Handle
(
TRequest
request
,
CancellationToken
cancellationToken
,
RequestHandlerDelegate
<
TResponse
>
next
)
{
var
context
=
new
ValidationContext
<
TRequest
>(
request
);
{
if
(
_validators
is
null
)
{
return
await
next
();
}
var
validationTasks
=
_validators
.
Select
(
v
=>
v
.
ValidateAsync
(
request
,
cancellationToken
));
var
validationResults
=
await
Task
.
WhenAll
(
validationTasks
);
var
errors
=
validationResults
.
SelectMany
(
r
=>
r
.
Errors
)
.
Where
(
e
=>
e
!=
null
)
.
Select
(
e
=>
new
ValidationError
(
e
.
ErrorCode
,
e
.
ErrorMessage
,
e
.
ErrorCode
,
new
ValidationSeverity
()))
.
ToList
();
if
(
errors
.
Any
())
{
return
(
dynamic
)
Result
.
Invalid
(
errors
);
}
return
await
next
();
}
private
Result
ValidateAsync
(
TRequest
request
)
{
var
context
=
new
ValidationContext
<
TRequest
>(
request
);
var
failures
=
_validators
.
Select
(
v
=>
v
.
Validate
(
context
))
.
SelectMany
(
result
=>
result
.
Errors
)
.
Where
(
f
=>
f
!=
null
)
.
ToList
();
if
(
failures
.
Count
!=
0
)
{
var
result
=
Result
.
Fail
(
"validation Error."
);
foreach
(
var
failure
in
failures
)
{
result
.
Reasons
.
Add
(
new
Error
(
failure
.
ErrorMessage
));
}
return
(
dynamic
)
result
;
var
result
=
Result
.
Invalid
(
new
ValidationError
(
"validation Error."
));
//foreach (var failure in failures)
//{
// result.Reasons.Add(new Error(failure.ErrorMessage));
//}
return
result
;
}
return
await
next
();
return
Result
.
Success
();
}
}
}
PSManagement.Application/Contracts/Authentication/IAuthenticationService.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
System
;
using
System.Threading.Tasks
;
...
...
PSManagement.Application/Contracts/Authorization/IRoleService.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
PSManagement.Domain.Identity.Entities
;
using
System.Collections.Generic
;
using
System.Linq
;
...
...
PSManagement.Application/Contracts/Authorization/IUserRoleService.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
...
...
@@ -7,10 +7,9 @@ namespace PSManagement.Application.Contracts.Authorization
{
public
interface
IUserRoleService
{
Task
<
bool
>
IsInRoleAsync
(
int
userId
,
string
role
);
Task
<
List
<
string
>>
GetUserRolesAsync
(
string
email
);
Task
<
Result
>
AssignUserToRole
(
string
userName
,
string
roleName
);
Task
UpdateUsersRole
(
string
userName
,
string
usersRole
);
Task
<
bool
>
IsInRoleAsync
(
int
userId
,
string
roleName
);
Task
<
Result
<
List
<
string
>>>
GetUserRolesAsync
(
string
email
);
Task
<
Result
>
AssignUserToRole
(
string
email
,
string
roleName
);
Task
<
Result
>
RemoveUserFromRole
(
string
email
,
string
roleName
);
}
...
...
PSManagement.Application/Contracts/Providers/IDepartmentsProvider.cs
View file @
5e219566
using
PSManagement.Domain.Employees.Entities
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Contracts.Providers
{
public
interface
IDepartmentsProvider
{
public
ICollection
<
Department
>
FetchDepartments
();
public
Task
<
ICollection
<
Department
>
>
FetchDepartments
();
}
}
PSManagement.Application/Contracts/Providers/IEmployeesProvider.cs
View file @
5e219566
...
...
@@ -9,6 +9,6 @@ namespace PSManagement.Application.Contracts.Providers
{
public
interface
IEmployeesProvider
{
public
ICollection
<
Employee
>
FetchEmployees
();
public
Task
<
IEnumerable
<
Employee
>
>
FetchEmployees
();
}
}
PSManagement.Application/Contracts/Storage/IFileService.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
...
...
PSManagement.Application/Contracts/SyncData/ISyncDepartmentsService.cs
0 → 100644
View file @
5e219566
using
PSManagement.Application.Contracts.Providers
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Contracts.SyncData
{
public
interface
ISyncDepartmentsService
{
public
Task
<
SyncResponse
>
SyncEmployees
(
IEmployeesProvider
employeesProvider
);
}
}
PSManagement.Application/Contracts/SyncData/ISyncEmployeesService.cs
View file @
5e219566
...
...
@@ -9,10 +9,10 @@ namespace PSManagement.Application.Contracts.SyncData
{
public
interface
ISyncEmployeesService
{
public
void
SyncEmployees
(
IEmployeesProvider
employeesProvider
);
}
public
interface
ISyncDepartmentsService
{
public
void
SyncEmployees
(
IEmployeesProvider
employeesProvider
);
public
Task
<
SyncResponse
>
SyncEmployees
(
IEmployeesProvider
employeesProvider
);
}
public
record
SyncResponse
(
int
SyncDataCount
,
DateTime
SyncDate
);
}
PSManagement.Application/Contracts/
Authorization
/IJwtTokenGenerator.cs
→
PSManagement.Application/Contracts/
Tokens
/IJwtTokenGenerator.cs
View file @
5e219566
using
PSManagement.Domain.Identity.Entities
;
using
System
;
namespace
PSManagement.Application.Contracts.
Authorization
namespace
PSManagement.Application.Contracts.
Tokens
{
public
interface
IJwtTokenGenerator
{
public
S
tring
GenerateToken
(
User
user
);
public
s
tring
GenerateToken
(
User
user
);
}
}
PSManagement.Application/Customers/Events/CustomerCreatedEventHandler.cs
View file @
5e219566
...
...
@@ -11,11 +11,12 @@ namespace PSManagement.Application.Customers.Events
{
public
class
CustomerCreatedEventHandler
:
IDomainEventHandler
<
CutsomerCreatedEvent
>
{
public
async
Task
Handle
(
CutsomerCreatedEvent
notification
,
CancellationToken
cancellationToken
)
public
Task
Handle
(
CutsomerCreatedEvent
notification
,
CancellationToken
cancellationToken
)
{
Console
.
WriteLine
(
"fdgfg"
);
return
Task
.
CompletedTask
;
}
}
}
PSManagement.Application/Customers/UseCases/Commands/AddContactInfo/AddContactInfoCommand.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
PSManagement.SharedKernel.Repositories
;
using
System
;
...
...
@@ -8,6 +8,9 @@ using System.Text;
namespace
PSManagement.Application.Customers.UseCases.Commands.AddContactInfo
{
public
record
AddContactInfoCommand
(
int
CustomerId
,
String
ContactType
,
String
ContactValue
)
:
ICommand
<
Result
>;
public
record
AddContactInfoCommand
(
int
CustomerId
,
String
ContactType
,
String
ContactValue
)
:
ICommand
<
Result
>;
}
PSManagement.Application/Customers/UseCases/Commands/AddContactInfo/AddContactInfoCommandHandler.cs
View file @
5e219566
using
FluentResults
;
using
PSManagement.Domain.Customers.Aggregate
;
using
Ardalis.Result
;
using
PSManagement.Domain.Customers.DomainErrors
;
using
PSManagement.Domain.Customers.Entities
;
using
PSManagement.Domain.Customers.Repositories
;
...
...
@@ -24,13 +23,13 @@ namespace PSManagement.Application.Customers.UseCases.Commands.AddContactInfo
if
(
customer
is
null
)
{
return
Result
.
Fail
(
CustomerErrors
.
InvalidEntryError
);
return
Result
.
Invalid
(
CustomerErrors
.
InvalidEntryError
);
}
ContactInfo
contact
=
new
(
request
.
ContactValue
,
request
.
ContactType
);
customer
.
AddContactInfo
(
contact
);
await
_customersRepository
.
UpdateAsync
(
customer
);
return
Result
.
Ok
();
return
Result
.
Success
();
}
}
...
...
PSManagement.Application/Customers/UseCases/Commands/CreateCustomer/CreateCustomerCommand.cs
View file @
5e219566
using
FluentResults
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Domain.Customers.Aggregate
;
using
Ardalis.Result
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
...
...
PSManagement.Application/Customers/UseCases/Commands/CreateCustomer/CreateCustomerCommandHandler.cs
View file @
5e219566
using
AutoMapper
;
using
FluentResults
;
using
PSManagement.Domain.Customers.Aggregate
;
using
Ardalis.Result
;
using
AutoMapper
;
using
PSManagement.Domain.Customers.DomainEvents
;
using
PSManagement.Domain.Customers.Entities
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
...
...
@@ -35,7 +35,7 @@ namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
customer
.
AddDomainEvent
(
new
CutsomerCreatedEvent
(
customer
.
Id
,
customer
.
CustomerName
));
await
_unitOfWork
.
SaveChangesAsync
();
return
Result
.
Ok
(
customer
.
Id
);
return
Result
.
Success
(
customer
.
Id
);
}
}
}
PSManagement.Application/Customers/UseCases/Commands/DeleteCustomer/DeleteCustomerCommand.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
using
System.Collections.Generic
;
...
...
PSManagement.Application/Customers/UseCases/Commands/DeleteCustomer/DeleteCustomerCommandHandler.cs
View file @
5e219566
using
FluentResults
;
using
PSManagement.Domain.Customers.Aggregate
;
using
Ardalis.Result
;
using
PSManagement.Domain.Customers.DomainErrors
;
using
PSManagement.Domain.Customers.Entities
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
...
...
@@ -27,12 +27,12 @@ namespace PSManagement.Application.Customers.UseCases.Commands.DeleteCustomer
if
(
customer
is
null
)
{
return
Result
.
Fail
(
CustomerErrors
.
InvalidEntryError
);
return
Result
.
Invalid
(
CustomerErrors
.
InvalidEntryError
);
}
await
_customersRepository
.
DeleteAsync
(
customer
);
return
Result
.
Ok
();
return
Result
.
Success
();
}
}
}
PSManagement.Application/Customers/UseCases/Commands/UpdateCustomer/UpdateCustomerCommand.cs
View file @
5e219566
using
FluentResults
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Domain.Customers.Aggregate
;
using
Ardalis.Result
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
...
...
PSManagement.Application/Customers/UseCases/Commands/UpdateCustomer/UpdateCustomerCommandHandler.cs
View file @
5e219566
using
A
utoMapper
;
using
FluentResults
;
using
PSManagement.Domain.Customers.Aggregate
;
using
A
rdalis.Result
;
using
AutoMapper
;
using
PSManagement.Domain.Customers.DomainEvents
;
using
PSManagement.Domain.Customers.Entities
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
...
...
@@ -31,7 +32,7 @@ namespace PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
await
_customerRepository
.
UpdateAsync
(
customer
);
return
Result
.
Ok
();
return
Result
.
Success
();
}
}
}
PSManagement.Application/Customers/UseCases/Queries/GetCustomer/GetCustomerQuery.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.SharedKernel.CQRS.Query
;
using
System
;
...
...
PSManagement.Application/Customers/UseCases/Queries/GetCustomer/GetCustomerQueryHandler.cs
View file @
5e219566
using
A
utoMapper
;
using
FluentResults
;
using
A
rdalis.Result
;
using
AutoMapper
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.DomainErrors
;
using
PSManagement.Domain.Customers.Entities
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.SharedKernel.CQRS.Query
;
using
System.Collections.Generic
;
...
...
@@ -25,9 +25,9 @@ namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer
{
Customer
customer
=
await
_customersRepository
.
GetByIdAsync
(
request
.
customerId
);
if
(
customer
is
null
)
{
return
Result
.
Fail
(
CustomerErrors
.
InvalidEntryError
);
return
Result
.
NotFound
(
CustomerErrors
.
InvalidEntryError
.
ErrorMessage
);
}
return
Result
.
Ok
(
_mapper
.
Map
<
CustomerDTO
>(
customer
));
return
Result
.
Success
(
_mapper
.
Map
<
CustomerDTO
>(
customer
));
}
}
...
...
PSManagement.Application/Customers/UseCases/Queries/ListAllCustomers/ListAllCustomersQuery.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.SharedKernel.CQRS.Query
;
using
System
;
...
...
PSManagement.Application/Customers/UseCases/Queries/ListAllCustomers/ListAllCustomersQueryHandler.cs
View file @
5e219566
using
A
utoMapper
;
using
FluentResults
;
using
A
rdalis.Result
;
using
AutoMapper
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.SharedKernel.CQRS.Query
;
...
...
@@ -21,7 +21,7 @@ namespace PSManagement.Application.Customers.UseCases.Queries.ListAllCustomers
public
async
Task
<
Result
<
IEnumerable
<
CustomerDTO
>>>
Handle
(
ListAllCustomersQuery
request
,
CancellationToken
cancellationToken
)
{
return
Result
.
Ok
(
_mapper
.
Map
<
IEnumerable
<
CustomerDTO
>>(
await
_customersRepository
.
ListAsync
()));
return
Result
.
Success
(
_mapper
.
Map
<
IEnumerable
<
CustomerDTO
>>(
await
_customersRepository
.
ListAsync
()));
}
}
...
...
PSManagement.Application/PSManagement.Application.csproj
View file @
5e219566
...
...
@@ -2,11 +2,13 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<NoWarn>NU1701</NoWarn>
</PropertyGroup>
<ItemGroup>
<Folder Include="Behaviors\AuthorizationBehavior\" />
<Folder Include="Employees\UseCases\Commands\UpdateEmployeeWorkHours\" />
<Folder Include="Employees\UseCases\Commands\SyncEmployeesData\" />
<Folder Include="Employees\UseCases\Queries\GetEmployeeWorkingHours\" />
<Folder Include="Employees\UseCases\Queries\GetEmployeeProjects\" />
<Folder Include="Employees\UseCases\Queries\GetAvailableEmployees\" />
...
...
@@ -58,6 +60,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="5.0.1" />
<PackageReference Include="ErrorOr" Version="2.0.1" />
<PackageReference Include="FluentValidation" Version="8.6.3" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="8.6.3" />
<PackageReference Include="MediatR" Version="8.0.1" />
...
...
PSManagement.Application/Projects/UseCases/Commands/CreateProject/CreateProjectCommand.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
PSManagement.Application.Projects.Common
;
using
PSManagement.Domain.Projects.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
...
...
@@ -13,9 +13,10 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
ProjectInfo
ProjectInfo
,
ProposalInfo
ProposalInfo
,
Aggreement
ProjectAggreement
,
FinancialFund
FinancialFund
,
int
TeamLeaderId
,
int
ProjectManagerId
,
int
ProposerId
)
:
ICommand
<
Result
<
ProjectDTO
>>;
int
ProposerId
,
int
ExecuterId
)
:
ICommand
<
Result
<
CreateProjectResponse
>>;
}
PSManagement.Application/Projects/UseCases/Commands/CreateProject/CreateProjectCommandHandler.cs
View file @
5e219566
using
FluentResults
;
using
Ardalis.Result
;
using
PSManagement.Application.Projects.Common
;
using
PSManagement.Domain.Projects.Builders
;
using
PSManagement.Domain.Projects.Entities
;
using
PSManagement.Domain.Projects.Repositories
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
PSManagement.SharedKernel.Interfaces
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Projects.UseCases.Commands.CreateProject
{
public
class
CreateProjectCommandHandler
:
ICommandHandler
<
CreateProjectCommand
,
Result
<
ProjectDTO
>>
public
class
CreateProjectCommandHandler
:
ICommandHandler
<
CreateProjectCommand
,
Result
<
CreateProjectResponse
>>
{
private
readonly
IProjectsRepository
_projectsRepository
;
private
readonly
ProjectBuilder
_projectBuilder
;
private
readonly
IUnitOfWork
_unitOfWork
;
public
CreateProjectCommandHandler
(
IProjectsRepository
projectsRepository
)
public
CreateProjectCommandHandler
(
IProjectsRepository
projectsRepository
,
ProjectBuilder
projectBuilder
,
IUnitOfWork
unitOfWork
)
{
_projectsRepository
=
projectsRepository
;
_projectBuilder
=
projectBuilder
;
_unitOfWork
=
unitOfWork
;
}
public
Task
<
Result
<
ProjectDTO
>>
Handle
(
CreateProjectCommand
request
,
CancellationToken
cancellationToken
)
public
async
Task
<
Result
<
CreateProjectResponse
>>
Handle
(
CreateProjectCommand
request
,
CancellationToken
cancellationToken
)
{
return
Task
.
FromResult
<
Result
<
ProjectDTO
>>(
Result
.
Fail
(
new
Error
(
""
)));
Project
project
=
_projectBuilder
.
WithProjectAggreement
(
request
.
ProjectAggreement
)
.
WithProjectInfo
(
request
.
ProjectInfo
)
.
WithProposalInfo
(
request
.
ProposalInfo
)
.
WithExecuter
(
request
.
ExecuterId
)
.
WithFinancialFund
(
request
.
FinancialFund
)
.
WithProjectManager
(
request
.
ProjectManagerId
)
.
WithTeamLeader
(
request
.
TeamLeaderId
)
.
WithProposer
(
request
.
ProposerId
)
.
Build
();
Project
AddedProject
=
await
_projectsRepository
.
AddAsync
(
project
);
CreateProjectResponse
response
=
new
(
AddedProject
.
Id
,
AddedProject
.
ProposalInfo
,
AddedProject
.
ProjectInfo
,
AddedProject
.
ProjectAggreement
,
AddedProject
.
TeamLeaderId
,
AddedProject
.
ProjectManagerId
,
AddedProject
.
ExecuterId
);
await
_unitOfWork
.
SaveChangesAsync
();
return
Result
.
Success
(
response
);
}
}
...
...
PSManagement.Application/Projects/UseCases/Commands/CreateProject/CreateProjectResponse.cs
0 → 100644
View file @
5e219566
using
PSManagement.Domain.Projects.ValueObjects
;
namespace
PSManagement.Application.Projects.UseCases.Commands.CreateProject
{
public
record
CreateProjectResponse
(
int
ProjectId
,
ProposalInfo
ProposalInfo
,
ProjectInfo
ProjectInfo
,
Aggreement
ProjectAggrement
,
int
TeamLeaderId
,
int
ProjectManagerId
,
int
ExecuterId
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment