Commit e9254581 authored by hasan khaddour's avatar hasan khaddour

fix s.

parent b6741e60
using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Api.Controllers.ApiBase;
using PSManagement.Application.Projects.UseCases.Commands.AddAttachment;
using PSManagement.Application.Projects.UseCases.Commands.CreateProject;
using PSManagement.Contracts.Projects.Requests;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.Projects
{
[Route("api/[controller]")]
[ApiController]
public class ProjectsController : APIController
{
private readonly IMediator _sender;
private readonly IMapper _mapper;
public ProjectsController(IMapper mapper, IMediator sender)
{
_mapper = mapper;
_sender = sender;
}
[HttpPost]
public async Task<IActionResult> Post([FromBody] CreateProjectRequest request)
{
var command = _mapper.Map<CreateProjectCommand>(request);
var result = await _sender.Send(command);
return Ok(_mapper.Map<CreateProjectResult>(result));
}
[HttpPost("AddAttachment")]
public async Task<IActionResult> AddAttachment( [FromForm]AddAttachmentRequest request)
{
var command = _mapper.Map<AddAttachmentCommand>(request);
var result = await _sender.Send(command);
return Ok(result);
}
}
}
......@@ -21,7 +21,10 @@ namespace PSManagement.Api.DI
services.AddApiCors();
services.AddScoped<Mapper>();
services.AddAutoMapper(typeof(CustomerMapperConfiguration),typeof(MapperConfigurations));
services.AddAutoMapper(
typeof(CustomerMapperConfiguration),
typeof(ProjectMapperConfiguration),
typeof(MapperConfigurations));
return services;
}
......
......@@ -3,8 +3,10 @@ using PSManagement.Application.Customers.Common;
using PSManagement.Application.Customers.UseCases.Commands.AddContactInfo;
using PSManagement.Application.Customers.UseCases.Commands.CreateCustomer;
using PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer;
using PSManagement.Application.Projects.UseCases.Commands.CreateProject;
using PSManagement.Contracts.Customers.Requests;
using PSManagement.Contracts.Customers.Responses;
using PSManagement.Contracts.Projects.Requests;
using PSManagement.SharedKernel.Utilities;
using System;
using System.Collections.Generic;
......@@ -31,4 +33,12 @@ namespace PSManagement.Api.Mappers
}
}
public class ProjectMapperConfiguration : Profile
{
public ProjectMapperConfiguration()
{
CreateMap<CreateProjectRequest, CreateProjectCommand>().ReverseMap();
}
}
}
......@@ -20,7 +20,7 @@
<ProjectReference Include="..\PSManagement.Contracts\PSManagement.Contracts.csproj" />
<ProjectReference Include="..\PSManagement.Domain\PSManagement.Domain.csproj" />
<ProjectReference Include="..\PSManagement.Infrastructure.Persistence\PSManagement.Infrastructure.Persistence.csproj" />
<ProjectReference Include="..\PSManagement.Infrastructure\PSManagement.Infrastructure.csproj" />
<ProjectReference Include="..\PSManagement.Infrastructure\PSManagement.Infrastructure.Services.csproj" />
<ProjectReference Include="..\PSManagement.Presentation\PSManagement.Presentation.csproj" />
<ProjectReference Include="..\PSManagement.SharedKernel\PSManagement.SharedKernel.csproj" />
</ItemGroup>
......
using Ardalis.Result;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -9,7 +10,7 @@ namespace PSManagement.Application.Contracts.Storage
{
public interface IFileService
{
public Result StoreFile(string fileName);
public Task<Result<String>> StoreFile(string fileName,IFormFile file);
}
}
......@@ -18,15 +18,15 @@
<Folder Include="FinancialSpending\UseCases\Commands\UpateFinancialSpendingItem\" />
<Folder Include="FinancialSpending\UseCases\Queries\GetFinancialSpendingByProject\" />
<Folder Include="FinancialSpending\UseCases\Queries\GetFinancialSpendingById\" />
<Folder Include="ProjectsStatus\UseCases\" />
<Folder Include="Projects\EventsHandlers\" />
<Folder Include="Projects\UseCases\Commands\AddProjectPlan\" />
<Folder Include="Projects\UseCases\Commands\AddParticipant\" />
<Folder Include="Projects\UseCases\Commands\ApproveProject\" />
<Folder Include="Projects\UseCases\Commands\ChangeProjectTeamLeader\" />
<Folder Include="Projects\UseCases\Commands\CompletePlanProcess\" />
<Folder Include="Projects\UseCases\Commands\CancleProject\" />
<Folder Include="Projects\UseCases\Commands\CompleteProgressProcess\" />
<Folder Include="Projects\UseCases\Commands\RemoveParticipant\" />
<Folder Include="Projects\UseCases\Commands\UpdateParticipant\" />
<Folder Include="Projects\UseCases\Commands\AddAttachment\" />
<Folder Include="Projects\UseCases\Commands\UpdateStep\" />
<Folder Include="Projects\UseCases\Queries\ListAllProject\" />
<Folder Include="Projects\UseCases\Queries\GetProjectPlan\" />
......@@ -65,6 +65,7 @@
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="8.6.3" />
<PackageReference Include="MediatR" Version="8.0.1" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
</ItemGroup>
......
namespace PSManagement.Application.Projects.Common
using PSManagement.Domain.Customers.Entities;
using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.ValueObjects;
using PSManagement.Domain.ProjectsStatus.Entites;
using System.Collections.Generic;
namespace PSManagement.Application.Projects.Common
{
public class ProjectDTO
{
public int Id { get; set; }
public ProposalInfo ProposalInfo { get; set; }
public ProjectInfo ProjectInfo { get; set; }
public ProjectStatus ProjectStatus { get; set; }
public Aggreement ProjectAggreement { get; set; }
// information about who lead and execute the project
public int TeamLeaderId { get; set; }
public Employee TeamLeader { get; set; }
public int ProjectManagerId { get; set; }
public Employee ProjectManager { get; set; }
public int ExecuterId { get; set; }
public Department Executer { get; set; }
// the proposer of the project
public int ProposerId { get; private set; }
public Customer Proposer { get; set; }
//
public ICollection<Step> Steps { get; set; }
public ICollection<Employee> Participants { get; set; }
public ICollection<Attachment> Attachments { get; set; }
// finincial plan
public FinancialFund FinancialFund { get; set; }
public ICollection<FinancialSpending> FinancialSpending { get; set; }
public ICollection<EmployeeParticipate> EmployeeParticipates { get; set; }
}
}
\ No newline at end of file
using PSManagement.Application.Contracts.Email;
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.SharedKernel.DomainEvents;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Projects.EventsHandlers
{
public class ProjectCreatedEventHandler:IDomainEventHandler<ProjectCreatedEvent>
{
private readonly IEmailService _emailService;
public ProjectCreatedEventHandler(IEmailService emailService)
{
_emailService = emailService;
}
public async Task Handle(ProjectCreatedEvent notification, CancellationToken cancellationToken)
{
await _emailService.SendAsync(""+notification.ProjectManagerId,"gf h gf ","fg fdg");
await _emailService.SendAsync("" + notification.TeamLeaderId, "gf h gf ", "fg fdg");
}
}
}
using Ardalis.Result;
using Microsoft.AspNetCore.Http;
using PSManagement.SharedKernel.CQRS.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Application.Projects.UseCases.Commands.AddAttachment
{
public record AddAttachmentCommand(
int ProjectId,
String AttachmentDescription,
String AttachmentName,
IFormFile File ) : ICommand<Result<int>>;
}
using Ardalis.Result;
using PSManagement.Application.Contracts.Storage;
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 PSManagement.SharedKernel.Repositories;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Projects.UseCases.Commands.AddAttachment
{
public class AddAttachmentCommandHandler : ICommandHandler<AddAttachmentCommand, Result<int>> {
private readonly IFileService _fileService;
private readonly IRepository<Attachment> _attachmentRepository;
private readonly IUnitOfWork _unitOfWork;
public AddAttachmentCommandHandler(
IFileService fileService,
IRepository<Attachment> repository,
IUnitOfWork unitOfWork)
{
_fileService = fileService;
_attachmentRepository = repository;
_unitOfWork = unitOfWork;
}
public async Task<Result<int>> Handle(AddAttachmentCommand request, CancellationToken cancellationToken)
{
Result<string> pathResult = await _fileService.StoreFile(request.AttachmentName+Guid.NewGuid(),request.File);
if (pathResult.IsSuccess)
{
Attachment attachment = new(pathResult.Value, request.AttachmentName, request.AttachmentDescription, request.ProjectId);
attachment = await _attachmentRepository.AddAsync(attachment);
await _unitOfWork.SaveChangesAsync();
return Result.Success(attachment.Id);
}
else {
return Result.Invalid(pathResult.ValidationErrors);
}
}
}
}
......@@ -18,5 +18,5 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
int ProjectManagerId,
int ProposerId,
int ExecuterId
) : ICommand<Result<CreateProjectResponse>>;
) : ICommand<Result<CreateProjectResult>>;
}
using Ardalis.Result;
using PSManagement.Application.Projects.Common;
using PSManagement.Domain.Projects.Builders;
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
......@@ -10,7 +11,7 @@ using System.Threading.Tasks;
namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
{
public class CreateProjectCommandHandler : ICommandHandler<CreateProjectCommand, Result<CreateProjectResponse>>
public class CreateProjectCommandHandler : ICommandHandler<CreateProjectCommand, Result<CreateProjectResult>>
{
private readonly IProjectsRepository _projectsRepository;
private readonly ProjectBuilder _projectBuilder;
......@@ -27,7 +28,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
_unitOfWork = unitOfWork;
}
public async Task<Result<CreateProjectResponse>> Handle(CreateProjectCommand request, CancellationToken cancellationToken)
public async Task<Result<CreateProjectResult>> Handle(CreateProjectCommand request, CancellationToken cancellationToken)
{
Project project = _projectBuilder
.WithProjectAggreement(request.ProjectAggreement)
......@@ -40,7 +41,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
.WithProposer(request.ProposerId)
.Build();
Project AddedProject =await _projectsRepository.AddAsync(project);
CreateProjectResponse response = new (
CreateProjectResult response = new (
AddedProject.Id,
AddedProject.ProposalInfo,
AddedProject.ProjectInfo,
......@@ -49,6 +50,8 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
AddedProject.ProjectManagerId,
AddedProject.ExecuterId
);
project.Propose();
project.AddDomainEvent(new ProjectCreatedEvent(AddedProject.Id,AddedProject.TeamLeaderId,AddedProject.ProjectManagerId));
await _unitOfWork.SaveChangesAsync();
return Result.Success(response);
......
......@@ -2,7 +2,7 @@
namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
{
public record CreateProjectResponse(
public record CreateProjectResult(
int ProjectId,
ProposalInfo ProposalInfo ,
ProjectInfo ProjectInfo,
......
......@@ -4,6 +4,10 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PSManagement.Domain\PSManagement.Domain.csproj" />
</ItemGroup>
......
using Microsoft.AspNetCore.Http;
using System;
namespace PSManagement.Contracts.Projects.Requests
{
public record AddAttachmentRequest(
int ProjectId,
String AttachmentDescription,
String AttachmentName,
IFormFile File);
}
using PSManagement.Domain.Projects.ValueObjects;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Contracts.Projects.Requests
{
public record CreateProjectRequest(
ProjectInfo ProjectInfo,
ProposalInfo ProposalInfo,
Aggreement ProjectAggreement,
FinancialFund FinancialFund,
int TeamLeaderId,
int ProjectManagerId,
int ProposerId,
int ExecuterId);
}
using PSManagement.Domain.Projects.ValueObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Contracts.Projects.Response
{
public record CreateProjectResponse(
int ProjectId,
ProposalInfo ProposalInfo,
ProjectInfo ProjectInfo,
Aggreement ProjectAggrement,
int TeamLeaderId,
int ProjectManagerId,
int ExecuterId
);
}
......@@ -19,7 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSManagement.Domain", "PSMa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSManagement.SharedKernel", "PSManagement.SharedKernel\PSManagement.SharedKernel.csproj", "{3507E59A-4B8B-4418-B1C6-0AD0C2697959}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSManagement.Infrastructure", "PSManagement.Infrastructure\PSManagement.Infrastructure.csproj", "{E96488F4-9D4F-4890-A7A0-1085647C82A8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSManagement.Infrastructure.Services", "PSManagement.Infrastructure\PSManagement.Infrastructure.Services.csproj", "{E96488F4-9D4F-4890-A7A0-1085647C82A8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{7C209DBF-1DB8-4E86-BD78-F689B70D5BD1}"
EndProject
......
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