67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
namespace Helpdesk.Domain.Proposals;
|
|
|
|
public sealed class ProposalEvent
|
|
{
|
|
private ProposalEvent() { }
|
|
|
|
public ProposalEvent(Proposal proposal, ProposalEventType eventType, ProposalStatus? fromStatus, int actorId,
|
|
string? note, DateTime occurredAt)
|
|
{
|
|
Proposal = proposal;
|
|
EventType = eventType;
|
|
FromStatus = fromStatus;
|
|
ToStatus = proposal.Status;
|
|
ActorId = actorId;
|
|
Note = note;
|
|
OccurredAt = occurredAt;
|
|
}
|
|
|
|
public int Id { get; private set; }
|
|
public int ProposalId { get; private set; }
|
|
public Proposal Proposal { get; private set; } = null!;
|
|
public ProposalEventType EventType { get; private set; }
|
|
public ProposalStatus? FromStatus { get; private set; }
|
|
public ProposalStatus ToStatus { get; private set; }
|
|
public int ActorId { get; private set; }
|
|
public string? Note { get; private set; }
|
|
public DateTime OccurredAt { get; private set; }
|
|
}
|
|
|
|
public sealed class ProposalVote
|
|
{
|
|
private ProposalVote() { }
|
|
|
|
public ProposalVote(Proposal proposal, int userId, sbyte value, DateTime now)
|
|
{
|
|
ProposalId = proposal.Id;
|
|
UserId = userId;
|
|
SetValue(proposal, value, now);
|
|
}
|
|
|
|
public int ProposalId { get; private set; }
|
|
public int UserId { get; private set; }
|
|
public sbyte Value { get; private set; }
|
|
public DateTime VotedAt { get; private set; }
|
|
|
|
public void SetValue(Proposal proposal, sbyte value, DateTime now)
|
|
{
|
|
if (proposal.Id != ProposalId || !proposal.CanVote(UserId))
|
|
throw new InvalidOperationException("O návrhu nelze hlasovat.");
|
|
if (value is not (1 or -1))
|
|
throw new ArgumentOutOfRangeException(nameof(value));
|
|
if (Value == value)
|
|
return;
|
|
|
|
Value = value;
|
|
VotedAt = now;
|
|
}
|
|
}
|
|
|
|
public sealed class ProposalScore
|
|
{
|
|
public int ProposalId { get; private set; }
|
|
public decimal VotesFor { get; private set; }
|
|
public decimal VotesAgainst { get; private set; }
|
|
public decimal Score { get; private set; }
|
|
}
|