Error retrieving Client Data for Editing - C#

Asked

Viewed 12 times

0

Friends, I have a table "person" and "address", I can register a customer and insert their information in the two tables, but I’m having difficulty to consult the customer’s information and bring it in an editing form. Address table information appears as "Null".

This is my Update method

[ClienteAutorizacao]
        [HttpGet]
        public IActionResult Atualizar(Models.cad_endereco endereco)
        {
            cad_pessoa cliente = _clienteRepository.ObterCliente(_loginCliente.GetCliente().PES_CODIGO);
            cliente.cad_endereco = endereco;
            return View(cliente);
        }


[ClienteAutorizacao]
[HttpPost]
public IActionResult Atualizar(Models.cad_pessoa cliente, [FromForm] Models.cad_endereco endereco)
        {
            ModelState.Remove("Senha");
            ModelState.Remove("ConfirmacaoSenha");

            if (ModelState.IsValid)
            {
                cliente.PES_SENHA = _loginCliente.GetCliente().PES_SENHA;
                cliente.cad_endereco = endereco;
                _clienteRepository.Atualizar(cliente);

                _loginCliente.Login(cliente);

                TempData["MSG_S"] = Mensagem.MSG_S001;

                return RedirectToAction(nameof(Index));
                
            }
            return View();
        }

I end up getting this mistake:

inserir a descrição da imagem aqui

This is my model:

using LojaVirtual.Libraries.Lang;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;


namespace LojaVirtual.Models.ViewModels.Aluno
{
    public class EnderecoViewModel
    {
        [Key]
        public int PES_CODIGO { get; set; }
         
        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        [MinLength(4, ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E002")]
        public string PES_NOME { get; set; }

        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        public DateTime PES_NASCIMENTO { get; set; }

        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        public string PES_SEXO { get; set; }

        //TODO - Validar CPF
        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        public string PES_CPF { get; set; }

        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        public string PES_TEL_RESIDENCIAL { get; set; }

        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        public string PES_TEL_CELULAR { get; set; }

        public string PES_TEL_COMERCIAL { get; set; }

        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        [MinLength(4, ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E002")]
        public string PES_MAE { get; set; }

        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        [MinLength(4, ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E002")]
        public string PES_PAI { get; set; }

        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        [EmailAddress(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E004")]
        public string PES_EMAIL { get; set; }

        [Required(ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E001")]
        [MinLength(6, ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E002")]
        public string PES_SENHA { get; set; }

        [NotMapped]
        [Display(Name = "Confirme a senha")]
        [Compare("PES_SENHA", ErrorMessageResourceType = typeof(Mensagem), ErrorMessageResourceName = "MSG_E005")]
        public string ConfirmacaoSenha { get; set; }

        [Display(Name = "Situação")]
        public string PES_SITUACAO { get; set; }


        public string PES_CEP { get; set; }
        public string PES_BAIRRO { get; set; }

        public string PES_CIDADE { get; set; }

        public string PES_ESTADO { get; set; }

        public string PES_LOGRADOURO { get; set; }

        public string PES_NUMERO { get; set; }
        public string PES_COMPLEMENTO { get; set; }
    }
}

I’d appreciate it if someone would help me analyze this mistake!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.