2024-02-25 13:22:48 +01:00
|
|
|
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]
|
2024-02-25 22:59:50 +01:00
|
|
|
[Route("api/[controller]")]
|
2024-02-25 13:22:48 +01:00
|
|
|
public class CustomerApiController : ControllerBase
|
|
|
|
{
|
|
|
|
public readonly AuthenticationController authenticationController;
|
|
|
|
public readonly DatabaseContext dbContext;
|
|
|
|
|
|
|
|
public CustomerApiController(DatabaseContext dbContext)
|
|
|
|
{
|
|
|
|
authenticationController = new AuthenticationController();
|
|
|
|
this.dbContext = dbContext;
|
|
|
|
}
|
2024-02-25 22:59:50 +01:00
|
|
|
[HttpPost("add")]
|
|
|
|
public async Task<IActionResult> CreateCustomer(CustomerDto customerDto)
|
|
|
|
{
|
|
|
|
if (customerDto == null)
|
2024-02-25 13:22:48 +01:00
|
|
|
{
|
|
|
|
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();
|
2024-02-25 22:59:50 +01:00
|
|
|
return Ok();
|
2024-02-25 13:22:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|