Commit bf203fbc authored by hasan khaddour's avatar hasan khaddour

refator some entities

parent 4f8f60d1
......@@ -5,6 +5,8 @@ using PSManagement.Application.Employees.Common;
using PSManagement.Application.FinancialSpends.Common;
using PSManagement.Application.FinancialSpends.UseCases.Commands.CreateFinancialSpendItem;
using PSManagement.Application.Projects.Common;
using PSManagement.Application.Projects.UseCases.Commands.CompleteProgressProject;
using PSManagement.Application.ProjectsTypes.UseCases.Commands.CreateNewType;
using PSManagement.Application.Tracks.Common;
using PSManagement.Application.Tracks.UseCaes.Commands.AddEmployeeTrack;
using PSManagement.Application.Tracks.UseCaes.Commands.AddStepTrack;
......@@ -41,12 +43,6 @@ namespace PSManagement.Application.Mappers
.ForMember(e => e.Email, op => op.MapFrom(e => e.User.Email))
;
CreateMap< EmployeeParticipate, EmployeeParticipateDTO>()
.ForMember(d => d.ProjectInfo, opt => opt.MapFrom(s => s.Project.ProjectInfo))
.ForMember(d => d.Employee, op => op.MapFrom(e => e.Employee))
;
CreateMap<StepTrack, StepTrackDTO>()
.ForMember(d => d.StepInfo, opt => opt.MapFrom(s => s.Step.StepInfo))
.ForMember(d => d.TrackInfo, op => op.MapFrom(e => e.Track.TrackInfo))
......@@ -54,30 +50,60 @@ namespace PSManagement.Application.Mappers
CreateMap<EmployeeTrack, EmployeeTrackDTO>()
.ForMember(d => d.TrackInfo, op => op.MapFrom(e => e.Track.TrackInfo))
;
CreateMap<Project, ProjectInfo>()
.ConvertUsing(project => project.ProjectInfo);
CreateMap<Track, TrackDTO>()
.ForMember(e => e.ProjectInfo , op =>op.MapFrom(s => s.Project.ProjectInfo))
;
CreateMap<CreateTrackCommand, Track>().ReverseMap();
CreateMap<AddEmployeeTrackCommand, EmployeeTrack>().ReverseMap();
CreateMap<AddStepTrackCommand, StepTrack>()
.ForMember(e => e.OldExecutionRatio, op => op.Ignore());
CreateMap<FinancialSpendingDTO, FinancialSpending>().ReverseMap();
CreateMap<Role,RoleDTO>().ReverseMap();
}
}
public class ProjectDTOMapperConfiguration : Profile {
public ProjectDTOMapperConfiguration()
{
CreateMap<Project, ProjectDTO>().ReverseMap();
CreateMap<Project, ProjectDetailsDTO>().ReverseMap();
CreateMap<Project, ProjectInfo>()
.ConvertUsing(project => project.ProjectInfo);
CreateMap<CreateFinancialSpendItemCommand,FinancialSpending> ()
.ForMember(d=>d.Id, op => op.Ignore())
.ForMember(d=> d.Events, op => op.Ignore())
CreateMap<EmployeeParticipate, EmployeeParticipateDTO>()
.ForMember(d => d.ProjectInfo, opt => opt.MapFrom(s => s.Project.ProjectInfo))
.ForMember(d => d.Employee, op => op.MapFrom(e => e.Employee))
;
CreateMap<CreateNewTypeCommand, ProjectType>();
CreateMap<UpdateTypeCommand, ProjectType>();
CreateMap <CompleteProjectCommand, ProjectCompletion>();
}
}
public class FinanialSpendingDTOMapperConfiguration : Profile {
public FinanialSpendingDTOMapperConfiguration()
{
CreateMap<FinancialSpendingDTO, FinancialSpending>().ReverseMap();
CreateMap<CreateFinancialSpendItemCommand, FinancialSpending>()
.ForMember(d => d.Id, op => op.Ignore())
.ForMember(d => d.Events, op => op.Ignore())
.ConstructUsing(src => new FinancialSpending(
src.ProjectId,
src.LocalPurchase,
......@@ -88,8 +114,6 @@ namespace PSManagement.Application.Mappers
))
;
CreateMap<Role,RoleDTO>().ReverseMap();
}
}
......
......@@ -16,21 +16,37 @@ namespace PSManagement.Application.DI
{
public static IServiceCollection AddApplication(this IServiceCollection services)
{
//services.AddMediatR();
services.AddMyMediatR()
.AddMappers();
return services;
}
private static IServiceCollection AddMyMediatR(this IServiceCollection services) {
services.AddMediatR(typeof(DependencyInjection).Assembly);
// Register the pipeline behaviors explicitly
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
// Register FluentValidation validators
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
return services;
}
private static IServiceCollection AddMappers(this IServiceCollection services)
{
services.AddAutoMapper(cfg => {
cfg.AddProfile<MapperConfiguration>();
cfg.AddProfile<ProjectDTOMapperConfiguration>();
cfg.AddProfile<FinanialSpendingDTOMapperConfiguration>();
});
return services;
}
......
......@@ -20,4 +20,8 @@ namespace PSManagement.Application.Employees.Common
public Availability Availability { get; set; }
}
public class DepartmentDTO {
public int Id { get; set; }
public String Name { get; set; }
}
}
......@@ -12,4 +12,6 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetAvailableEmploy
public record GetAvailableEmployeesQuery (
int? PageNumber,
int? PageSize) : IQuery<Result<IEnumerable<EmployeeDTO>>>;
}
using Ardalis.Result;
using PSManagement.Application.Employees.Common;
using PSManagement.SharedKernel.CQRS.Query;
using System.Collections.Generic;
namespace PSManagement.Application.Employees.UseCases.Queries.GetDepartments
{
public record GetDepartmentsQuery(
) : IQuery<Result<IEnumerable<DepartmentDTO>>>;
}
using Ardalis.Result;
using AutoMapper;
using PSManagement.Application.Employees.Common;
using PSManagement.Domain.Employees.Entities;
using PSManagement.SharedKernel.CQRS.Query;
using PSManagement.SharedKernel.Repositories;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Employees.UseCases.Queries.GetDepartments
{
public class GetDepartmentsQueryHandler : IQueryHandler<GetDepartmentsQuery, Result<IEnumerable<DepartmentDTO>>>
{
private readonly IRepository<Department> _deparmentsRepository;
private readonly IMapper _mapper;
public GetDepartmentsQueryHandler(IMapper mapper, IRepository<Department> deparmentsRepository)
{
_mapper = mapper;
_deparmentsRepository = deparmentsRepository;
}
public async Task<Result<IEnumerable<DepartmentDTO>>> Handle(GetDepartmentsQuery request, CancellationToken cancellationToken)
{
var result = await _deparmentsRepository.ListAsync();
return Result.Success(_mapper.Map<IEnumerable<DepartmentDTO>>(result));
}
}
}
......@@ -5,12 +5,6 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>
<ItemGroup>
<Folder Include="Behaviors\AuthorizationBehavior\" />
<Folder Include="Projects\UseCases\Commands\ChangeParticiptionInfo\" />
<Folder Include="Tracks\UseCaes\Queries\GetUncompletedTracks\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="5.0.1" />
......
......@@ -17,6 +17,7 @@ namespace PSManagement.Application.Projects.Common
public ProjectClassification ProjectClassification { get; set; }
public ProjectInfo ProjectInfo { get; set; }
public ProjectTypeDTO ProjectType { get; set; }
public int ProjectTypeId { get; set; }
public string CurrentState { get; set; }
public Aggreement ProjectAggreement { get; set; }
public int TeamLeaderId { get; set; }
......
using Ardalis.Result;
using PSManagement.SharedKernel.CQRS.Command;
namespace PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManager
{
public record ChangeEmployeeParticipationCommand(
int ParticipantId,
int ProjectId,
int PartialTimeRation,
string Role
) : ICommand<Result>;
}
using Ardalis.Result;
using PSManagement.Domain.Employees.Repositories;
using PSManagement.Domain.Projects;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
using PSManagement.SharedKernel.Interfaces;
using PSManagement.SharedKernel.Specification;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Projects.UseCases.Commands.ChangeProjectManager
{
public class ChangeEmployeeParticipationCommandHandler : ICommandHandler<ChangeEmployeeParticipationCommand, Result>
{
private readonly IProjectsRepository _projectsRepository;
private readonly BaseSpecification<Project> _specification;
private readonly IUnitOfWork _unitOfWork;
public ChangeEmployeeParticipationCommandHandler(
IProjectsRepository projectsRepository,
IUnitOfWork unitOfWork,
IEmployeesRepository employeesRepository)
{
_projectsRepository = projectsRepository;
_unitOfWork = unitOfWork;
_specification = new ProjectSpecification();
}
public async Task<Result> Handle(ChangeEmployeeParticipationCommand request, CancellationToken cancellationToken)
{
_specification.AddInclude(e => e.EmployeeParticipates);
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId,_specification);
if (project is null)
{
return Result.Invalid(ProjectsErrors.InvalidEntryError);
}
else
{
if (!project.HasParticipant(request.ParticipantId)) {
return Result.Invalid(ProjectsErrors.ParticipantUnExistError);
}
project.ChangeParticipant(request.ParticipantId,request.PartialTimeRation,request.Role);
await _unitOfWork.SaveChangesAsync();
return Result.Success();
}
}
}
}
......@@ -18,6 +18,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
int TeamLeaderId ,
int ProjectManagerId,
int ProposerId,
int ExecuterId
int ExecuterId,
int ProjectTypeId
) : ILoggableCommand<Result<int>>;
}
using Ardalis.Result;
using PSManagement.Application.Projects.Common;
using PSManagement.Domain.Projects.Builders;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
......@@ -14,6 +15,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
public class CreateProjectCommandHandler : ICommandHandler<CreateProjectCommand, Result<int>>
{
private readonly IProjectsRepository _projectsRepository;
private readonly IProjectTypesRepository _projectTypesRepository;
private readonly ProjectBuilder _projectBuilder;
private readonly IUnitOfWork _unitOfWork;
......@@ -21,15 +23,23 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
public CreateProjectCommandHandler(
IProjectsRepository projectsRepository,
ProjectBuilder projectBuilder,
IUnitOfWork unitOfWork)
IUnitOfWork unitOfWork, IProjectTypesRepository projectTypesRepository)
{
_projectsRepository = projectsRepository;
_projectBuilder = projectBuilder;
_unitOfWork = unitOfWork;
_projectTypesRepository = projectTypesRepository;
}
public async Task<Result<int>> Handle(CreateProjectCommand request, CancellationToken cancellationToken)
{
var type = await _projectTypesRepository.GetByIdAsync(request.ProjectTypeId);
if (type is null) {
return Result.Invalid(PrjectTypesErrors.InvalidEntryError);
}
Project project = _projectBuilder
.WithProjectAggreement(request.ProjectAggreement)
.WithProjectInfo(request.ProjectInfo)
......@@ -41,23 +51,17 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
.WithProposer(request.ProposerId)
.WithClassification(request.ProjectClassification)
.Build();
project.ProjectTypeId = request.ProjectTypeId;
project.Propose();
project =await _projectsRepository.AddAsync(project);
CreateProjectResult response = new (
project.Id,
project.ProposalInfo,
project.ProjectInfo,
project.ProjectAggreement,
project.TeamLeaderId,
project.ProjectManagerId,
project.ExecuterId
);
project.AddDomainEvent(new ProjectCreatedEvent(project.Id,project.TeamLeaderId,project.ProjectManagerId));
await _unitOfWork.SaveChangesAsync();
return Result.Success(response.ProjectId);
return Result.Success(project.Id);
}
}
......
using PSManagement.Domain.Projects.ValueObjects;
namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
{
public record CreateProjectResult(
int ProjectId,
ProposalInfo ProposalInfo ,
ProjectInfo ProjectInfo,
Aggreement ProjectAggrement,
int TeamLeaderId ,
int ProjectManagerId,
int ExecuterId
);
}
......@@ -37,6 +37,8 @@ namespace PSManagement.Application.Projects.UseCases.Queries.GetProject
_specification.Includes.Add(p => p.Executer);
_specification.Includes.Add(p => p.Proposer);
_specification.Includes.Add(p => p.ProjectType);
var project = await _projectRepository.GetByIdAsync(request.ProjectId,_specification);
......
......@@ -4,6 +4,7 @@ using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -26,7 +27,7 @@ namespace PSManagement.Application.ProjectsTypes.UseCases.Commands.CreateNewType
{
var result = await _projectTypesRepository.GetByTypeName(request.TypeName);
if (result is not null)
if (result.Count() !=0 )
{
return Result.Invalid(PrjectTypesErrors.InvalidName);
}
......
......@@ -4,6 +4,7 @@ using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -24,12 +25,12 @@ namespace PSManagement.Application.ProjectsTypes.UseCases.Commands.CreateNewType
public async Task<Result> Handle(UpdateTypeCommand request, CancellationToken cancellationToken)
{
var result = await _projectTypesRepository.GetByTypeName(request.TypeName);
//var result = await _projectTypesRepository.GetByTypeName(request.TypeName);
if (result is not null)
{
return Result.Invalid(PrjectTypesErrors.InvalidEntryError);
}
//if (result is null || result.Count()==0)
//{
// return Result.Invalid(PrjectTypesErrors.InvalidEntryError);
//}
var projectType = await _projectTypesRepository.UpdateAsync(_mapper.Map<ProjectType>(request));
......
......@@ -34,7 +34,7 @@ namespace PSManagement.Application.ProjectsTypes.UseCases.Queries.GetProjectsTyp
result = new List<ProjectType>();
}
return Result.Success(_mapper.Map<Result<IEnumerable<ProjectTypeDTO>>>(result)); ;
return Result.Success(_mapper.Map<IEnumerable<ProjectTypeDTO>>(result)); ;
}
}
}
......@@ -23,7 +23,7 @@ namespace PSManagement.Application.ProjectsTypes.UseCases.Queries.GetTypeById
_mapper = mapper;
}
public async Task<Result<ProjectTypeDTO>> Handle(GetProjectsTypesQuery request, CancellationToken cancellationToken)
public async Task<Result<ProjectTypeDTO>> Handle(GetTypeByIdQuery request, CancellationToken cancellationToken)
{
var result = await _projectTypesRepository.ListAsync();
......@@ -33,7 +33,7 @@ namespace PSManagement.Application.ProjectsTypes.UseCases.Queries.GetTypeById
return Result.Invalid(PrjectTypesErrors.InvalidEntryError);
}
return Result.Success(_mapper.Map<Result<ProjectTypeDTO>>(result)); ;
return Result.Success(_mapper.Map<ProjectTypeDTO>(result)); ;
}
}
}
......@@ -14,4 +14,6 @@ namespace PSManagement.Application.Tracks.UseCaes.Queries.GetTracksByProject
int? PageSize
) : IQuery<Result<IEnumerable<TrackDTO>>>;
}
using Ardalis.Result;
using PSManagement.Application.Tracks.Common;
using PSManagement.SharedKernel.CQRS.Query;
using System.Collections.Generic;
namespace PSManagement.Application.Tracks.UseCaes.Queries.GetUncompletedTracks
{
public record GetUnCompletedTracksQuery(
) : IQuery<Result<IEnumerable<TrackDTO>>>;
}
using Ardalis.Result;
using AutoMapper;
using PSManagement.Application.Tracks.Common;
using PSManagement.Domain.Steps.Repositories;
using PSManagement.Domain.Tracking;
using PSManagement.Domain.Tracking.Specification;
using PSManagement.SharedKernel.CQRS.Query;
using PSManagement.SharedKernel.Specification;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Tracks.UseCaes.Queries.GetUncompletedTracks
{
public class GetUnCompletedTracksQueryHandler : IQueryHandler<GetUnCompletedTracksQuery, Result<IEnumerable<TrackDTO>>>
{
private readonly ITracksRepository _tracksRepository;
private readonly IMapper _mapper;
private readonly BaseSpecification<Track> _specification;
public GetUnCompletedTracksQueryHandler(
IMapper mapper,
ITracksRepository tracksRepository)
{
_mapper = mapper;
_tracksRepository = tracksRepository;
_specification = new TrackSpecification();
}
public async Task<Result<IEnumerable<TrackDTO>>> Handle(GetUnCompletedTracksQuery request, CancellationToken cancellationToken)
{
_specification.Criteria = c => c.TrackInfo.IsCompleted == false;
var tracks = await _tracksRepository.ListAsync(_specification);
return Result.Success(_mapper.Map<IEnumerable<TrackDTO>>(tracks));
}
}
}
......@@ -13,4 +13,9 @@ namespace PSManagement.Contracts.Projects.Response
public Availability Availability { get; set; }
public WorkInfo WorkInfo { get; set; }
}
public record DepartmentResponse (
int Id ,
string Name
);
}
\ No newline at end of file
namespace PSManagement.Contracts.Projects.Requests
{
public record ChangeEmployeeParticipationRequest(
int ParticipantId,
int ProjectId,
int PartialTimeRation,
string Role
);
}
using System;
namespace PSManagement.Contracts.Projects.Requests
{
public record CompleteProjectRequest(
int ProjectId,
DateTime CompletionDate,
String CustomerNotes,
int CustomerRate
);
}
......@@ -15,5 +15,6 @@ namespace PSManagement.Contracts.Projects.Requests
int TeamLeaderId,
int ProjectManagerId,
int ProposerId,
int ExecuterId);
int ExecuterId,
int ProjectTypeId);
}
using System;
namespace PSManagement.Contracts.Projects.Response
{
public class ProjectCompletionResponse
{
public int Id { get; set; }
public int ProjectId { get; set; }
public ProjectResponse Project { get; set; }
public DateTime CompletionDate { get; set; }
public String CustomerNotes { get; set; }
public int CustomerRate { get; set; }
}
}
using PSManagement.Contracts.Customers.Responses;
using PSManagement.Contracts.ProjectsTypes.Request;
using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.ValueObjects;
......@@ -12,15 +13,17 @@ namespace PSManagement.Contracts.Projects.Response
public ProposalInfo ProposalInfo { get; set; }
public ProjectInfo ProjectInfo { get; set; }
public string CurrentState { get; set; }
public ProjectTypeResponse ProjectType { get; set; }
public Aggreement ProjectAggreement { get; set; }
public int TeamLeaderId { get; set; }
public int ProjecTypeId { get; set; }
public ProjectClassification ProjectClassification { get; set; }
public EmployeeResponse TeamLeader { get; set; }
public int ProjectManagerId { get; set; }
public EmployeeResponse ProjectManager { get; set; }
public int ExecuterId { get; set; }
public Department Executer { get; set; }
public DepartmentResponse Executer { get; set; }
public int ProposerId { get; private set; }
public CustomerResponse Proposer { get; set; }
......@@ -33,5 +36,4 @@ namespace PSManagement.Contracts.Projects.Response
public ICollection<EmployeeParticipateResponse> EmployeeParticipates { get; set; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Contracts.ProjectsTypes.Request
{
public record CreateNewTypeRequest(
string TypeName,
string Description,
int ExpectedEffort
);
}
namespace PSManagement.Contracts.ProjectsTypes.Request
{
public record UpdateTypeRequest(
int Id,
string TypeName,
string Description,
int ExpectedEffort
);
}
namespace PSManagement.Contracts.ProjectsTypes.Request
{
public record ProjectTypeResponse(
int Id,
string TypeName ,
string Description,
int ExpectedEffort
);
}
......@@ -14,9 +14,26 @@ namespace PSManagement.Domain.Customers.Entities
public string CustomerName { get; set; }
public Address Address { get; set; }
public string Email { get; set; }
#region Association
public ICollection<ContactInfo> ContactInfo { get; private set; }
public ICollection<Project> Projects { get; private set; }
#endregion Association
#region Encapsulation
public void AddContactInfo(ContactInfo contactInfo)
{
if (ContactInfo is null)
{
ContactInfo = new List<ContactInfo>();
}
ContactInfo.Add(contactInfo);
}
#endregion Encapsulation
#region Constructors
public Customer()
{
......@@ -29,15 +46,8 @@ namespace PSManagement.Domain.Customers.Entities
Email = email;
}
public void AddContactInfo(ContactInfo contactInfo)
{
if (ContactInfo is null)
{
ContactInfo = new List<ContactInfo>();
}
ContactInfo.Add(contactInfo);
#endregion Construtors
}
}
}
......@@ -22,13 +22,19 @@ namespace PSManagement.Domain.Employees.Entities
public Department Department { get; set; }
public PersonalInfo PersonalInfo { get; set; }
public WorkInfo WorkInfo { get; set; }
public Availability Availability { get; set; }
#region Asscociation
public ICollection<Project> Projects { get; set; }
public ICollection<EmployeeTrack> EmployeeTracks { get; set; }
public Availability Availability { get; set; }
public ICollection<EmployeeParticipate> EmployeeParticipates { get; set; }
#endregion Asscociation
#region Constructors
public Employee()
{
......@@ -39,9 +45,12 @@ namespace PSManagement.Domain.Employees.Entities
PersonalInfo = personalInfo;
HIASTId = hiastId;
}
#endregion Constructors
public void UpdateWorkHours(int workingHour)
{
int currentWorkHours = Availability.CurrentWorkingHours;
// change the employee working hours
......
......@@ -6,7 +6,14 @@ namespace PSManagement.Domain.FinancialSpends.Entities
{
public class FinancialSpending : BaseEntity
{
public int ProjectId { get; set; }
public DateTime ExpectedSpendingDate { get; set; }
public string CostType { get; set; }
public string Description { get; set; }
public int LocalPurchase { get; set; }
public Money ExternalPurchase { get; set; }
#region Constructors
public FinancialSpending()
{
......@@ -27,14 +34,7 @@ namespace PSManagement.Domain.FinancialSpends.Entities
Description = description;
ExpectedSpendingDate = expectedSpendingDate;
}
public int ProjectId { get; set; }
public DateTime ExpectedSpendingDate { get; set; }
public string CostType { get; set; }
public string Description { get; set; }
public int LocalPurchase { get; set; }
public Money ExternalPurchase { get; set; }
#endregion Constructors
}
......
......@@ -11,6 +11,9 @@ using System.Threading.Tasks;
namespace PSManagement.Domain.Projects.Builders
{
// this class repsponsible for crate and instance of the project
// we use this class to give and uniform interface to the other layer to get
// instance as it like
public class ProjectBuilder
{
private ProposalInfo _proposalInfo;
......@@ -18,7 +21,6 @@ namespace PSManagement.Domain.Projects.Builders
private FinancialFund _financialFund;
private Aggreement _projectAggreement;
private ProjectType _projectType;
// information about who lead and execute the project
private int _teamLeaderId;
private int _projectManagerId;
private int _executerId;
......
using PSManagement.SharedKernel.Events;
using System;
namespace PSManagement.Domain.Projects.DomainEvents
{
public record ParticipationChanged(
int ParticipantId,
int PartialTimeRatioBefore,
int PartialTimeRatioAfter,
string RoleBefore ,
string RoleAfter ,
int ProjectId,
DateTime DateTime
) :IDomainEvent;
}
......@@ -8,6 +8,8 @@ namespace PSManagement.Domain.Projects.Entities
public string AttachmentUrl { get; set; }
public string AttachmentName { get; set; }
public string AttachmentDescription { get; set; }
#region Constructors
public Attachment(string attachmentUrl, string attachmentName, string attachmentDescription, int projectId)
{
AttachmentUrl = attachmentUrl;
......@@ -15,6 +17,7 @@ namespace PSManagement.Domain.Projects.Entities
AttachmentDescription = attachmentDescription;
ProjectId = projectId;
}
#endregion Constructors
}
}
......@@ -12,6 +12,8 @@ namespace PSManagement.Domain.Projects.Entities
public Project Project { get; set; }
public int PartialTimeRatio { get; set; }
public string Role { get; set; }
#region Constructors
public EmployeeParticipate(int employeeId, int projectId, string role, int partialTimeRatio)
{
EmployeeId = employeeId;
......@@ -23,5 +25,6 @@ namespace PSManagement.Domain.Projects.Entities
{
}
#endregion Constuctors
}
}
......@@ -20,16 +20,46 @@ namespace PSManagement.Domain.Projects.Entities
{
// information about the project itself
#region Project informations
// the proposal information
// -- hide the details of the proposing in a value object
// -- conatain the proposing book and date
public ProposalInfo ProposalInfo { get; set; }
// the value object project info
// -- hide the subjective info of the project
// -- conatin code ,name , start and expect end date
public ProjectInfo ProjectInfo { get; set; }
// the aggremenet information value object
// -- hide the details of the aggrement in a value object
// -- conatain the aggrement book and date
public Aggreement ProjectAggreement { get; set; }
// the type of the project
public int ProjectTypeId { get; set; }
public ProjectType ProjectType { get; set; }
public ProjectCompletion ProjectCompletion { get; set; }
// the classiccation information of the project
public ProjectClassification ProjectClassification { get; set; }
#endregion Project informations
// the completion information of the project
#region Completion
// -- its an associated entity contain the details of the completion of the project
public ProjectCompletion ProjectCompletion { get; set; }
#endregion Completion
// the current state (phase) of the project
// its control the behavior of the project
#region Project State
public string CurrentState { get; private set; } // Persisted in the database
......@@ -63,24 +93,37 @@ namespace PSManagement.Domain.Projects.Entities
public Employee ProjectManager { get; set; }
public int ExecuterId { get; set; }
public Department Executer { get; set; }
#endregion Project Management Iformations
// the financial inforamtion
#region Financial fund and plan
public FinancialFund FinancialFund { get; set; }
public ICollection<FinancialSpending> FinancialSpending { get; set; }
#endregion Project Management Iformations
#endregion Financial fund and plan
// the proposer of the project
#region Project Proposer
public int ProposerId { get; private set; }
public Customer Proposer { get; set; }
//
#endregion Project Proposer
// the steps and paticipand and attachment
#region Execution Plaining
public ICollection<Step> Steps { get; set; }
public ICollection<Employee> Participants { get; set; }
public ICollection<Attachment> Attachments { get; set; }
#endregion Execution Plaining
#region Association
public ICollection<EmployeeParticipate> EmployeeParticipates { get; set; }
public ICollection<Track> Tracks { get; set; }
#endregion Association
#region Encapsulating the collection operations
......@@ -119,6 +162,11 @@ namespace PSManagement.Domain.Projects.Entities
#endregion Encapsulating the collection operations
// the transition of the project state
// each handler (stated transition) move the project state form one ot other
// its hide the actual behavior
#region State Transitions
public Result Complete(ProjectCompletion projectCompletion)
......@@ -153,6 +201,12 @@ namespace PSManagement.Domain.Projects.Entities
}
#endregion State Transitions
// validating data
// this methods help to hide the buissness rules
// and encapsulate it
#region Busines rules validators
public bool VailedSteps()
{
int weightSum = 0;
......@@ -162,10 +216,27 @@ namespace PSManagement.Domain.Projects.Entities
return weightSum == 100;
}
public void ChangeParticipant(int participantId, int partialTimeRation, string role)
{
var participate = EmployeeParticipates.Where(e => e.EmployeeId == participantId).FirstOrDefault();
AddDomainEvent(new ParticipationChanged(
participantId,
participate.PartialTimeRatio,partialTimeRation,
role,participate.Role, Id, DateTime.Now));
participate.Role = role;
participate.PartialTimeRatio = partialTimeRation;
}
public bool HasParticipant(int participantId)
{
return EmployeeParticipates.Where(e => e.EmployeeId ==participantId).FirstOrDefault() is not null;
}
#endregion Busines rules validators
// the constructor
// thsi is mainly use by the builder of the project
#region constructors
public Project(
......@@ -206,7 +277,7 @@ namespace PSManagement.Domain.Projects.Entities
#endregion constructors
// the methds responsible for extract the state when load the object for Data Store
#region state extracting from state name
public void SetStateFromString(string stateName)
{
......@@ -232,6 +303,7 @@ namespace PSManagement.Domain.Projects.Entities
}
}
#endregion state extracting from state name
}
}
......@@ -15,14 +15,15 @@ namespace PSManagement.Domain.Projects.Entities
{
public StepInfo StepInfo { get; set; }
// this field can be calculated from the track
// but we use it for performance matter
public int CurrentCompletionRatio { get; set; }
public int Weight { get; set; }
public int ProjectId { get; set; }
public Project Project { get; set; }
public ICollection<StepTrack> StepTracks { get; set; }
#region Constructors
public Step()
{
......@@ -35,6 +36,8 @@ namespace PSManagement.Domain.Projects.Entities
ProjectId = projectId;
Weight = weight;
}
#endregion Constructors
}
}
......@@ -8,7 +8,6 @@ namespace PSManagement.Domain.Projects.Repositories
{
public interface IProjectTypesRepository : IRepository<ProjectType>
{
public Task<IEnumerable<Project>> GetProjectsByTypeName(string typeName, ISpecification<ProjectType> specification=null);
public Task<IEnumerable<ProjectType>> GetByTypeName(string typeName, ISpecification<ProjectType> specification=null);
}
......
......@@ -18,15 +18,26 @@ namespace PSManagement.Domain.Tracking
public TrackInfo TrackInfo { get; set; }
public String Notes { get; set; }
public int ProjectId { get; set; }
public Project Project { get; set; }
public Project Project { get; set; }
public ICollection<StepTrack> StepTracks { get; set; }
public ICollection<Employee> TrackedEmployees { get; set; }
public ICollection<EmployeeTrack> EmployeeTracks { get; set; }
#region Association
public ICollection<Employee> TrackedEmployees { get; set; }
#endregion Association
#region Constructors
public Track()
{
}
#endregion Constructors
// this method hide the publishing of the domain events
public void Complete(DateTime completionDate)
{
TrackInfo = new (TrackInfo.TrackDate,true,TrackInfo.StatusDescription);
......
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