public void GuardarIngrediente(Clases.Ingrediente ingrediente) { ingrediente.FechaDeCreacion = DateTime.Now; ingrediente.FechaDeModificacion = DateTime.Now; ingrediente.Activo = true; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { AccesoADatos.Ingrediente ingredienteDb = ConvertirDeLogicaADbParaGuardar(ingrediente); foreach (Clases.Componente componente in ingrediente.Componentes) { RelacionIngrediente componenteDB = new RelacionIngrediente(); componenteDB.Cantidad = componente.Cantidad; componenteDB.IngredienteHijo = context.Ingredientes.Find(componente.Ingrediente.Id); componenteDB.IngredientePadre = null; ingredienteDb.RelacionIngredientesHijo.Add(componenteDB); } context.Ingredientes.Add(ingredienteDb); if (!ValidarExistenciaDeIngrediente(ingredienteDb)) { context.SaveChanges(); } } }
public AccesoADatos.RelacionIngrediente ConvertirDeLogicaADatos(Clases.Componente componente) { RelacionIngrediente componenteDb = new RelacionIngrediente(); IngredienteDAO ingredienteDAO = new IngredienteDAO(); componenteDb.Cantidad = componente.Cantidad; componenteDb.IngredienteHijo = ingredienteDAO.ConvertirDeLogicaADb(componente.Ingrediente); return(componenteDb); }
public List <AccesoADatos.RelacionIngrediente> ConvertirlistaDeLogicaADatos(List <Clases.Componente> componentes) { List <AccesoADatos.RelacionIngrediente> componentesDb = new List <RelacionIngrediente>(); foreach (Clases.Componente componente in componentes) { RelacionIngrediente componenteDb = ConvertirDeLogicaADatos(componente); componentesDb.Add(componenteDb); } return(componentesDb); }