Get User Entity ID

0

I'm trying to get the user id and save it to the table, here's how I referenced it in the ForeignKey table:

public string FuncionarioId { get; set; }
    [ForeignKey("FuncionarioId")]
    public virtual ApplicationUser ApplicationUser { get; set; }

And here's how I'm trying to play to the table:

public async Task<IActionResult> OnPost()
    {
        if (ModelState.IsValid)
        {
            var CR = _context.ContasReceber.Find(ContasReceberVM.ContasReceber.Id);
            CR.Quitado = true;
            CR.ValorPago = Convert.ToDecimal(ContasReceberVM.ContasReceber.ValorPago.ToString().Replace(",","."));
            CR.FormaPagamento = ContasReceberVM.ContasReceber.FormaPagamento;
            CR.DataPagamento = DateTime.Now;
            ApplicationUser a = new ApplicationUser();
            CR.FuncionarioId = a.Id;
            await _context.SaveChangesAsync();
            Message = "Pagamento Realizado com Sucesso!";

            return RedirectToPage("Index");
        }
    }

But this way, it does not get the correct ID, it takes an ID that does not exist, then it returns the following error.

  

The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_ContasReceber_AspNetUsers_FuntionaryId". The conflict occurred in the database "CronoParque", table "dbo.AspNetUsers", column 'Id'.    The statement has been terminated.

It returns this error, because the ID does not match the registered ID in the AspNetUsers table.

    
asked by anonymous 11.07.2018 / 21:04

0 answers