Commit 4b446462 authored by hasan khaddour's avatar hasan khaddour

update some entity

parent 4ea3732a
using System;
using PSManagement.Application.Contracts.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -7,10 +8,11 @@ using System.Threading.Tasks;
namespace PSManagement.Contracts.Authentication
{
public record AuthenticationResponse(
int Id ,
int EmployeeId ,
String FirstName,
String LastName ,
String Email ,
ICollection<RoleDTO> Roles,
String Token
);
}
......@@ -5,6 +5,8 @@
string TeamLeaderName,
string DepartmentName,
string ProposerName,
int? ProjectManagerId,
int? TeamLeaderId,
int? PageNumber,
int? PagerSize);
int? PageSize);
}
using PSManagement.SharedKernel.Events;
namespace PSManagement.Domain.Employees.DomainEvents
{
public record EmployeeWorkHoursChangedEvent(
int EmployeeId,
int CurrentWorkingHours,
int NewWorkinghours
) : IDomainEvent;
}
using PSManagement.Domain.Identity.Entities;
using PSManagement.Domain.Employees.DomainEvents;
using PSManagement.Domain.Identity.Entities;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Tracking;
using PSManagement.Domain.Tracking.Entities;
using PSManagement.SharedKernel.Aggregate;
using PSManagement.SharedKernel.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -37,5 +39,18 @@ namespace PSManagement.Domain.Employees.Entities
PersonalInfo = personalInfo;
HIASTId = hiastId;
}
public void UpdateWorkHours(int workingHour)
{
int currentWorkHours = Availability.CurrentWorkingHours;
// change the employee working hours
Availability = new(workingHour, Availability.IsAvailable);
// publish the events of changing the working hours
AddDomainEvent(new EmployeeWorkHoursChangedEvent(Id,currentWorkHours,workingHour));
}
}
}
......@@ -13,6 +13,7 @@ namespace PSManagement.Domain.Projects.DomainErrors
public static DomainError InvalidEntryError { get; } = new ("ProjectError.InvalidEntry.", "Invalid Project Data");
public static DomainError ParticipantExistError { get; } = new("ProjectError.Participant.Exist.", "the Project already have the given particpant Data");
public static DomainError ParticipantUnExistError { get; } = new("ProjectError.Participant.UnExist.", "the Project doesnt have the given particpant Data");
public static DomainError StateTracnsitionError (string from, string to) => new("ProjectError.StateTransitionError","you cannot change the project state from " +from +" to "+to);
}
}
using PSManagement.SharedKernel.Events;
namespace PSManagement.Domain.Projects.DomainEvents
{
public record ProjectCompletedEvent(
int ProjectId
) : IDomainEvent;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Domain.Projects.DomainEvents
{
class _
{
}
}
using PSManagement.Domain.Customers.Entities;
using Ardalis.Result;
using PSManagement.Domain.Customers.Entities;
using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.FinancialSpends.Entities;
using PSManagement.Domain.Projects.ValueObjects;
......@@ -16,16 +17,22 @@ namespace PSManagement.Domain.Projects.Entities
{
public class Project : IAggregateRoot
{
// information about the project itself
#region Project informations
public ProposalInfo ProposalInfo { get; set; }
public ProjectInfo ProjectInfo { get; set; }
public Aggreement ProjectAggreement { get; set; }
// state management
#endregion Project informations
#region Project State
public string CurrentState { get; private set; } // Persisted in the database
[NotMapped]
private IProjectState _state ;
[NotMapped]
public IProjectState State {
get {
......@@ -40,13 +47,21 @@ namespace PSManagement.Domain.Projects.Entities
set => _state = value;
}
#endregion Project State
// information about who lead and execute the project
#region Project Management Iformations
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; }
public FinancialFund FinancialFund { get; set; }
public ICollection<FinancialSpending> FinancialSpending { get; set; }
#endregion Project Management Iformations
// the proposer of the project
public int ProposerId { get; private set; }
......@@ -57,16 +72,22 @@ namespace PSManagement.Domain.Projects.Entities
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; }
public ICollection<Track> Tracks { get; set; }
public void AddAttachment(Attachment attachment) {
#region Encapsulating the collection operations
public void AddAttachment(Attachment attachment)
{
Attachments.Add(attachment);
}
public void AddAttachment(string attachmentUrl,string attachmentName,string attachmentDescription,int projectId)
{
Attachment attachment = new(attachmentUrl, attachmentName,attachmentDescription, projectId);
Attachments.Add(attachment);
......@@ -76,14 +97,43 @@ namespace PSManagement.Domain.Projects.Entities
FinancialSpending.Add(financialSpending);
}
public void AddStep(Step step)
{
Steps.Add(step);
}
#endregion Encapsulating the collection operations
#region State Transitions
public Result Complete()
{
return State.Complete(this);
}
public Result Plan()
{
return State.Plan(this);
}
public Result Approve(Aggreement projectAggreement)
{
return State.Approve(this, projectAggreement);
}
public Result Cancel(DateTime canellationTime)
{
return State.Cancel(this,canellationTime);
}
public Result Propose()
{
return State.Propose(this);
}
#endregion State Transitions
public Project(
ProposalInfo proposalInfo,
ProjectInfo projectInfo,
......@@ -92,7 +142,8 @@ namespace PSManagement.Domain.Projects.Entities
int teamLeaderId,
int projectManagerId,
int executerId,
string stateName)
string stateName
)
{
SetStateFromString(stateName);
ProposalInfo = proposalInfo;
......@@ -108,43 +159,20 @@ namespace PSManagement.Domain.Projects.Entities
Steps = new List<Step>();
Participants = new List<Employee>();
EmployeeParticipates = new List<EmployeeParticipate>();
}
public Project()
{
}
public void SetState(IProjectState newState)
{
_state = newState;
CurrentState = _state.StateName;
}
public void Complete()
{
State.Complete(this);
}
public void Plan()
{
State.Plan(this);
}
public void Approve(Aggreement projectAggreement)
{
State.Approve(this,projectAggreement);
}
public void Cancel(DateTime canellationTime)
{
State.Cancel(this,canellationTime);
}
public void Propose()
{
State.Propose(this);
CurrentState = _state.StateName;
}
#region state extracting from state name
public void SetStateFromString(string stateName)
{
switch (stateName)
......@@ -168,7 +196,7 @@ namespace PSManagement.Domain.Projects.Entities
throw new InvalidOperationException("Unknown state");
}
}
#endregion state extracting from state name
}
}
using PSManagement.Domain.Projects.ValueObjects;
using Ardalis.Result;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities
......@@ -7,29 +9,29 @@ namespace PSManagement.Domain.Projects.Entities
{
public string StateName => "CancledState";
public void Approve(Project project, Aggreement projectAggreement)
public Result Approve(Project project, Aggreement projectAggreement)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Cancelled","Approved"));
}
public void Cancel(Project project, DateTime canellationTime)
public Result Cancel(Project project, DateTime canellationTime)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Cancelled", "Cancelled"));
}
public void Complete(Project project)
public Result Complete(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Cancelled", "Completed"));
}
public void Plan(Project project)
public Result Plan(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Cancelled", "Plan"));
}
public void Propose(Project project)
public Result Propose(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Cancelled", "Proposed"));
}
}
}
using PSManagement.Domain.Projects.ValueObjects;
using Ardalis.Result;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities
......@@ -7,28 +9,30 @@ namespace PSManagement.Domain.Projects.Entities
{
public string StateName => "Completed";
public void Approve(Project project, Aggreement projectAggreement)
public Result Approve(Project project, Aggreement projectAggreement)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Approved", "Approved"));
}
public void Cancel(Project project, DateTime canellationTime)
public Result Cancel(Project project, DateTime canellationTime)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Approved", "Cancelled"));
}
public void Complete(Project project)
public Result Complete(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Approved", "Completed"));
}
public void Plan(Project project)
public Result Plan(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Approved", "InPlan"));
}
public void Propose(Project project)
public Result Propose(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Approved", "Proposed"));
}
}
......
using PSManagement.Domain.Projects.ValueObjects;
using Ardalis.Result;
using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities
{
public interface IProjectState
{
void Complete(Project project);
void Plan(Project project);
void Approve(Project project, Aggreement projectAggreement);
void Cancel(Project project, DateTime canellationTime);
void Propose(Project project);
Result Complete(Project project);
Result Plan(Project project);
Result Approve(Project project, Aggreement projectAggreement);
Result Cancel(Project project, DateTime canellationTime);
Result Propose(Project project);
string StateName { get; }
}
......
using PSManagement.Domain.Projects.DomainEvents;
using Ardalis.Result;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.ValueObjects;
using System;
......@@ -8,32 +10,38 @@ namespace PSManagement.Domain.Projects.Entities
{
public string StateName => "InPlan";
public void Approve(Project project, Aggreement projectAggreement)
public Result Approve(Project project, Aggreement projectAggreement)
{
project.ProjectAggreement = projectAggreement;
project.AddDomainEvent(new ProjectApprovedEvent(project.Id,projectAggreement));
project.SetState(new InProgressState());
return Result.Success();
}
public void Cancel(Project project, DateTime canellationTime)
public Result Cancel(Project project, DateTime canellationTime)
{
project.AddDomainEvent(new ProjectCancelledEvent(project.Id,DateTime.Now));
project.SetState(new CancledState());
return Result.Success();
}
public void Complete(Project project)
public Result Complete(Project project)
{
project.AddDomainEvent(new ProjectCompletedEvent(project.Id));
project.SetState(new CompletedState());
return Result.Success();
}
public void Plan(Project project)
public Result Plan(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("In Plainning ", "In Planning"));
}
public void Propose(Project project)
public Result Propose(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Approved", "Proposed"));
}
}
......
using PSManagement.Domain.Projects.DomainEvents;
using Ardalis.Result;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.ValueObjects;
using System;
......@@ -8,30 +10,36 @@ namespace PSManagement.Domain.Projects.Entities
{
public string StateName => "InProgress";
public void Approve(Project project, Aggreement projectAggreement)
public Result Approve(Project project, Aggreement projectAggreement)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("InProgress", "Approved"));
}
public void Cancel(Project project, DateTime canellationTime)
public Result Cancel(Project project, DateTime canellationTime)
{
project.AddDomainEvent(new ProjectCancelledEvent(project.Id,canellationTime));
project.SetState(new CancledState());
return Result.Success();
}
public void Complete(Project project)
public Result Complete(Project project)
{
project.AddDomainEvent(new ProjectCompletedEvent(project.Id));
project.SetState(new CompletedState());
return Result.Success();
}
public void Plan(Project project)
public Result Plan(Project project)
{
project.SetState(new InPlanState());
return Result.Success();
}
public void Propose(Project project)
public Result Propose(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("InProgress", "Proposed"));
}
}
}
using PSManagement.Domain.Projects.ValueObjects;
using Ardalis.Result;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities
......@@ -7,29 +10,34 @@ namespace PSManagement.Domain.Projects.Entities
{
public string StateName => "Proposed";
public void Approve(Project project, Aggreement projectAggreement)
public Result Approve(Project project, Aggreement projectAggreement)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Proposed", "Approved"));
}
public void Cancel(Project project, DateTime canellationTime)
public Result Cancel(Project project, DateTime canellationTime)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Proposed", "Canceled"));
}
public void Complete(Project project)
public Result Complete(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Proposed", "Completed"));
}
public void Plan(Project project)
public Result Plan(Project project)
{
return Result.Invalid(ProjectsErrors.StateTracnsitionError("Propose", "In Planing"));
}
public void Propose(Project project)
public Result Propose(Project project)
{
project.SetState(new InPlanState());
return Result.Success();
}
}
......
......@@ -3,7 +3,7 @@ using System;
namespace PSManagement.Domain.Tracking.DomainEvents
{
public record TrackCompleteddEvent(
public record TrackCompletedEvent(
int ProjectId,
int TrackId,
DateTime Date) : IDomainEvent;
......
......@@ -31,7 +31,7 @@ namespace PSManagement.Domain.Tracking
{
TrackInfo = new (TrackInfo.TrackDate,true,TrackInfo.StatusDescription);
AddDomainEvent(new TrackCompleteddEvent(ProjectId, Id, completionDate));
AddDomainEvent(new TrackCompletedEvent(ProjectId, Id, completionDate));
}
}
......
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