ShoppingApp/Weifer.ShoppingApp.API/RestApi/CustomerApiController.cs
2024-02-25 13:22:48 +01:00

45 lines
1.4 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Weifer.Database.EF;
using Weifer.Database.EF.Entitys;
using Weifer.ShoppingApp.API.Controllers;
using Weifer.ShoppingApp.API.Models;
namespace Weifer.ShoppingApp.API.RestApi
{
[ApiController]
[Route("[controller]")]
public class CustomerApiController : ControllerBase
{
public readonly AuthenticationController authenticationController;
public readonly DatabaseContext dbContext;
public CustomerApiController(DatabaseContext dbContext)
{
authenticationController = new AuthenticationController();
this.dbContext = dbContext;
}
[HttpPost]
public async Task <IActionResult> CreateCustomer(CustomerDto customerDto)
{
if(customerDto == null)
{
return BadRequest();
}
var customer = new Customer
{
CustomerId = new Guid(),
FirstName = customerDto.FirstName,
LastName = customerDto.LastName,
Email = customerDto.Email,
PasswordHash = authenticationController.HashPassword(customerDto.Password),
CreatedOn = DateTime.UtcNow,
};
dbContext.Customers.Add(customer);
dbContext.SaveChanges();
return Ok(customerDto);
}
}
}