Created
April 15, 2016 19:09
-
-
Save jfbueno/387d8b6d7b1aca720e80fefed535c046 to your computer and use it in GitHub Desktop.
Teste-Pessoa-Com-EAV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Table("Pessoas")] | |
public class Pessoa | |
{ | |
[Key] | |
public int Id { get; set; } | |
public string NomePrincipal { get; set; } | |
public string Nome { get; set; } | |
public bool Ativo { get; set; } | |
public virtual List<PessoaAtributoValor> Atributos { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public ActionResult Create(PessoaViewModel pessoaVm) | |
{ | |
try | |
{ | |
var pessoa = pessoaVm.Pessoa; | |
pessoa.Atributos = new List<PessoaAtributoValor>(); | |
pessoa.Atributos.AddRange(new[] { new PessoaAtributoValor | |
{ | |
Nome = "Cpf", | |
Valor = pessoaVm.Cpf.ToString() | |
}, | |
new PessoaAtributoValor | |
{ | |
Nome = "RG", | |
Valor = pessoaVm.NumeroRg.ToString() | |
} | |
}); | |
_db.Pessoas.Add(pessoa); | |
_db.SaveChanges(); | |
return RedirectToAction("Index"); | |
} | |
catch | |
{ | |
return View(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PessoaViewModel | |
{ | |
public Pessoa Pessoa { get; set; } | |
public int NumeroRg { get; set; } | |
public long Cpf { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment