示例#1
0
        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();
                }
            }
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }