diff --git a/Weiferl.Api/Controllers/HelloWorldController.cs b/Weiferl.Api/Controllers/HelloWorldController.cs deleted file mode 100644 index c1845ec..0000000 --- a/Weiferl.Api/Controllers/HelloWorldController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Weiferl.Databas.EF; -using Weiferl.Databas.EF.Models; - -namespace WeiFerL.Api.Controllers -{ - [ApiController] - [Route("api")] - public class HelloWorldController : ControllerBase - { - private HardwareShopContext _dbContext = new HardwareShopContext(); - - [HttpGet("helloworld")] - public IActionResult Get() - { - return Ok("Hello World"); - } - [HttpGet("pups")] - public IActionResult GetAll() - { - var gk = _dbContext.Hersteller.ToList(); - return Ok(gk); - } - - } -} diff --git a/Weiferl.Api/Controllers/Users.cs b/Weiferl.Api/Controllers/Users.cs index f012699..d69bd3d 100644 --- a/Weiferl.Api/Controllers/Users.cs +++ b/Weiferl.Api/Controllers/Users.cs @@ -29,6 +29,20 @@ namespace Weiferl.Api.Controllers } } + [HttpGet("getUser")] + public async Task GetUsers() + { + try + { + var user = await userRepo.GetUser(1); + return Ok(user); + } + catch (Exception ex) + { + return BadRequest(ex); + } + } + [HttpPost("addUser")] public async Task AddUser() { @@ -40,6 +54,8 @@ namespace Weiferl.Api.Controllers Birthday = new DateTime(1986, 01, 17), Email = "marcus@weifer.de", IsDeleted = false, + RegisterDate = DateTime.Now, + CountrySlug = "DE" }; try diff --git a/Weiferl.Api/Program.cs b/Weiferl.Api/Program.cs index 2b4ac80..6e820fc 100644 --- a/Weiferl.Api/Program.cs +++ b/Weiferl.Api/Program.cs @@ -23,5 +23,5 @@ app.UseAuthorization(); app.MapControllers(); -//app.Run("http://192.168.0.57:3045"); +//app.Run("http://192.168.0.57:3045"); //Linux Server app.Run(); diff --git a/Weiferl.Api/Repos/UserRepo.cs b/Weiferl.Api/Repos/UserRepo.cs index aa38143..6ff129a 100644 --- a/Weiferl.Api/Repos/UserRepo.cs +++ b/Weiferl.Api/Repos/UserRepo.cs @@ -6,18 +6,18 @@ namespace Weiferl.Api.Repos { public class UserRepo { - readonly private HardwareShopContext dbContext; + readonly private WeiferlDb dbContext; public UserRepo() { - this .dbContext = new HardwareShopContext(); + this .dbContext = new WeiferlDb(); } public async Task CreateUser(User user) { try { - dbContext.User.Add(user); + dbContext.Users.Add(user); dbContext.SaveChanges(); } catch (Exception ex) @@ -29,7 +29,7 @@ namespace Weiferl.Api.Repos { try { - var user = dbContext.User.FirstOrDefault(u => u.Id == id); + var user = dbContext.Users.FirstOrDefault(u => u.Id == id); return user; } catch (Exception ex) @@ -38,11 +38,11 @@ namespace Weiferl.Api.Repos } } - public async Task> GetAllUsers() + public async Task> GetAllUsers() { try { - var users = dbContext.User.ToList(); + var users = await dbContext.Users.ToListAsync(); return users; } catch (Exception ex) @@ -52,7 +52,7 @@ namespace Weiferl.Api.Repos } public async Task UpdateUser(User updatedUser, int id) { - var user = await dbContext.User.FindAsync(id); + var user = await dbContext.Users.FindAsync(id); if(user != null) { @@ -61,6 +61,7 @@ namespace Weiferl.Api.Repos user.Birthday = updatedUser.Birthday; user.Email = updatedUser.Email; user.IsDeleted = updatedUser.IsDeleted; + user.CountrySlug = updatedUser.CountrySlug; } try { @@ -73,13 +74,13 @@ namespace Weiferl.Api.Repos } public async Task RemoveUser(int id) { - var user = await dbContext.User.FindAsync(id); + var user = await dbContext.Users.FindAsync(id); if(user != null) { user.Firstname = "Deleted"; user.Lastname = "User"; - user.Birthday = DateTime.Now; + user.Birthday = null; user.Email = "@@@"; user.IsDeleted = true; } diff --git a/Weiferl.Api/Weiferl.Api.csproj b/Weiferl.Api/Weiferl.Api.csproj index 24d7612..c5f8fbe 100644 --- a/Weiferl.Api/Weiferl.Api.csproj +++ b/Weiferl.Api/Weiferl.Api.csproj @@ -12,7 +12,7 @@ - +