Ejemplo n.º 1
0
        public static IForm <MessageModel> BuildForm()
        {
            return(new FormBuilder <MessageModel>()
                   .Message("Welcome to ChatCode")
                   .Field(nameof(AnalysisText))
                   .Field(nameof(Email))
                   .Field(nameof(Age))
                   .Field(nameof(Gender))
                   .Field(nameof(Description))
                   .Field(nameof(Image))
                   .Field(nameof(Facebook))
                   .Field(nameof(Twitter))
                   .Field(nameof(LinkedIn))
                   .Field(nameof(IsPublish))
                   .Field(nameof(Star))
                   .OnCompletion(async(context, state) =>
            {
                var client = new DataClient();

                if (state.IsPublish == PublishEnum.Yes)
                {
                    var analysis = new CreateAnalysisModel()
                    {
                        Text = state.AnalysisText
                    };

                    var textAnalaysisKeyword = await client.RequestAnalysis(analysis);

                    var model = new CreateAboutMeModel()
                    {
                        Email = state.Email,
                        NameSurname = MessagesController.UserName,
                        Age = "23",
                        Gender = state.Gender.Value.ToString(),
                        Description = state.Description,
                        ImageUrl = "image-url",
                        Background = "#ffffff",
                        Foreground = "#000000",
                        AnalysisText = textAnalaysisKeyword
                    };

                    var response = await client.SendInformation(model);

                    if (response.IsSuccess == true)
                    {
                        await context.PostAsync("https://chatcode.blob.core.windows.net/chatcodecontainer/aboutme.html");

                        var social = new CreateSocialMediaModel()
                        {
                            Email = state.Email,
                            Facebook = state.Facebook,
                            Twitter = state.Twitter,
                            LinkedIn = state.LinkedIn
                        };
                        var socialResponse = client.AddSocialMedia(social);

                        int websiteId = Convert.ToInt32(socialResponse.Result.Message);
                        var star = new CreateStartModel()
                        {
                            WebsiteId = websiteId,
                            Rate = (int)state.Star.Value
                        };

                        await context.PostAsync("https://chatcode.blob.core.windows.net/chatcodecontainer/aboutme.html");
                    }

                    else
                    {
                        await context.PostAsync("https://chatcode.blob.core.windows.net/chatcodecontainer/aboutme.html");
                    }
                }

                else
                {
                    await context.PostAsync("You gave up");
                }
            })
                   .Build());
        }