contact updated
This commit is contained in:
@@ -7,5 +7,7 @@ public class CreateContactDto
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Address { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? Role { get; set; }
|
||||
public int? CustomerId { get; set; }
|
||||
}
|
||||
@@ -8,5 +8,7 @@ public class UpdateContactDto
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Address { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? Role { get; set; }
|
||||
public int? CustomerTypeId { get; set; }
|
||||
}
|
||||
@@ -8,5 +8,7 @@ public class GetContactDto
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Address { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? Role { get; set; }
|
||||
public int? CustomerId { get; set; }
|
||||
}
|
||||
@@ -3,4 +3,5 @@ namespace PyroFetes.DTO.Customer.Request;
|
||||
public class CreateCustomerDto
|
||||
{
|
||||
public string? Note { get; set; }
|
||||
public int CustomerTypeId { get; set; }
|
||||
}
|
||||
@@ -4,4 +4,6 @@ public class GetCustomerDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Note { get; set; }
|
||||
|
||||
public int CustomerTypeId { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Contact.Request;
|
||||
using PyroFetes.DTO.Contact.Response;
|
||||
|
||||
@@ -15,6 +16,15 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
|
||||
|
||||
public override async Task HandleAsync(CreateContactDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.CustomerId, cancellationToken: ct);
|
||||
|
||||
if (databaseCustomer == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
Console.WriteLine("Customer not found");
|
||||
return;
|
||||
}
|
||||
|
||||
Models.Contact contact = new()
|
||||
{
|
||||
LastName = req.LastName,
|
||||
@@ -22,7 +32,9 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
|
||||
PhoneNumber = req.PhoneNumber,
|
||||
Email = req.Email,
|
||||
Address = req.Address,
|
||||
City = req.City,
|
||||
Role = req.Role,
|
||||
CustomerId = databaseCustomer.Id,
|
||||
};
|
||||
pyroFetesDbContext.Add(contact);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
@@ -34,7 +46,9 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
|
||||
PhoneNumber = contact.PhoneNumber,
|
||||
Email = contact.Email,
|
||||
Address = contact.Address,
|
||||
City = contact.City,
|
||||
Role = contact.Role,
|
||||
CustomerId = contact.CustomerId,
|
||||
};
|
||||
|
||||
await Send.OkAsync(response, ct);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Customer.Request;
|
||||
using PyroFetes.DTO.Customer.Response;
|
||||
|
||||
@@ -15,9 +16,20 @@ public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
|
||||
|
||||
public override async Task HandleAsync(CreateCustomerDto req, CancellationToken ct)
|
||||
{
|
||||
var customer = new Models.Customer
|
||||
Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.CustomerTypeId, cancellationToken: ct);
|
||||
|
||||
if (databaseCustomerType == null)
|
||||
{
|
||||
Note = req.Note
|
||||
await Send.NotFoundAsync(ct);
|
||||
Console.WriteLine("Customer Type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
Models.Customer customer = new()
|
||||
{
|
||||
Note = req.Note,
|
||||
CustomerTypeId = databaseCustomerType.Id,
|
||||
|
||||
};
|
||||
pyroFetesDbContext.Add(customer);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
@@ -25,7 +37,8 @@ public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
|
||||
GetCustomerDto response = new GetCustomerDto()
|
||||
{
|
||||
Id = customer.Id,
|
||||
Note = customer.Note
|
||||
Note = customer.Note,
|
||||
CustomerTypeId = customer.CustomerTypeId
|
||||
};
|
||||
|
||||
await Send.OkAsync(response, ct);
|
||||
|
||||
14
PyroFetes/Models/ContactCustomer.cs
Normal file
14
PyroFetes/Models/ContactCustomer.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Models;
|
||||
|
||||
[PrimaryKey(nameof(ContactId), nameof(CustomerId))]
|
||||
public class ContactCustomer
|
||||
{
|
||||
[Required] public int ContactId { get; set; }
|
||||
[Required] public int CustomerId { get; set; }
|
||||
|
||||
public Contact? Contact { get; set; }
|
||||
public Customer? Customer { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user