public Task <bool> UpdateOrder(Pizza pizza) { var old = _order.Pizza.SingleOrDefault(x => x.Id == pizza.Id); if (old != null) { old.Status = pizza.Status; } if (old != null) { _logger.LogInformation($"Order has been updated new status {old.Status}"); } var orderStateMachine = new OrderStateMachine(_order); if (orderStateMachine.CanFire(Trigger.UpdateOrder) && _order.Status <= Status.ReadyForDelivery) { orderStateMachine.Fire(Trigger.UpdateOrder); UpdateOrderForAPI(_order); } if (_order.Status == Status.Delivering) { if (orderStateMachine.CanFire(Trigger.UpdateOrder)) { orderStateMachine.Fire(Trigger.UpdateOrder); if (_order.Status != Status.Delivered) { UpdateOrderForAPI(_order); } else { UpdateOrderForAPI(_order, false); } } if (_order.Status == Status.Delivered) { UpdateOrderForAPI(_order); _logger.LogInformation($"Order Was delivered"); //try //{ // base.ClearStateAsync(); //} //catch (Exception e) //{ // _logger.LogError($"Exception clearing the grain storage: {e}"); //} } } _logger.LogInformation($"Order status {_order.Status}"); return(Task.FromResult(true)); }
Task <string> IHello.SayHello(string greeting) { var order = new Order { Status = Status.Started }; var orderStateMachine = new OrderStateMachine(order); orderStateMachine.Fire(Trigger.UpdateOrder); _logger.LogInformation($"SayHello message received: greeting = '{greeting}'"); return(Task.FromResult($"You said: '{greeting}', I say: Hello! {order.Status}")); }