From 15a1af43ee8646de985b3392c735542929ff903d Mon Sep 17 00:00:00 2001 From: Ashraful Haque Date: Thu, 18 Feb 2021 14:10:39 +0000 Subject: [PATCH] added games controller --- Controllers/GamesController.cs | 43 ++++++++++++++++++++++++ Controllers/WeatherForecastController.cs | 19 +++++++++++ Models/Games.cs | 9 +++++ 3 files changed, 71 insertions(+) create mode 100644 Controllers/GamesController.cs create mode 100644 Models/Games.cs diff --git a/Controllers/GamesController.cs b/Controllers/GamesController.cs new file mode 100644 index 0000000..827eaf0 --- /dev/null +++ b/Controllers/GamesController.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using TestApplication.Models; + +namespace TestApplication.Controllers +{ + [ApiController] + [Route("[controller]")] + public class GamesController : ControllerBase + { + public static List GetGames() + { + List games = new List(); + games.Add(new Games(){Id = 1, Name = "Game 1", Price = 10}); + games.Add(new Games(){Id = 2, Name = "Game 2", Price = 15}); + games.Add(new Games(){Id = 3, Name = "Game 3", Price = 20}); + games.Add(new Games(){Id = 4, Name = "Game 4", Price = 25}); + games.Add(new Games(){Id = 5, Name = "Game 5", Price = 30}); + return games; + } + + [HttpGet] + public IEnumerable GetGames_List() + { + return GetGames(); + } + + [HttpGet("{id}")] + public ActionResult GetGames_ById(int id) + { + var games = GetGames().Find(x => x.Id == id); + if(games != null) + { + return games; + } + else + { + return NotFound(); + } + } + } +} \ No newline at end of file diff --git a/Controllers/WeatherForecastController.cs b/Controllers/WeatherForecastController.cs index 10261b2..b2e36da 100644 --- a/Controllers/WeatherForecastController.cs +++ b/Controllers/WeatherForecastController.cs @@ -36,5 +36,24 @@ namespace TestApplication.Controllers }) .ToArray(); } + + [HttpGet("list")] + public IEnumerable Get_List() + { + return Summaries.ToList(); + } + + [HttpGet("list/{id}")] + public string Get_list_byId(int id) + { + if(id < 0 || id > Summaries.Length - 1) + { + return new string("not found"); + } + else + { + return Summaries[id]; + } + } } } diff --git a/Models/Games.cs b/Models/Games.cs new file mode 100644 index 0000000..c98f93e --- /dev/null +++ b/Models/Games.cs @@ -0,0 +1,9 @@ +namespace TestApplication.Models +{ + public class Games + { + public int Id { get; set; } + public string Name { get; set; } + public int Price { get; set; } + } +} \ No newline at end of file