update nuget

This commit is contained in:
Marcus Ferl 2023-07-09 12:03:37 +02:00
parent f64af6e0af
commit 26de83bc8a
5 changed files with 28 additions and 37 deletions

View File

@ -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);
}
}
}

View File

@ -29,6 +29,20 @@ namespace Weiferl.Api.Controllers
} }
} }
[HttpGet("getUser")]
public async Task<IActionResult> GetUsers()
{
try
{
var user = await userRepo.GetUser(1);
return Ok(user);
}
catch (Exception ex)
{
return BadRequest(ex);
}
}
[HttpPost("addUser")] [HttpPost("addUser")]
public async Task<IActionResult> AddUser() public async Task<IActionResult> AddUser()
{ {
@ -40,6 +54,8 @@ namespace Weiferl.Api.Controllers
Birthday = new DateTime(1986, 01, 17), Birthday = new DateTime(1986, 01, 17),
Email = "marcus@weifer.de", Email = "marcus@weifer.de",
IsDeleted = false, IsDeleted = false,
RegisterDate = DateTime.Now,
CountrySlug = "DE"
}; };
try try

View File

@ -23,5 +23,5 @@ app.UseAuthorization();
app.MapControllers(); app.MapControllers();
//app.Run("http://192.168.0.57:3045"); //app.Run("http://192.168.0.57:3045"); //Linux Server
app.Run(); app.Run();

View File

@ -6,18 +6,18 @@ namespace Weiferl.Api.Repos
{ {
public class UserRepo public class UserRepo
{ {
readonly private HardwareShopContext dbContext; readonly private WeiferlDb dbContext;
public UserRepo() public UserRepo()
{ {
this .dbContext = new HardwareShopContext(); this .dbContext = new WeiferlDb();
} }
public async Task CreateUser(User user) public async Task CreateUser(User user)
{ {
try try
{ {
dbContext.User.Add(user); dbContext.Users.Add(user);
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
catch (Exception ex) catch (Exception ex)
@ -29,7 +29,7 @@ namespace Weiferl.Api.Repos
{ {
try try
{ {
var user = dbContext.User.FirstOrDefault(u => u.Id == id); var user = dbContext.Users.FirstOrDefault(u => u.Id == id);
return user; return user;
} }
catch (Exception ex) catch (Exception ex)
@ -38,11 +38,11 @@ namespace Weiferl.Api.Repos
} }
} }
public async Task<IEnumerable<User>> GetAllUsers() public async Task<List<User>> GetAllUsers()
{ {
try try
{ {
var users = dbContext.User.ToList(); var users = await dbContext.Users.ToListAsync();
return users; return users;
} }
catch (Exception ex) catch (Exception ex)
@ -52,7 +52,7 @@ namespace Weiferl.Api.Repos
} }
public async Task UpdateUser(User updatedUser, int id) 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) if(user != null)
{ {
@ -61,6 +61,7 @@ namespace Weiferl.Api.Repos
user.Birthday = updatedUser.Birthday; user.Birthday = updatedUser.Birthday;
user.Email = updatedUser.Email; user.Email = updatedUser.Email;
user.IsDeleted = updatedUser.IsDeleted; user.IsDeleted = updatedUser.IsDeleted;
user.CountrySlug = updatedUser.CountrySlug;
} }
try try
{ {
@ -73,13 +74,13 @@ namespace Weiferl.Api.Repos
} }
public async Task RemoveUser(int id) public async Task RemoveUser(int id)
{ {
var user = await dbContext.User.FindAsync(id); var user = await dbContext.Users.FindAsync(id);
if(user != null) if(user != null)
{ {
user.Firstname = "Deleted"; user.Firstname = "Deleted";
user.Lastname = "User"; user.Lastname = "User";
user.Birthday = DateTime.Now; user.Birthday = null;
user.Email = "@@@"; user.Email = "@@@";
user.IsDeleted = true; user.IsDeleted = true;
} }

View File

@ -12,7 +12,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.8" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.8" />
<PackageReference Include="MySql.EntityFrameworkCore" Version="7.0.2" /> <PackageReference Include="MySql.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Weiferl.Databas.EF" Version="1.0.2" /> <PackageReference Include="Weiferl.Databas.EF" Version="1.0.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>