Exemple #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IPollResultsService pollResults)
        {
            app.Use(async(context, next) =>
            {
                if (context.Request.Query.ContainsKey("favorite"))
                {
                    string selectedValue      = context.Request.Query["favorite"];
                    SelectedGame selectedGame = (SelectedGame)Enum.Parse(typeof(SelectedGame), selectedValue, true);
                    pollResults.AddVote(selectedGame);

                    await context.Response.WriteAsync($"Thank you for submitting the poll.");
                }
                else
                {
                    await next.Invoke();
                }
            });

            app.UseStaticFiles();

            app.UseMvcWithDefaultRoute();

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("This text was generated by the app.Run middleware. wwwroot folder path: " + env.WebRootPath);
            });
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IPollResultsService pollResults)
        {
            app.Use(async(context, next) =>
            {
                if (context.Request.Query.ContainsKey("favorite"))
                {
                    string selectedValue      = context.Request.Query["favorite"];
                    SelectedGame selectedGame = (SelectedGame)Enum.Parse(typeof(SelectedGame), selectedValue, true);
                    pollResults.AddVote(selectedGame);
                    SortedDictionary <SelectedGame, int> gameVotes = pollResults.GetVoteResult();

                    foreach (KeyValuePair <SelectedGame, int> currentVote in gameVotes)
                    {
                        await context.Response.WriteAsync($"<div> Game name: {currentVote.Key}. Votes: {currentVote.Value} </div>");
                    }
                }
                else
                {
                    await next.Invoke();
                }
            });
            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("This text was generated by the app.Run middleware.");
            });
        }
Exemple #3
0
        //public void Configure(IApplicationBuilder app)
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IPollResultsService pollResults)
        {
            app.Use(async(context, next) =>
            {
                if (context.Request.Query.ContainsKey("favorite"))
                {
                    string selectedValue      = context.Request.Query["favorite"];
                    SelectedGame selectedGame = (SelectedGame)Enum.Parse(typeof(SelectedGame), selectedValue, true);
                    pollResults.AddVote(selectedGame);
                    //await context.Response.WriteAsync("Selected value is: " + selectedValue);
                    //SortedDictionary<SelectedGame, int> gameVotes = pollResults.GetVoteResult();

                    //foreach (KeyValuePair<SelectedGame, int> currentVote in gameVotes)
                    //{
                    //    await context.Response.WriteAsync($"<div> Game name: {currentVote.Key}. Votes: {currentVote.Value} </div>");
                    //}
                    context.Response.Headers.Add("content-type", "text/html");
                    await context.Response.WriteAsync("Thank you for submitting the poll. You may look at the poll results <a href='/?submitted=true'>Here</a>.");
                }
                else
                {
                    await next.Invoke();
                }
            });

            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();

            app.Run(async(context) =>
            {
                //await context.Response.WriteAsync("This text was generated by the app.Run middleware.");
                await context.Response.WriteAsync("This text was generated by the app.Run middleware. wwwroot folder path: " + env.WebRootPath);
            });
        }
Exemple #4
0
        public void Configure(IApplicationBuilder app,
                              Microsoft.AspNetCore.Hosting.IHostingEnvironment env, IPollResultsService pollResults)
        {
            app.Use(async(context, next) =>
            {
                if (context.Request.Query.ContainsKey("favorite"))
                {
                    string selectedValue      = context.Request.Query["favorite"];
                    SelectedGame selectedGame = (SelectedGame)System.Enum.Parse(typeof(SelectedGame), selectedValue, true);
                    pollResults.AddVote(selectedGame);
                    var gameVotes = pollResults.GetVoteResult();
                    foreach (var currentVote in gameVotes)
                    {
                        await context.Response.WriteAsync($"<div> Game name: {currentVote.Key}. Votes: {currentVote.Value} </div>");
                    }
                }
                else
                {
                    await next.Invoke();
                }
            });
            app.UseStaticFiles();

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("This text was generated by the app.Run middleware. wwwroot folder path: " + env.WebRootPath);
            });
        }
