public static SubCategoria CategoriaViewModelToCategoria(SubCategoriaViewModel subCategoriaViewModel) { SubCategoria subCategoria = null; if (subCategoriaViewModel != null) { subCategoria = new SubCategoria(); subCategoria.SubCategoriaId = subCategoriaViewModel.SubCategoriaId; subCategoria.Descricao = subCategoriaViewModel.Descricao; subCategoria.Slug = subCategoriaViewModel.Slug; subCategoria.Categoria = new Categoria { CategoriaId = subCategoriaViewModel.IdCategoria }; if (subCategoriaViewModel.CamposViewModel != null && subCategoriaViewModel.CamposViewModel.Count > 0) { subCategoria.Campos = new List <Campo>(); foreach (var campoViewModel in subCategoriaViewModel.CamposViewModel) { Campo campo = new Campo(); campo.CampoId = campoViewModel.CampoId; campo.Obrigatorio = campoViewModel.Obrigatorio; campo.Ordem = campoViewModel.Ordem; campo.Descricao = campoViewModel.Descricao; campo.TipoCampo = new TipoCampo() { TipoCampoId = Convert.ToInt32(campoViewModel.IdTipoCampo ?? "0") }; if (campoViewModel.TextoCampos != null && campoViewModel.TextoCampos.Count > 0) { campo.TextoCampos = new List <TextoCampo>(); foreach (var textoCampoViewModel in campoViewModel.TextoCampos) { TextoCampo textoCampo = new TextoCampo(); textoCampo.TextoCampoId = textoCampoViewModel.TextoCampoId; textoCampo.Texto = textoCampoViewModel.Texto; textoCampo.Valor = textoCampoViewModel.Valor; campo.TextoCampos.Add(textoCampo); } } subCategoria.Campos.Add(campo); } } } return(subCategoria); }
public static TextoCampo CamopViewModelToCampo(TextoCampoViewModel textCampoViewModel) { TextoCampo textoCampo = new TextoCampo(); textoCampo.TextoCampoId = textCampoViewModel.TextoCampoId; textoCampo.Texto = textCampoViewModel.Texto; textoCampo.Valor = textCampoViewModel.Valor; return(textoCampo); }
public void Cadastrar(TextoCampo textoCampo) { _dbContextAccessCorp.TextoCampos.Add(textoCampo); _dbContextAccessCorp.SaveChanges(); }