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);
public AvailableCounters RemoveServingTicket(CounterName counterName) { Counters.MaybeEntityWith(counterName).Value.RemoveServingTicket(); return(this); }
public AvailableCounters SetServingTicketFor(CounterName counterName, Ticket t) { Counters.MaybeEntityWith(counterName).Value.SetServingTicket(t); return(this); }
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."));
public AvailableCounters AddNewWith(CounterName counterName) => new AvailableCounters(new List <Counter>(Counters) { new Counter(counterName) });
public Result CheckIfCounterIsAvailableWith(CounterName counterName) => Counters.ContainsEntityWith(counterName).OnBoth( () => Fail($"{nameof(Counter)} with name '{counterName}' already exists in {nameof(CustomerQueue)}."), Ok);