diff --git a/practise-05.slnx b/practise-05.slnx new file mode 100644 index 0000000..a8ccac0 --- /dev/null +++ b/practise-05.slnx @@ -0,0 +1,3 @@ + + + diff --git a/practise-05/Controllers/DeveloperController.cs b/practise-05/Controllers/DeveloperController.cs new file mode 100644 index 0000000..e503ef6 --- /dev/null +++ b/practise-05/Controllers/DeveloperController.cs @@ -0,0 +1,81 @@ +using Microsoft.AspNetCore.Mvc; + +namespace practise_05.Controllers +{ + [ApiController] + [Route("[controller]")] + public class DeveleperController : ControllerBase + { + private static List developerList = new List() + { + new Developer { + Id= "b8878c6c-eda2-35ee-f621-91f9b7af14dc", + Name="Kiss Lajos", + Email="KissLajos@nikuni.hu", + Job="Frontend Developer", + Age=35, + Salary=350000, + Image="https://randomuser.me/api/portraits/men/1.jpg", + Skills= new string[] { + + "User Research", + "Wireframing", + "Prototyping", + "Figma", + "Sketch", + "Interaction Design", + "Visual Design" + }, + } + }; + private static string next = "asdasd"; + + [HttpGet("/getAllDevelopers")] + public ActionResult> Get() + { + return Ok(developerList); + } + [HttpGet("/getDeveloperById/{id}")] + public ActionResult GetDeveloper(string id) + { + return Ok(developerList.First(x => x.Id == id)); + } + [HttpPost("/CreateDeveloper")] + public IActionResult PostDeveloper([FromBody] DeveloperPost developer) + { + Developer ffgh = new Developer(); + ffgh.Id = next; + ffgh.Name = developer.Name; + ffgh.Email = developer.Email; + ffgh.Job = developer.Job; + ffgh.Age = developer.Age; + ffgh.Salary = developer.Salary; + ffgh.Image = developer.Image; + ffgh.Skills = developer.Skills; + + developerList.Add(ffgh); + next = next + "asd"; + return Created(); + } + + [HttpPut("/updateDeveloper/{id}")] + public IActionResult UpdateDev([FromBody] DeveloperPost developer, string id) + { + developerList = developerList.Where(x => x.Id != id).ToList(); + Developer ffgh = new Developer(); + ffgh.Id = id; + ffgh.Name = developer.Name; + ffgh.Email = developer.Email; + ffgh.Job = developer.Job; + ffgh.Age = developer.Age; + ffgh.Salary = developer.Salary; + ffgh.Image = developer.Image; + ffgh.Skills = developer.Skills; + + developerList.Add(ffgh); + return CreatedAtAction(nameof(GetDeveloper), new {id = id}, ffgh); + } + + + } +} diff --git a/practise-05/Controllers/WeatherForecastController.cs b/practise-05/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..93ba675 --- /dev/null +++ b/practise-05/Controllers/WeatherForecastController.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.Mvc; + +namespace practise_05.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + + } +} diff --git a/practise-05/Developer.cs b/practise-05/Developer.cs new file mode 100644 index 0000000..aa85b71 --- /dev/null +++ b/practise-05/Developer.cs @@ -0,0 +1,41 @@ +namespace practise_05 +{ + public class Developer + { + string id; + string name; + string email; + string job; + int age; + int salary; + string image; + string[] skills; + + public string Id { get => id; set => id = value; } + public string Name { get => name; set => name = value; } + public string Email { get => email; set => email = value; } + public string Job { get => job; set => job = value; } + public int Age { get => age; set => age = value; } + public int Salary { get => salary; set => salary = value; } + public string Image { get => image; set => image = value; } + public string[] Skills { get => skills; set => skills = value; } + } + + public class DeveloperPost + { + string name; + string email; + string job; + int age; + int salary; + string image; + string[] skills; + public string Name { get => name; set => name = value; } + public string Email { get => email; set => email = value; } + public string Job { get => job; set => job = value; } + public int Age { get => age; set => age = value; } + public int Salary { get => salary; set => salary = value; } + public string Image { get => image; set => image = value; } + public string[] Skills { get => skills; set => skills = value; } + } +} diff --git a/practise-05/Program.cs b/practise-05/Program.cs new file mode 100644 index 0000000..cee4854 --- /dev/null +++ b/practise-05/Program.cs @@ -0,0 +1,45 @@ + +namespace practise_05 +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi + builder.Services.AddOpenApi(); + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) + { + app.MapOpenApi(); + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.UseHttpsRedirection(); + + app.UseAuthorization(); + + app.UseCors(x => + { + x.AllowCredentials(); + x.WithOrigins("http://127.0.0.1:5500"); + x.AllowAnyMethod(); + x.AllowAnyHeader(); + + }); + app.MapControllers(); + + app.Run(); + } + } +} diff --git a/practise-05/Properties/launchSettings.json b/practise-05/Properties/launchSettings.json new file mode 100644 index 0000000..063af78 --- /dev/null +++ b/practise-05/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5188", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7163;http://localhost:5188", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/practise-05/WeatherForecast.cs b/practise-05/WeatherForecast.cs new file mode 100644 index 0000000..2495a07 --- /dev/null +++ b/practise-05/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace practise_05 +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/practise-05/appsettings.Development.json b/practise-05/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/practise-05/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/practise-05/appsettings.json b/practise-05/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/practise-05/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/practise-05/practise-05.csproj b/practise-05/practise-05.csproj new file mode 100644 index 0000000..1eebc5d --- /dev/null +++ b/practise-05/practise-05.csproj @@ -0,0 +1,15 @@ + + + + net9.0 + enable + enable + practise_05 + + + + + + + + diff --git a/practise-05/practise-05.http b/practise-05/practise-05.http new file mode 100644 index 0000000..cbd781a --- /dev/null +++ b/practise-05/practise-05.http @@ -0,0 +1,6 @@ +@practise_05_HostAddress = http://localhost:5188 + +GET {{practise_05_HostAddress}}/weatherforecast/ +Accept: application/json + +###