Last active
November 29, 2019 13:43
-
-
Save MarcoNicolodi/8a827ea32b42adfb09de8d9ceda789c8 to your computer and use it in GitHub Desktop.
Proposal before being
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Proposal : Entity | |
{ | |
public Guid CandidateId { get; } | |
public Guid JobListingId { get; } | |
public ProposaStatus Status { get; private set; } | |
public DateTime? ClosedAt { get; private set; } | |
public Proposal(Guid candidateId, Guid jobListingId) | |
{ | |
CandidateId = candidateId; | |
JobListingId = jobListingId; | |
Status = ProprosalStatus.Open; | |
} | |
public void Accept() | |
{ | |
ChangeStatus(ProposalStatus.Accepted); | |
base.EventsRaised.Add(new ProposalAcceptedEvent(proposal.Id, proposal.AcceptedAt)) | |
} | |
public void Deny() | |
{ | |
ChangeStatus(ProposalStatus.Denied); | |
base.EventsRaised.Add(new ProposalDeniedEvent(proposal.Id, proposal.AcceptedAt)) | |
} | |
private void ChangeStatus(ProposalStatus newStatus) | |
{ | |
if(DateTime.Now.Substract(proprosal.SentAt).TotalDays > 15) | |
throw new DomainException("This proprosal has expired"); | |
if(Status != ProposalStatus.Pending) | |
throw new DomainException("Cannot accept or deny this proposal"); | |
Status = newStatus; | |
ClosedAt = DateTime.Now; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment