public Result <CustomerQueue> RevokeCustomer(CounterName counterName) =>
 AvailableCounters.GetMaybeServingTicket(counterName)
 .OnSuccess(maybeServingTicket => maybeServingTicket.Map(
                servingTicket => ApplyChange(new CustomerRevoked(Id, counterName, servingTicket.Id))))
 .ToTypedResult(this);
 private void ApplyCustomerServedIfTicketIsBeingServed(Maybe <Ticket> maybeServingTicket, CounterName counterName) =>
 maybeServingTicket.Map(t => ApplyChange(new CustomerServed(Id, counterName, t.Id)));
 private void ApplyCustomerTakenIfThereIsPendingTicketInTheQueue(CounterName counterName) =>
 QueuedTickets.MaybeNextTicket.Map(t => ApplyChange(new CustomerTaken(Id, counterName, QueuedTickets.MaybeNextTicket.Value.Id)));
 public Result <CustomerQueue> AddCounter(CounterName counterName) =>
 AvailableCounters.CheckIfCounterIsAvailableWith(counterName)
 .OnSuccess(() => ApplyChange(new CounterAdded(Id, counterName)))
 .ToTypedResult(this);
 public Result <CustomerQueue> TakeNextCustomer(CounterName counterName) => AvailableCounters
 .GetMaybeServingTicket(counterName)
 .OnSuccess(maybeServingTicketId => ApplyCustomerServedIfTicketIsBeingServed(maybeServingTicketId, counterName))
 .OnSuccess(_ => ApplyCustomerTakenIfThereIsPendingTicketInTheQueue(counterName))
 .ToTypedResult(this);
Example #6
0
 public AvailableCounters RemoveServingTicket(CounterName counterName)
 {
     Counters.MaybeEntityWith(counterName).Value.RemoveServingTicket();
     return(this);
 }
Example #7
0
 public AvailableCounters SetServingTicketFor(CounterName counterName, Ticket t)
 {
     Counters.MaybeEntityWith(counterName).Value.SetServingTicket(t);
     return(this);
 }
Example #8
0
 public Result <Maybe <Ticket> > GetMaybeServingTicket(CounterName counterName) => Counters.MaybeEntityWith(counterName)
 .Unwrap(
     m => Ok(m.MaybeServingTicket),
     () => Fail <Maybe <Ticket> >($"{nameof(Counter)} with name '{counterName}' doesn't exist."));
Example #9
0
 public AvailableCounters AddNewWith(CounterName counterName) => new AvailableCounters(new List <Counter>(Counters)
 {
     new Counter(counterName)
 });
Example #10
0
 public Result CheckIfCounterIsAvailableWith(CounterName counterName) => Counters.ContainsEntityWith(counterName).OnBoth(
     () => Fail($"{nameof(Counter)} with name '{counterName}' already exists in {nameof(CustomerQueue)}."),
     Ok);