예제 #1
0
파일: RecipeDialog.cs 프로젝트: Fanuer/HIS
        private async Task HandleGetRecipeStep(IDialogContext context, StepDirection direction)
        {
            try
            {
                int           recipeId = -1;
                StepViewModel step     = null;
                var           stepId   = 0;

                if (!context.UserData.TryGetValue(Userdata_RecipeId, out recipeId))
                {
                    throw new RecipeIdNotFoundException();
                }

                if (!context.UserData.TryGetValue(Userdata_StepId, out stepId))
                {
                    stepId = -1;
                }

                using (var client = new GatewayClient())
                {
                    step = await client.GetStepAsync(recipeId, stepId, direction);
                }

                if (step == null)
                {
                    await context.PostAsync(Resources.Message_Error_UnableToReceiveStep);
                }
                else
                {
                    context.UserData.SetValue(Userdata_StepId, step.Id);
                    await context.PostAsync($"{Resources.Message_Step} {step.Order + 1} {Resources.Message_of} {step.TotalSteps} {Resources.Message_Steps}:{Bot_NewLine}{step.Description}");

                    if (step.Order + 1 >= step.TotalSteps)
                    {
                        await context.PostAsync(Resources.Message_CookingCompleted);
                    }
                }
            }
            catch (RecipeIdNotFoundException e)
            {
                await context.PostAsync(Resources.Message_Error_RecipeMustBeSelectedFirst);
            }
        }