Init
This commit is contained in:
30
AceJobAgency/Controllers/UserController.cs
Normal file
30
AceJobAgency/Controllers/UserController.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using AceJobAgency.Data;
|
||||
using AceJobAgency.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AceJobAgency.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class UserController(DataContext context, IConfiguration configuration) : Controller
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Register(User user)
|
||||
{
|
||||
var userExists = context.Users.Any(u => u.Email == user.Email);
|
||||
if (userExists)
|
||||
{
|
||||
return BadRequest("User with the same email already exists.");
|
||||
}
|
||||
|
||||
string passwordHash = BCrypt.Net.BCrypt.HashPassword(user.Password);
|
||||
|
||||
user.Password = passwordHash;
|
||||
user.Id = Guid.NewGuid().ToString();
|
||||
|
||||
await context.Users.AddAsync(user);
|
||||
await context.SaveChangesAsync();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
33
AceJobAgency/Controllers/WeatherForecastController.cs
Normal file
33
AceJobAgency/Controllers/WeatherForecastController.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AceJobAgency.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<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user