ShoppingApp/Weifer.ShoppingApp.API/RestApi/CustomerApiController.cs

45 lines
1.5 KiB
C#
Raw Permalink Normal View History

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]
[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;
}
[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.ShoppingLists.Add(new ShoppingList { CustomerId = customer.CustomerId, ShoppingListId = new Guid(), ShoppingListName = "MainList"});
await dbContext.SaveChangesAsync();
return Ok();
2024-02-25 13:22:48 +01:00
}
}
}