Good morning, people,
I would like to create a function, which returns the requested client, and its data, which are in 3 different tables Clientes
, ClientesTelephone
, ClientesEmail
, I can add the client perfectly with my% / p>
CreateClientAsync:
public async Task<ApplicationClient> CreateClientAsync(ApplicationClient client)
{
try
{
var result = await _context.Clientes.AddAsync(client);
if (result.State == EntityState.Added)
{
_context.SaveChanges();
}
return result.Entity;
}
catch (Exception)
{
throw;
}
}
I am trying to develop a function to return client data, called CreateClientAsync
, but I do not know where to start, could you help me please?
public async Task<ApplicationClient> GetClientAsync(ApplicationClient client)
{
try
{
}
catch (Exception)
{
throw;
}
}
Table GetClientAsync
:
public class ApplicationClient
{
[Key]
public Guid Id { get; set; }
[Required]
public int TipoPessoa { get; set; }
public String Nome { get; set; }
public Guid UsuarioId { get; set; }
public virtual ICollection<ApplicationClientTelephone> ClientesTelefone { get; set; }
public virtual ICollection<ApplicationClientEmail> ClientesEmail { get; set; }
[ForeignKey("UsuarioId")]
public virtual ApplicationUser Usuario { get; set; }
}'
Tables Clientes
:
public class ApplicationClientEmail
{
[Key]
public long Id { get; set; }
public String Email { get; set; }
public Guid ClienteId { get; set; }
[ForeignKey("ClienteId")]
public virtual ApplicationClient Cliente { get; set; }
}
Tables ClientesEmail
:
public class ApplicationClientTelephone
{
[Key]
public long Id { get; set; }
public String Telefone { get; set; }
public Guid ClienteId { get; set; }
[ForeignKey("ClienteId")]
public virtual ApplicationClient Cliente { get; set; }
}