-2
Good morning Personal,
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 function CreateClientAsync.
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 customer data, call GetClientAsync, but I don’t know where to start, could help me please ?
public async Task<ApplicationClient> GetClientAsync(ApplicationClient client)
{
try
{
}
catch (Exception)
{
throw;
}
}
Table Clientes:
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 ClientesEmail:
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 ClientesTelefone:
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; }
}
I’m getting the error that 'Applicationclient' does not contain a definition for 'Getawaiter'
– Matheus
Sorry, change the Firstordefault for Firstordefaultasync
– Jean Gatto
I’m using this function to check if the
CNPJorCPF, is already inserted in the table, so from what I understand, if it does not find it will returnnull, and from thatnullcan make aifand make that check, correct ?– Matheus
That! exactly, you will test if the Client object is different from null and treat, if(client != null) { // Found! } Else { //Did not find }
– Jean Gatto
In case I can’t get back to
varresult, 'cause I get the following mistake:Não é possível converter implicitamente tipo "EasySistema.Models.ApplicationClient em Microsoft.Asp.NetCore.Mvc.ActionResult– Matheus