Commit bca956a3 authored by hasan khaddour's avatar hasan khaddour

fix s.

parent 5e095f70
...@@ -18,6 +18,7 @@ using PSManagement.Contracts.Customers.Responses; ...@@ -18,6 +18,7 @@ using PSManagement.Contracts.Customers.Responses;
using PSManagement.Application.Customers.UseCases.Queries.GetCustomer; using PSManagement.Application.Customers.UseCases.Queries.GetCustomer;
using PSManagement.Api.Controllers.ApiBase; using PSManagement.Api.Controllers.ApiBase;
using Ardalis.Result; using Ardalis.Result;
using PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo;
namespace PSManagement.Api.Controllers.Customers namespace PSManagement.Api.Controllers.Customers
{ {
...@@ -35,36 +36,53 @@ namespace PSManagement.Api.Controllers.Customers ...@@ -35,36 +36,53 @@ namespace PSManagement.Api.Controllers.Customers
} }
[HttpGet] [HttpGet]
public async Task<IActionResult> ListCustomers() public async Task<IActionResult> Get()
{ {
var query = new ListAllCustomersQuery(); var query = new ListAllCustomersQuery();
var result = _mapper.Map<Result<IEnumerable<CustomerRecord>>>( await _sender.Send(query)); var result = _mapper.Map<Result<IEnumerable<CustomerResponse>>>( await _sender.Send(query));
return Ok(result); return Ok(result);
} }
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<IActionResult> GetCustomer(int id ) public async Task<IActionResult> Get(int id )
{ {
var query = new GetCustomerQuery(id); var query = new GetCustomerQuery(id);
var result = await _sender.Send(query); var result = await _sender.Send(query);
return Ok(_mapper.Map<Result<CustomerRecord>>(result)); return Ok(_mapper.Map<Result<CustomerResponse>>(result));
} }
[HttpPost] [HttpPost]
public async Task<IActionResult> CreateCustomer(CreateCustomerRequest request) public async Task<IActionResult> Post(CreateCustomerRequest request)
{ {
var command = _mapper.Map<CreateCustomerCommand>(request); var command = _mapper.Map<CreateCustomerCommand>(request);
var result = await _sender.Send(command); var result = await _sender.Send(command);
if (result.IsSuccess)
{
var query = new GetCustomerQuery(result.Value);
var response = await _sender.Send(query);
return Ok(_mapper.Map<CustomerResponse>(response));
}
else
{
return Ok(result); return Ok(result);
}
} }
[HttpDelete] [HttpDelete]
public async Task<IActionResult> DeleteCustomer(DeleteCustomerRequest request) public async Task<IActionResult> Delete(DeleteCustomerRequest request)
{ {
var command = _mapper.Map<DeleteCustomerCommand>(request); var command = _mapper.Map<DeleteCustomerCommand>(request);
...@@ -73,8 +91,9 @@ namespace PSManagement.Api.Controllers.Customers ...@@ -73,8 +91,9 @@ namespace PSManagement.Api.Controllers.Customers
return Ok(result); return Ok(result);
} }
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<IActionResult> UpdateCustomer(int id ,UpdateCustomerRequest request) public async Task<IActionResult> Put(int id ,UpdateCustomerRequest request)
{ {
if(id != request.CustomerId){ if(id != request.CustomerId){
return Problem(); return Problem();
...@@ -89,7 +108,7 @@ namespace PSManagement.Api.Controllers.Customers ...@@ -89,7 +108,7 @@ namespace PSManagement.Api.Controllers.Customers
[HttpPost("AddContactInfo")] [HttpPost("AddContactInfo")]
public async Task<IActionResult> AddContactInfo(AddContactInfoRequest request) public async Task<IActionResult> PostContactInfo(AddContactInfoRequest request)
{ {
var command = _mapper.Map<AddContactInfoCommand>(request); var command = _mapper.Map<AddContactInfoCommand>(request);
...@@ -99,6 +118,16 @@ namespace PSManagement.Api.Controllers.Customers ...@@ -99,6 +118,16 @@ namespace PSManagement.Api.Controllers.Customers
} }
[HttpDelete("RemoveContactInfo")]
public async Task<IActionResult> DeleteContactInfo(RemoveContactInfoRequest request)
{
var command = _mapper.Map<RemoveContactInfoCommand>(request);
var result = await _sender.Send(command);
return Ok(result);
}
} }
} }
...@@ -32,12 +32,12 @@ namespace PSManagement.Api.Mappers ...@@ -32,12 +32,12 @@ namespace PSManagement.Api.Mappers
CreateMap<UpdateCustomerCommand, UpdateCustomerRequest>().ReverseMap(); CreateMap<UpdateCustomerCommand, UpdateCustomerRequest>().ReverseMap();
CreateMap<AddContactInfoRequest, AddContactInfoCommand>().ReverseMap(); CreateMap<AddContactInfoRequest, AddContactInfoCommand>().ReverseMap();
CreateMap<CustomerDTO, CustomerRecord>(); CreateMap<CustomerDTO, CustomerResponse>();
CreateMap<ContactInfoDTO, ContactInfoRecord>(); CreateMap<ContactInfoDTO, ContactInfoResponse>();
CreateMap<CustomerRecord, CustomerDTO>().ReverseMap(); CreateMap<CustomerResponse, CustomerDTO>().ReverseMap();
CreateMap<IEnumerable<CustomerRecord>, ListCustomersResponse>() CreateMap<IEnumerable<CustomerResponse>, ListCustomersResponse>()
.ConstructUsing(src => new ListCustomersResponse(src)); .ConstructUsing(src => new ListCustomersResponse(src));
} }
......
...@@ -24,7 +24,8 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior ...@@ -24,7 +24,8 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{ {
if (_validators is null) { if (_validators is null)
{
return await next(); return await next();
} }
...@@ -34,7 +35,7 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior ...@@ -34,7 +35,7 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
var errors = validationResults.SelectMany(r => r.Errors) var errors = validationResults.SelectMany(r => r.Errors)
.Where(e => e != null) .Where(e => e != null)
.Select(e => new ValidationError(e.ErrorCode,e.ErrorMessage,e.ErrorCode,new ValidationSeverity())) .Select(e => new ValidationError(e.ErrorCode, e.ErrorMessage, e.ErrorCode, new ValidationSeverity()))
.ToList(); .ToList();
if (errors.Any()) if (errors.Any())
...@@ -45,28 +46,5 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior ...@@ -45,28 +46,5 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
return await next(); 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.Invalid(new ValidationError("validation Error."));
//foreach (var failure in failures)
//{
// result.Reasons.Add(new Error(failure.ErrorMessage));
//}
return result;
}
return Result.Success();
}
} }
} }
using PSManagement.Domain.Customers.DomainEvents; using Microsoft.Extensions.Logging;
using PSManagement.Application.Contracts.Providers;
using PSManagement.Domain.Customers.DomainEvents;
using PSManagement.Domain.Customers.Entities;
using PSManagement.SharedKernel.DomainEvents; using PSManagement.SharedKernel.DomainEvents;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -11,10 +14,22 @@ namespace PSManagement.Application.Customers.Events ...@@ -11,10 +14,22 @@ namespace PSManagement.Application.Customers.Events
{ {
public class CustomerCreatedEventHandler : IDomainEventHandler<CutsomerCreatedEvent> public class CustomerCreatedEventHandler : IDomainEventHandler<CutsomerCreatedEvent>
{ {
private readonly ILogger<Customer> _logger;
private readonly IDateTimeProvider _dateTimeProvider;
public CustomerCreatedEventHandler(
ILogger<Customer> logger,
IDateTimeProvider dateTimeProvider)
{
_logger = logger;
_dateTimeProvider = dateTimeProvider;
}
public Task Handle(CutsomerCreatedEvent notification, CancellationToken cancellationToken) public Task Handle(CutsomerCreatedEvent notification, CancellationToken cancellationToken)
{ {
Console.WriteLine("fdgfg"); _logger.LogInformation("new customer Added at "+_dateTimeProvider.UtcNow);
return Task.CompletedTask; return Task.CompletedTask;
} }
......
using Ardalis.Result;
using PSManagement.SharedKernel.CQRS.Command;
namespace PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo
{
public record RemoveContactInfoCommand(
int Id,
int CustomerId) : ICommand<Result>;
}
using Ardalis.Result;
using PSManagement.Domain.Customers.DomainErrors;
using PSManagement.Domain.Customers.Entities;
using PSManagement.Domain.Customers.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
using PSManagement.SharedKernel.Repositories;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo
{
public class RemoveContactInfoCommandHandler : ICommandHandler<RemoveContactInfoCommand, Result>
{
private readonly ICustomersRepository _customersRepository;
private readonly IRepository<ContactInfo> _contactsRepository;
public RemoveContactInfoCommandHandler(
ICustomersRepository customersRepository,
IRepository<ContactInfo> contactsRepository)
{
_customersRepository = customersRepository;
_contactsRepository = contactsRepository;
}
public async Task<Result> Handle(RemoveContactInfoCommand request, CancellationToken cancellationToken)
{
Customer customer = await _customersRepository.GetByIdAsync(request.CustomerId);
if (customer is null)
{
return Result.Invalid(CustomerErrors.InvalidEntryError);
}
ContactInfo contact = await _contactsRepository.GetByIdAsync(request.Id);
if (contact is null) {
return Result.Invalid(CustomerErrors.InvalidEntryError);
}
await _contactsRepository.DeleteAsync(contact);
return Result.Success();
}
}
}
...@@ -27,8 +27,10 @@ namespace PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer ...@@ -27,8 +27,10 @@ namespace PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
public async Task<Result> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
{ {
Customer customer = new (request.CustomerName ,request.Address,request.Email); Customer customer = await _customerRepository.GetByIdAsync(request.CustomerId);
customer.Id = request.CustomerId; customer.Email = request.Email;
customer.CustomerName = request.CustomerName;
customer.Address = request.Address;
await _customerRepository.UpdateAsync(customer); await _customerRepository.UpdateAsync(customer);
......
...@@ -7,6 +7,6 @@ using System.Text; ...@@ -7,6 +7,6 @@ using System.Text;
namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer
{ {
public record GetCustomerQuery(int customerId) : IQuery<Result<CustomerDTO>>; public record GetCustomerQuery(int CustomerId) : IQuery<Result<CustomerDTO>>;
} }
...@@ -4,7 +4,9 @@ using PSManagement.Application.Customers.Common; ...@@ -4,7 +4,9 @@ using PSManagement.Application.Customers.Common;
using PSManagement.Domain.Customers.DomainErrors; using PSManagement.Domain.Customers.DomainErrors;
using PSManagement.Domain.Customers.Entities; using PSManagement.Domain.Customers.Entities;
using PSManagement.Domain.Customers.Repositories; using PSManagement.Domain.Customers.Repositories;
using PSManagement.Domain.Customers.Specification;
using PSManagement.SharedKernel.CQRS.Query; using PSManagement.SharedKernel.CQRS.Query;
using PSManagement.SharedKernel.Specification;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -15,18 +17,23 @@ namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer ...@@ -15,18 +17,23 @@ namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer
{ {
private readonly ICustomersRepository _customersRepository; private readonly ICustomersRepository _customersRepository;
private readonly IMapper _mapper; private readonly IMapper _mapper;
private readonly BaseSpecification<Customer> _specification ;
public GetCustomerQueryHandler(ICustomersRepository customersRepository, IMapper mapper) public GetCustomerQueryHandler(ICustomersRepository customersRepository, IMapper mapper)
{ {
_customersRepository = customersRepository; _customersRepository = customersRepository;
_mapper = mapper; _mapper = mapper;
_specification = new CustomerSpecification();
} }
public async Task<Result<CustomerDTO>> Handle(GetCustomerQuery request, CancellationToken cancellationToken) public async Task<Result<CustomerDTO>> Handle(GetCustomerQuery request, CancellationToken cancellationToken)
{ {
Customer customer = await _customersRepository.GetByIdAsync(request.customerId); Customer customer = await _customersRepository.GetByIdAsync(request.CustomerId,_specification);
if (customer is null) { if (customer is null) {
return Result.NotFound(CustomerErrors.InvalidEntryError.ErrorMessage);
return Result.Invalid(CustomerErrors.InvalidEntryError);
} }
return Result.Success(_mapper.Map<CustomerDTO>(customer)); return Result.Success(_mapper.Map<CustomerDTO>(customer));
} }
......
...@@ -15,6 +15,7 @@ namespace PSManagement.Application.Employees.Common ...@@ -15,6 +15,7 @@ namespace PSManagement.Application.Employees.Common
public String DepartmentName { get; set; } public String DepartmentName { get; set; }
public PersonalInfo PersonalInfo { get; set; } public PersonalInfo PersonalInfo { get; set; }
public WorkInfo WorkInfo { get; set; } public WorkInfo WorkInfo { get; set; }
public Availability Availability { get; set; }
} }
} }
...@@ -28,7 +28,7 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeeById ...@@ -28,7 +28,7 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeeById
public async Task<Result<EmployeeDTO>> Handle(GetEmployeeByIdQuery request, CancellationToken cancellationToken) public async Task<Result<EmployeeDTO>> Handle(GetEmployeeByIdQuery request, CancellationToken cancellationToken)
{ {
_specification.AddInclude(e => e.Department);
return Result.Success(_mapper.Map<EmployeeDTO>(await _employeesRepository.GetByIdAsync(request.EmployeeId,_specification))); return Result.Success(_mapper.Map<EmployeeDTO>(await _employeesRepository.GetByIdAsync(request.EmployeeId,_specification)));
} }
} }
......
...@@ -38,6 +38,8 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeeById ...@@ -38,6 +38,8 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeeById
_specification.AddInclude("Employee.Department"); _specification.AddInclude("Employee.Department");
_specification.AddInclude(e => e.Employee); _specification.AddInclude(e => e.Employee);
_specification.AddInclude(e => e.Employee.Department);
IEnumerable<EmployeeParticipate> response = await _employeesParticipateRepository.ListAsync(_specification); IEnumerable<EmployeeParticipate> response = await _employeesParticipateRepository.ListAsync(_specification);
......
...@@ -17,21 +17,17 @@ namespace PSManagement.Application.FinancialSpends.UseCases.Commands.CreateFinan ...@@ -17,21 +17,17 @@ namespace PSManagement.Application.FinancialSpends.UseCases.Commands.CreateFinan
private readonly IProjectsRepository _projectsRepository; private readonly IProjectsRepository _projectsRepository;
private readonly IFinancialSpendingRepository _spendRepository; private readonly IFinancialSpendingRepository _spendRepository;
private readonly IUnitOfWork _unitOfWork; private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;
public CreateFinancialSpendItemCommandHandler( public CreateFinancialSpendItemCommandHandler(
IFinancialSpendingRepository spendRepository, IFinancialSpendingRepository spendRepository,
IProjectsRepository projectsRepository, IProjectsRepository projectsRepository,
IUnitOfWork unitOfWork, IUnitOfWork unitOfWork
IMapper mapper) )
{ {
_spendRepository = spendRepository; _spendRepository = spendRepository;
_projectsRepository = projectsRepository; _projectsRepository = projectsRepository;
_unitOfWork = unitOfWork; _unitOfWork = unitOfWork;
_mapper = mapper;
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
<ItemGroup> <ItemGroup>
<Folder Include="Behaviors\AuthorizationBehavior\" /> <Folder Include="Behaviors\AuthorizationBehavior\" />
<Folder Include="Customers\UseCases\Commands\RemoveContactInfo\" />
<Folder Include="Tracks\EventsHandlers\" /> <Folder Include="Tracks\EventsHandlers\" />
</ItemGroup> </ItemGroup>
......
...@@ -41,7 +41,8 @@ namespace PSManagement.Application.Projects.UseCases.Commands.AddParticipant ...@@ -41,7 +41,8 @@ namespace PSManagement.Application.Projects.UseCases.Commands.AddParticipant
public async Task<Result> Handle(AddParticipantCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(AddParticipantCommand request, CancellationToken cancellationToken)
{ {
_specification.Includes.Add(p => p.EmployeeParticipates); _specification.AddInclude(e => e.EmployeeParticipates);
Project project =await _projectsRepository.GetByIdAsync(request.ProjectId,_specification); Project project =await _projectsRepository.GetByIdAsync(request.ProjectId,_specification);
if (project is null) if (project is null)
{ {
...@@ -54,12 +55,14 @@ namespace PSManagement.Application.Projects.UseCases.Commands.AddParticipant ...@@ -54,12 +55,14 @@ namespace PSManagement.Application.Projects.UseCases.Commands.AddParticipant
return Result.Invalid(ProjectsErrors.ParticipantExistError); return Result.Invalid(ProjectsErrors.ParticipantExistError);
} }
else { else {
Employee employee = await _employeesRepository.GetByIdAsync(request.ParticipantId); Employee employee = await _employeesRepository.GetByIdAsync(request.ParticipantId);
if (employee is null) { if (employee is null) {
return Result.Invalid(EmployeesErrors.EmployeeUnExist); return Result.Invalid(EmployeesErrors.EmployeeUnExist);
} }
await _employeeParticipateRepository.AddAsync(new (request.ParticipantId,request.ProjectId,request.Role,request.PartialTimeRatio)); await _employeeParticipateRepository.AddAsync(new (request.ParticipantId,request.ProjectId,request.Role,request.PartialTimeRatio));
project.AddDomainEvent(new ParticipantAddedEvent(request.ParticipantId,request.ProjectId,request.PartialTimeRatio,request.Role)); project.AddDomainEvent(new ParticipantAddedEvent(request.ParticipantId,request.ProjectId,request.PartialTimeRatio,request.Role));
......
using Ardalis.Result; using Ardalis.Result;
using PSManagement.Application.Contracts.Providers;
using PSManagement.Domain.Projects.DomainErrors; using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.Entities; using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories; using PSManagement.Domain.Projects.Repositories;
...@@ -13,16 +14,17 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CancelProject ...@@ -13,16 +14,17 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CancelProject
{ {
private readonly IProjectsRepository _projectsRepository; private readonly IProjectsRepository _projectsRepository;
private readonly IUnitOfWork _unitOfWork; private readonly IUnitOfWork _unitOfWork;
private readonly IDateTimeProvider _dateTime;
public CancelProjectCommandHandler( public CancelProjectCommandHandler(
IProjectsRepository projectsRepository, IProjectsRepository projectsRepository,
IUnitOfWork unitOfWork IUnitOfWork unitOfWork,
) IDateTimeProvider dateTime)
{ {
_projectsRepository = projectsRepository; _projectsRepository = projectsRepository;
_unitOfWork = unitOfWork; _unitOfWork = unitOfWork;
_dateTime = dateTime;
} }
public async Task<Result> Handle(CancelProjectCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(CancelProjectCommand request, CancellationToken cancellationToken)
...@@ -35,7 +37,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CancelProject ...@@ -35,7 +37,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CancelProject
else else
{ {
project.Cancle(); project.Cancel(_dateTime.UtcNow);
await _unitOfWork.SaveChangesAsync(); await _unitOfWork.SaveChangesAsync();
return Result.Success(); return Result.Success();
......
using Ardalis.Result; using Ardalis.Result;
using PSManagement.Domain.Projects;
using PSManagement.Domain.Projects.DomainErrors; using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.DomainEvents; using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.Entities; using PSManagement.Domain.Projects.Entities;
...@@ -6,6 +7,7 @@ using PSManagement.Domain.Projects.Repositories; ...@@ -6,6 +7,7 @@ using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.CQRS.Command; using PSManagement.SharedKernel.CQRS.Command;
using PSManagement.SharedKernel.Interfaces; using PSManagement.SharedKernel.Interfaces;
using PSManagement.SharedKernel.Repositories; using PSManagement.SharedKernel.Repositories;
using PSManagement.SharedKernel.Specification;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -17,6 +19,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant ...@@ -17,6 +19,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant
private readonly IProjectsRepository _projectsRepository; private readonly IProjectsRepository _projectsRepository;
private readonly IRepository<EmployeeParticipate> _employeeParticipateRepository; private readonly IRepository<EmployeeParticipate> _employeeParticipateRepository;
private readonly IUnitOfWork _unitOfWork; private readonly IUnitOfWork _unitOfWork;
private readonly BaseSpecification<Project> _specification;
public AddParticipantCommandHandler( public AddParticipantCommandHandler(
IRepository<EmployeeParticipate> repository, IRepository<EmployeeParticipate> repository,
...@@ -24,37 +27,41 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant ...@@ -24,37 +27,41 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant
IUnitOfWork unitOfWork) IUnitOfWork unitOfWork)
{ {
_employeeParticipateRepository = repository; _employeeParticipateRepository = repository;
_specification = new ProjectSpecification();
_projectsRepository = projectsRepository; _projectsRepository = projectsRepository;
_unitOfWork = unitOfWork; _unitOfWork = unitOfWork;
} }
public async Task<Result> Handle(RemoveParticipantCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(RemoveParticipantCommand request, CancellationToken cancellationToken)
{ {
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId); _specification.AddInclude(e => e.EmployeeParticipates);
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId,_specification);
if (project is null) if (project is null)
{ {
return Result.Invalid(ProjectsErrors.InvalidEntryError); return Result.Invalid(ProjectsErrors.InvalidEntryError);
} }
else else
{ {
if (project.EmployeeParticipates is null) {
if (project.EmployeeParticipates?.Where(e => e.Id == request.ParticipantId) is null) return Result.Invalid(ProjectsErrors.ParticipantUnExistError);
{
}
var employeeParticipate =project.EmployeeParticipates.Where(e => e.ProjectId == request.ParticipantId).FirstOrDefault();
if (employeeParticipate is null) {
return Result.Invalid(ProjectsErrors.ParticipantUnExistError); return Result.Invalid(ProjectsErrors.ParticipantUnExistError);
} }
else
{
EmployeeParticipate participant = await _employeeParticipateRepository.GetByIdAsync(request.ParticipantId);
await _employeeParticipateRepository.DeleteAsync(participant);
await _employeeParticipateRepository.DeleteAsync(employeeParticipate);
project.AddDomainEvent(new ParticipantRemovedEvent(request.ParticipantId, request.ProjectId)); project.AddDomainEvent(new ParticipantRemovedEvent(request.ParticipantId, request.ProjectId));
await _unitOfWork.SaveChangesAsync(); await _unitOfWork.SaveChangesAsync();
return Result.Success(); return Result.Success();
}
} }
......
...@@ -15,19 +15,14 @@ namespace PSManagement.Application.Tracks.UseCaes.Commands.UpdateEmployeeWorkTra ...@@ -15,19 +15,14 @@ namespace PSManagement.Application.Tracks.UseCaes.Commands.UpdateEmployeeWorkTra
{ {
private readonly IRepository<EmployeeTrack> _employeeTracksRepository; private readonly IRepository<EmployeeTrack> _employeeTracksRepository;
private readonly ITracksRepository _tracksRepository; private readonly ITracksRepository _tracksRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;
public UpdateEmployeeWorkTrackCommandHandler( public UpdateEmployeeWorkTrackCommandHandler(
IUnitOfWork unitOfWork,
ITracksRepository tracksRepository, ITracksRepository tracksRepository,
IRepository<EmployeeTrack> employeeTracksRepository, IRepository<EmployeeTrack> employeeTracksRepository
IMapper mapper) )
{ {
_unitOfWork = unitOfWork;
_tracksRepository = tracksRepository; _tracksRepository = tracksRepository;
_employeeTracksRepository = employeeTracksRepository; _employeeTracksRepository = employeeTracksRepository;
_mapper = mapper;
} }
public async Task<Result> Handle(UpdateEmployeeWorkTrackCommand request, CancellationToken cancellationToken) public async Task<Result> Handle(UpdateEmployeeWorkTrackCommand request, CancellationToken cancellationToken)
......
...@@ -10,4 +10,5 @@ namespace PSManagement.Contracts.Customers.Requests ...@@ -10,4 +10,5 @@ namespace PSManagement.Contracts.Customers.Requests
int CustomerId, int CustomerId,
String ContactType, String ContactType,
String ContactValue); String ContactValue);
} }
namespace PSManagement.Contracts.Customers.Requests
{
public record RemoveContactInfoRequest(
int Id,
int CustomerId) ;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace PSManagement.Contracts.Customers.Responses namespace PSManagement.Contracts.Customers.Responses
{ {
public class ContactInfoRecord { public class ContactInfoResponse {
public String ContactType { get; set; } public String ContactType { get; set; }
public String ContactValue { get; set; } public String ContactValue { get; set; }
} }
......
...@@ -5,8 +5,8 @@ using System.Collections.Generic; ...@@ -5,8 +5,8 @@ using System.Collections.Generic;
namespace PSManagement.Contracts.Customers.Responses namespace PSManagement.Contracts.Customers.Responses
{ {
public class CustomerRecord { public class CustomerResponse {
public CustomerRecord() public CustomerResponse()
{ {
} }
...@@ -15,6 +15,6 @@ namespace PSManagement.Contracts.Customers.Responses ...@@ -15,6 +15,6 @@ namespace PSManagement.Contracts.Customers.Responses
public String CustomerName { get; set; } public String CustomerName { get; set; }
public String Email { get; set; } public String Email { get; set; }
public Address Address { get; set; } public Address Address { get; set; }
public IEnumerable<ContactInfoRecord> ContactInfo { get; set; } public IEnumerable<ContactInfoResponse> ContactInfo { get; set; }
} }
} }
...@@ -5,6 +5,6 @@ using System.Threading.Tasks; ...@@ -5,6 +5,6 @@ using System.Threading.Tasks;
namespace PSManagement.Contracts.Customers.Responses namespace PSManagement.Contracts.Customers.Responses
{ {
public record ListCustomersResponse( IEnumerable<CustomerRecord> Customers ); public record ListCustomersResponse( IEnumerable<CustomerResponse> Customers );
} }
...@@ -9,6 +9,7 @@ namespace PSManagement.Contracts.Projects.Response ...@@ -9,6 +9,7 @@ namespace PSManagement.Contracts.Projects.Response
public int UserId { get; set; } public int UserId { get; set; }
public string DepartmentName { get; set; } public string DepartmentName { get; set; }
public PersonalInfo PersonalInfo { get; set; } public PersonalInfo PersonalInfo { get; set; }
public Availability Availability { get; set; }
public WorkInfo WorkInfo { get; set; } public WorkInfo WorkInfo { get; set; }
} }
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ namespace PSManagement.Contracts.Projects.Response ...@@ -22,7 +22,7 @@ namespace PSManagement.Contracts.Projects.Response
public Department Executer { get; set; } public Department Executer { get; set; }
public int ProposerId { get; private set; } public int ProposerId { get; private set; }
public CustomerRecord Proposer { get; set; } public CustomerResponse Proposer { get; set; }
public ICollection<StepResponse> Steps { get; set; } public ICollection<StepResponse> Steps { get; set; }
public ICollection<Attachment> Attachments { get; set; } public ICollection<Attachment> Attachments { get; set; }
......
using PSManagement.Domain.Customers.Entities;
using PSManagement.SharedKernel.Specification;
using System;
using System.Linq.Expressions;
namespace PSManagement.Domain.Customers.Specification
{
public class CustomerSpecification : BaseSpecification<Customer>
{
public CustomerSpecification(Expression<Func<Customer, bool>> criteria = null) : base(criteria)
{
AddInclude(e => e.ContactInfo);
}
}
}
...@@ -9,7 +9,6 @@ namespace PSManagement.Domain.Customers.ValueObjects ...@@ -9,7 +9,6 @@ namespace PSManagement.Domain.Customers.ValueObjects
{ {
public record Address( public record Address(
int StreetNumber , int StreetNumber ,
int ZipCode ,
String StreetName , String StreetName ,
String City ); String City );
} }
...@@ -89,6 +89,7 @@ namespace PSManagement.Domain.Projects.Builders ...@@ -89,6 +89,7 @@ namespace PSManagement.Domain.Projects.Builders
} }
public ProjectBuilder WithAttachment(Attachment[] attachments) public ProjectBuilder WithAttachment(Attachment[] attachments)
{ {
_attachments = new List<Attachment>();
foreach (Attachment attachment in attachments) { foreach (Attachment attachment in attachments) {
_attachments.Add(attachment); _attachments.Add(attachment);
} }
......
...@@ -20,10 +20,11 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -20,10 +20,11 @@ namespace PSManagement.Domain.Projects.Entities
public ProposalInfo ProposalInfo { get; set; } public ProposalInfo ProposalInfo { get; set; }
public ProjectInfo ProjectInfo { get; set; } public ProjectInfo ProjectInfo { get; set; }
public Aggreement ProjectAggreement { get; set; } public Aggreement ProjectAggreement { get; set; }
// state management // state management
[NotMapped]
public string CurrentState { get; private set; } // Persisted in the database public string CurrentState { get; private set; } // Persisted in the database
[NotMapped]
private IProjectState _state; private IProjectState _state;
// information about who lead and execute the project // information about who lead and execute the project
...@@ -95,16 +96,16 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -95,16 +96,16 @@ namespace PSManagement.Domain.Projects.Entities
Participants = new List<Employee>(); Participants = new List<Employee>();
EmployeeParticipates = new List<EmployeeParticipate>(); EmployeeParticipates = new List<EmployeeParticipate>();
} }
public Project() public Project()
{ {
_state = new ProposedState(); SetStateFromString(CurrentState);
CurrentState = _state.StateName;
} }
public void SetState(IProjectState newState) public void SetState(IProjectState newState)
{ {
_state = newState; _state = newState;
CurrentState = _state.StateName; // Update the persisted state CurrentState = _state.StateName;
} }
public void Complete() public void Complete()
{ {
...@@ -121,9 +122,9 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -121,9 +122,9 @@ namespace PSManagement.Domain.Projects.Entities
_state.Approve(this,projectAggreement); _state.Approve(this,projectAggreement);
} }
public void Cancle() public void Cancel(DateTime canellationTime)
{ {
_state.Cancle(this); _state.Cancel(this,canellationTime);
} }
public void Propose() public void Propose()
......
using PSManagement.Domain.Projects.ValueObjects; using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities namespace PSManagement.Domain.Projects.Entities
{ {
...@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities
} }
public void Cancle(Project project) public void Cancel(Project project, DateTime canellationTime)
{ {
} }
......
using PSManagement.Domain.Projects.ValueObjects; using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities namespace PSManagement.Domain.Projects.Entities
{ {
...@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities
} }
public void Cancle(Project project) public void Cancel(Project project, DateTime canellationTime)
{ {
} }
......
using PSManagement.Domain.Projects.ValueObjects; using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities namespace PSManagement.Domain.Projects.Entities
{ {
...@@ -7,7 +8,7 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -7,7 +8,7 @@ namespace PSManagement.Domain.Projects.Entities
void Complete(Project project); void Complete(Project project);
void Plan(Project project); void Plan(Project project);
void Approve(Project project, Aggreement projectAggreement); void Approve(Project project, Aggreement projectAggreement);
void Cancle(Project project); void Cancel(Project project, DateTime canellationTime);
void Propose(Project project); void Propose(Project project);
string StateName { get; } string StateName { get; }
} }
......
...@@ -16,7 +16,7 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -16,7 +16,7 @@ namespace PSManagement.Domain.Projects.Entities
project.SetState(new InProgressState()); project.SetState(new InProgressState());
} }
public void Cancle(Project project) public void Cancel(Project project, DateTime canellationTime)
{ {
project.AddDomainEvent(new ProjectCancelledEvent(project.Id,DateTime.Now)); project.AddDomainEvent(new ProjectCancelledEvent(project.Id,DateTime.Now));
project.SetState(new CancledState()); project.SetState(new CancledState());
......
...@@ -13,9 +13,9 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -13,9 +13,9 @@ namespace PSManagement.Domain.Projects.Entities
} }
public void Cancle(Project project) public void Cancel(Project project, DateTime canellationTime)
{ {
project.AddDomainEvent(new ProjectCancelledEvent(project.Id, DateTime.Now)); project.AddDomainEvent(new ProjectCancelledEvent(project.Id,canellationTime));
project.SetState(new CancledState()); project.SetState(new CancledState());
} }
......
using PSManagement.Domain.Projects.ValueObjects; using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities namespace PSManagement.Domain.Projects.Entities
{ {
...@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities ...@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities
} }
public void Cancle(Project project) public void Cancel(Project project, DateTime canellationTime)
{ {
} }
......
...@@ -19,11 +19,10 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration ...@@ -19,11 +19,10 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
address.Property(a => a.StreetName).HasColumnName("StreetName"); address.Property(a => a.StreetName).HasColumnName("StreetName");
address.Property(a => a.City).HasColumnName("City"); address.Property(a => a.City).HasColumnName("City");
address.Property(a => a.StreetNumber).HasColumnName("StreetNumber"); address.Property(a => a.StreetNumber).HasColumnName("StreetNumber");
address.Property(a => a.ZipCode).HasColumnName("ZipCode");
} }
); );
builder.OwnsMany(c => c.ContactInfo); builder.HasMany(c => c.ContactInfo);
} }
} }
......
...@@ -37,6 +37,7 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration ...@@ -37,6 +37,7 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
} }
); );
builder.HasOne(e => e.TeamLeader) builder.HasOne(e => e.TeamLeader)
.WithMany() .WithMany()
.HasForeignKey(e => e.TeamLeaderId) .HasForeignKey(e => e.TeamLeaderId)
...@@ -63,12 +64,17 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration ...@@ -63,12 +64,17 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
} }
); );
builder.Property(p => p.CurrentState).HasDefaultValue("Proposed"); builder.Property(p => p.CurrentState)
.HasDefaultValueSql("Proposed")
;
builder.HasMany(e => e.Attachments).WithOne().HasForeignKey(e => e.ProjectId); builder.HasMany(e => e.Attachments).WithOne().HasForeignKey(e => e.ProjectId);
builder.HasMany(e => e.FinancialSpending).WithOne().HasForeignKey(e=>e.ProjectId); builder.HasMany(e => e.FinancialSpending).WithOne().HasForeignKey(e=>e.ProjectId);
builder.HasMany(e => e.Tracks).WithOne(e => e.Project).HasForeignKey(e => e.ProjectId); builder.HasMany(e => e.Tracks).WithOne(e => e.Project).HasForeignKey(e => e.ProjectId);
} }
} }
} }
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class FixCustomerEntity : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ContactInfo_Customers_CustomerId",
table: "ContactInfo");
migrationBuilder.DropPrimaryKey(
name: "PK_ContactInfo",
table: "ContactInfo");
migrationBuilder.DropColumn(
name: "ZipCode",
table: "Customers");
migrationBuilder.AlterColumn<int>(
name: "CustomerId",
table: "ContactInfo",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AddPrimaryKey(
name: "PK_ContactInfo",
table: "ContactInfo",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_ContactInfo_CustomerId",
table: "ContactInfo",
column: "CustomerId");
migrationBuilder.AddForeignKey(
name: "FK_ContactInfo_Customers_CustomerId",
table: "ContactInfo",
column: "CustomerId",
principalTable: "Customers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ContactInfo_Customers_CustomerId",
table: "ContactInfo");
migrationBuilder.DropPrimaryKey(
name: "PK_ContactInfo",
table: "ContactInfo");
migrationBuilder.DropIndex(
name: "IX_ContactInfo_CustomerId",
table: "ContactInfo");
migrationBuilder.AddColumn<int>(
name: "ZipCode",
table: "Customers",
type: "int",
nullable: true);
migrationBuilder.AlterColumn<int>(
name: "CustomerId",
table: "ContactInfo",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AddPrimaryKey(
name: "PK_ContactInfo",
table: "ContactInfo",
columns: new[] { "CustomerId", "Id" });
migrationBuilder.AddForeignKey(
name: "FK_ContactInfo_Customers_CustomerId",
table: "ContactInfo",
column: "CustomerId",
principalTable: "Customers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class FixProjectEntity : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "CurrentState",
table: "Projects",
type: "nvarchar(max)",
nullable: true,
defaultValueSql: "Proposed",
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true,
oldDefaultValue: "Proposed");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "CurrentState",
table: "Projects",
type: "nvarchar(max)",
nullable: true,
defaultValue: "Proposed",
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true,
oldDefaultValueSql: "Proposed");
}
}
}
...@@ -20,6 +20,29 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -20,6 +20,29 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.HasAnnotation("ProductVersion", "5.0.17") .HasAnnotation("ProductVersion", "5.0.17")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.ContactInfo", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("ContactType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ContactValue")
.HasColumnType("nvarchar(max)");
b.Property<int?>("CustomerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.ToTable("ContactInfo");
});
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b => modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
...@@ -281,7 +304,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -281,7 +304,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.Property<string>("CurrentState") b.Property<string>("CurrentState")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("nvarchar(max)") .HasColumnType("nvarchar(max)")
.HasDefaultValue("Proposed"); .HasDefaultValueSql("Proposed");
b.Property<int?>("CustomerId") b.Property<int?>("CustomerId")
.HasColumnType("int"); .HasColumnType("int");
...@@ -553,32 +576,15 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -553,32 +576,15 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
}); });
}); });
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b => modelBuilder.Entity("PSManagement.Domain.Customers.Entities.ContactInfo", b =>
{ {
b.OwnsMany("PSManagement.Domain.Customers.Entities.ContactInfo", "ContactInfo", b1 => b.HasOne("PSManagement.Domain.Customers.Entities.Customer", null)
{ .WithMany("ContactInfo")
b1.Property<int>("CustomerId")
.HasColumnType("int");
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b1.Property<string>("ContactType")
.HasColumnType("nvarchar(max)");
b1.Property<string>("ContactValue")
.HasColumnType("nvarchar(max)");
b1.HasKey("CustomerId", "Id");
b1.ToTable("ContactInfo");
b1.WithOwner()
.HasForeignKey("CustomerId"); .HasForeignKey("CustomerId");
}); });
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b =>
{
b.OwnsOne("PSManagement.Domain.Customers.ValueObjects.Address", "Address", b1 => b.OwnsOne("PSManagement.Domain.Customers.ValueObjects.Address", "Address", b1 =>
{ {
b1.Property<int>("CustomerId") b1.Property<int>("CustomerId")
...@@ -598,10 +604,6 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -598,10 +604,6 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.HasColumnType("int") .HasColumnType("int")
.HasColumnName("StreetNumber"); .HasColumnName("StreetNumber");
b1.Property<int>("ZipCode")
.HasColumnType("int")
.HasColumnName("ZipCode");
b1.HasKey("CustomerId"); b1.HasKey("CustomerId");
b1.ToTable("Customers"); b1.ToTable("Customers");
...@@ -611,8 +613,6 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -611,8 +613,6 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
}); });
b.Navigation("Address"); b.Navigation("Address");
b.Navigation("ContactInfo");
}); });
modelBuilder.Entity("PSManagement.Domain.Employees.Entities.Employee", b => modelBuilder.Entity("PSManagement.Domain.Employees.Entities.Employee", b =>
...@@ -1181,6 +1181,8 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -1181,6 +1181,8 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b => modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b =>
{ {
b.Navigation("ContactInfo");
b.Navigation("Projects"); b.Navigation("Projects");
}); });
......
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