Exemple #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env, IPollResultsService pollResults)
        {
            app.UseStaticFiles();
            app.Use(async(context, next) =>
            {
                await context.Response.WriteAsync(
                    "This text was generated by the app.Run middleware. wwwroot folder path: "
                    + env.WebRootPath);
                string selectedValue      = context.Request.Query["favorite"];
                SelectedGame selectedGame = (SelectedGame)Enum
                                            .Parse(typeof(SelectedGame), selectedValue, true);
                pollResults.AddVote(selectedGame);
                await context.Response.WriteAsync("Selected value is: " + selectedValue);
            });

            app.UseRouting();
            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("This text was generated by the app.Run middleware.");
            });
        }
Exemple #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IPollResultsService pollResults)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvcWithDefaultRoute();


            app.Use(async(context, next) =>
            {
                if (context.Request.Query.ContainsKey("Favorite"))
                {
                    string selectedValue      = context.Request.Query["Favorite"];
                    SelectedGame selectedGame = (SelectedGame)Enum.Parse(typeof(SelectedGame), selectedValue);
                    pollResults.AddVote(selectedGame);
                    SortedDictionary <SelectedGame, int> gameVotes = pollResults.GetVoteResult();

                    foreach (KeyValuePair <SelectedGame, int> currentVote in gameVotes)
                    {
                        await context.Response.WriteAsync($"<p> Game name: {currentVote.Key}, Votes: {currentVote.Value} </p>");
                    }
                }
                else
                {
                    await next.Invoke();
                }
            });

            app.UseStaticFiles();

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Action was not handled by any middleware. App run is executing. wwwroot folder path: " + env.WebRootPath);
            });
        }
Exemple #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        //public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IPollResultsService pollResults)
        {
            app.Use(async(context, next) =>
            {
                if (context.Request.Query.ContainsKey("favorite"))
                {
                    string selectedValue      = context.Request.Query["favorite"];
                    SelectedGame selectedGame = (SelectedGame)Enum.Parse(typeof(SelectedGame), selectedValue, true);
                    pollResults.AddVote(selectedGame);
                    //await context.Response.WriteAsync("Selected value is: " + selectedValue);
                    SortedDictionary <SelectedGame, int> gameVotes = pollResults.GetVoteResult();

                    foreach (KeyValuePair <SelectedGame, int> currentVote in gameVotes)
                    {
                        await context.Response.WriteAsync($"<div> Game name: {currentVote.Key}. Votes: {currentVote.Value} </div>");
                    }
                    await context.Response.WriteAsync("This text was generated by the app.Run middleware. wwwroot folder path: " + env.WebRootPath);
                }
                else
                {
                    await next.Invoke();
                }
            });
            app.UseStaticFiles();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }


            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
 public HomeController(IPollResultsService pollResults)
 {
     _pollResults = pollResults;
 }
 public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, IPollResultsService pollResults)
 {
     app.Use(async(context, next) =>
     {
         if (context.Request.Query.ContainsKey("favorite"))
         {
             string selectedValue = context.Request.Query["favorite"];
             SelectedGame game    = (SelectedGame)Enum.Parse(typeof(SelectedGame), selectedValue, true);
             pollResults.AddVote(game);
             context.Response.Headers.Add("Content-Type", "text/html");
             await context.Response.WriteAsync("Thank you for submitting the poll. You may look at the poll results <a href='/?submitted=true'>Here</a>.");
         }
         else
         {
             await next.Invoke();
         }
     });
     app.UseStaticFiles();
     app.UseMvcWithDefaultRoute();
     app.Run(async(context) =>
     {
         await context.Response.WriteAsync("This text was generated by the app.Run middleware. wwwroot folder path: " + env.WebRootPath);
     });
 }
Exemple #10
0
 public HomeController(ILogger <HomeController> logger, IPollResultsService pollResults)
 {
     _logger      = logger;
     _pollResults = pollResults;
 }