Exemplo n.º 1
0
        public void EditarPlatillo(Clases.Platillo Platillo)
        {
            Platillo.FechaDeModificacion = DateTime.Now;

            Platillo platilloDb;

            using (ModeloDeDatosContainer context = new ModeloDeDatosContainer())
            {
                platilloDb = context.Platillos.Include(x => x.PlatilloIngredientes.Select(i => i.Ingrediente)).FirstOrDefault(p => p.Id == Platillo.Id);

                platilloDb.Nombre = Platillo.Nombre;
                platilloDb.Precio = Platillo.Precio;
                platilloDb.FechaDeModificacion = Platillo.FechaDeModificacion;
                platilloDb.Activo      = Platillo.Activo;
                platilloDb.Codigo      = Platillo.Codigo;
                platilloDb.Notas       = Platillo.Notas;
                platilloDb.Descripcion = Platillo.Descripcion;
                platilloDb.Imagen      = Platillo.Imagen;

                foreach (Clases.Proporcion proporcion in Platillo.Proporciones)
                {
                    if (proporcion.Id == 0)
                    {
                        PlatilloIngrediente platilloIngrediente = new PlatilloIngrediente
                        {
                            Cantidad    = proporcion.Cantidad,
                            Platillo    = platilloDb,
                            Ingrediente = context.Ingredientes.Find(proporcion.Ingrediente.Id)
                        };

                        context.PlatilloIngrediente.Add(platilloIngrediente);
                    }
                    else
                    {
                        foreach (PlatilloIngrediente proporcionDB in platilloDb.PlatilloIngredientes)
                        {
                            if (proporcion.Id == proporcionDB.Id)
                            {
                                proporcionDB.Cantidad = proporcion.Cantidad;
                                break;
                            }
                        }
                    }
                }

                List <PlatilloIngrediente> proporcionesAEliminar = platilloDb.PlatilloIngredientes.Where(p => !Platillo.Proporciones.Any(p2 => p2.Id == p.Id)).ToList();

                foreach (PlatilloIngrediente proporcion in proporcionesAEliminar)
                {
                    context.PlatilloIngrediente.Remove(proporcion);
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public AccesoADatos.PlatilloIngrediente ConvertirLogicaADb(Clases.Proporcion Proporcion)
        {
            AccesoADatos.PlatilloIngrediente proporcionConvertida = new PlatilloIngrediente()
            {
                Id       = Proporcion.Id,
                Cantidad = Proporcion.Cantidad,
            };

            IngredienteDAO ingredienteDAO = new IngredienteDAO();

            proporcionConvertida.Ingrediente = ingredienteDAO.ConvertirDeLogicaADb(Proporcion.Ingrediente);
            proporcionConvertida.Ingrediente.PlatilloIngredientes = new List <PlatilloIngrediente>()
            {
                proporcionConvertida
            };

            return(proporcionConvertida);
        }
Exemplo n.º 3
0
        private AccesoADatos.PlatilloIngrediente ConvertirProporcionDeLogicaAProporcionDeAccesoADatosParaEdicion(Clases.Proporcion Proporcion)
        {
            PlatilloIngrediente proporcionConvertida = new PlatilloIngrediente();

            using (ModeloDeDatosContainer context = new ModeloDeDatosContainer())
            {
                proporcionConvertida = context.PlatilloIngrediente.Find(Proporcion.Id);
            }

            proporcionConvertida.Cantidad = Proporcion.Cantidad;

            IngredienteDAO ingredienteDAO = new IngredienteDAO();

            proporcionConvertida.Ingrediente = ingredienteDAO.ConvertirDeLogicaADb(Proporcion.Ingrediente);
            proporcionConvertida.Ingrediente.PlatilloIngredientes = new List <PlatilloIngrediente>()
            {
                proporcionConvertida
            };

            return(proporcionConvertida);
        }
Exemplo n.º 4
0
 public void ClonarProporcionDeAccesoDatos(PlatilloIngrediente Proporcion, PlatilloIngrediente resultado)
 {
     resultado.Id       = Proporcion.Id;
     resultado.Platillo = Proporcion.Platillo;
     resultado.Cantidad = Proporcion.Cantidad;
 }