Created
October 15, 2019 01:26
-
-
Save MarcoNicolodi/fd8691488da15c3ad3a72dce320ec893 to your computer and use it in GitHub Desktop.
Proposal service with anemic domain, and no domain service
This file contains 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 ProposalService | |
{ | |
public void AcceptProposal(Guid proposalId) | |
{ | |
var proposal = _repository.Find(proposalId); | |
//calling Accept method instead of changing its properties | |
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"); | |
proposal.Status = newStatus; | |
proposal.ClosedAt = DateTime.Now; | |
_repository.Save(proposal); | |
var proposalsToDeny = _repository.FindOpenForCandidate(proposal.CandidateId); | |
foreach(var p in proposalsToDeny) | |
{ | |
p.Status = ProposalStatus.Denied; | |
p.ClosedAt = DateTime.Now; | |
_repository.Save(p); | |
} | |
_logger.Info($"Proposal {proposal.id} was accepted"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment