Esempio n. 1
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.");
            });
        }
Esempio n. 2
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);
            });
        }
        public IActionResult Index()
        {
            StringBuilder results = new StringBuilder();
            SortedDictionary <SelectedGame, int> voteLista = _pollResults.GetVoteResult();

            foreach (var gameVotes in voteLista)
            {
                results.Append($"Game name: {gameVotes.Key}, Votes: {gameVotes.Value}{Environment.NewLine}");
            }

            return(Content(results.ToString()));
        }
Esempio n. 4
0
 public IActionResult Index()
 {
     if (Request.Query.ContainsKey("submitted"))
     {
         StringBuilder results = new StringBuilder();
         SortedDictionary <SelectedGame, int> voteList = _pollResults.GetVoteResult();
         foreach (var gameVotes in voteList)
         {
             results.Append($"Game name: {gameVotes.Key}. Votes: {gameVotes.Value}{Environment.NewLine}");
         }
         return(Content(results.ToString()));
     }
     else
     {
         return(Redirect("poll-questions.html"));
     }
 }
Esempio n. 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)
        {
            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);
            });
        }
Esempio n. 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)
        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!");
            });
        }