/// <summary>
        /// Makes the coffee safe by ensuring the correct state and context to start making coffee.
        /// </summary>
        /// <inheritdoc/>
        public BaseResponse MakeCoffeeSafe(MakeCoffeeRequest makeCoffeeRequest)
        {
            // if we are off or already running, stop the execution
            if (!this._coffeeMachine.IsOn)
            {
                return(new CoffeeMachineOfflineErrorResponse("make coffee"));
            }
            if (this._coffeeMachine.IsMakingCoffee)
            {
                return(new CoffeeMachineMakingCoffeeErrorResponse());
            }

            // if we are alerting, you cannot start making coffee, only turn off or descale.
            if (this.IsCurrentlyAlerting())
            {
                return(new CoffeeMachineAlertingErrorResponse("make coffee"));
            }

            var coffeeOptions = new CoffeeCreationOptions
            {
                AddMilk          = makeCoffeeRequest.AddMilk,
                NumEspressoShots = makeCoffeeRequest.NumberOfEspressoShots
            };

            Task.Run(async() => await this._coffeeMachine.MakeCoffeeAsync(coffeeOptions).ConfigureAwait(false));
            return(new MakeCoffeeResponse(15));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> StartMakingCoffeeAsync([FromBody] MakeCoffeeRequest request)
        {
            this._logger.LogInformation("Attempting to start making coffee with the machine.");
            BaseResponse response = this._coffeeMachineService.MakeCoffeeSafe(request);

            await this._auditService.AddAuditEntryForRequest(this.Request, response,
                                                             AuditActionType.MakeCoffee).ConfigureAwait(false);

            return(this.StatusCode(response.Status, response));
        }