45 lines
1.4 KiB
C#
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);
|
||
|
}
|
||
|
}
|
||
|
}
|