public QueuedTickets AddFrom( TicketId ticketId, int ticketNumber, DateTime ticketPrintingTimestamp) => new QueuedTickets(new List <Ticket>(Tickets) { new Ticket(ticketId, ticketNumber, ticketPrintingTimestamp) });
public Result <CustomerQueue> AddTicket( TicketId ticketId, int ticketNumber) => QueuedTickets.CanAddFrom(ticketId, ticketNumber) .OnSuccess(() => ApplyChange(new TicketAdded(Id, ticketId, ticketNumber))) .OnSuccess(_ => AvailableCounters.MapFirstFree(counter => ApplyChange(new CustomerTaken(Id, counter.Id, ticketId)))) .ToTypedResult(this);
public Ticket GetWithId(TicketId ticketId) => Tickets.First(t => t.Id == ticketId);
public QueuedTickets RemoveWithId(TicketId ticketId) { return(new QueuedTickets(new List <Ticket>(Tickets .Where(t => t.Id != ticketId)))); }
private Result Validate(TicketId ticketId) => Tickets.ContainsEntityWith(ticketId).OnBoth( () => Fail <Ticket>($"{nameof(Ticket)} with Id {ticketId} already exist."), Ok);
public Result CanAddFrom(TicketId ticketId, int ticketNumber) => Validate(ticketId) .OnSuccess(() => Validate(ticketNumber));