Ejemplo n.º 1
0
        /// <summary>
        /// Actualiza la informacion de una entrada en el listado de precios
        /// Pueden actualizarse el precio del ingrediente, su cantidad o su unidad
        /// </summary>
        /// <param name="precioIngrediente">Unidad dentro la lista de precios a actualizar</param>
        public void Actualizar(PrecioIngrediente precioIngrediente)
        {
            ValidarPrecioIngrediente(precioIngrediente);

            Datos.PreciosIngredientesDAL dalPreciosIngredientes = dal.ObtenerPreciosIngredientesDAL();
            Datos.PrecioIngrediente      precioIngredienteDAL   = dalPreciosIngredientes.Obtener(precioIngrediente.Id);

            if (precioIngredienteDAL == null)
            {
                throw new OBMCateringException(Resources.PreciosIngredientesBL_Validaciones_ItemInvalido);
            }

            Datos.RecetasDAL   dalRecetas = dal.ObtenerRecetasDAL();
            Datos.UnidadMedida unidadDAL  = dalRecetas.ObtenerUnidad(precioIngrediente.Unidad.ToString());

            if (unidadDAL == null)
            {
                throw new OBMCateringException(string.Format(Resources.BL_Validaciones_UnidadMedidaInvalida, precioIngrediente.Unidad));
            }

            precioIngredienteDAL.Precio   = precioIngrediente.Precio;
            precioIngredienteDAL.Cantidad = precioIngrediente.Cantidad;
            precioIngredienteDAL.Unidad   = unidadDAL;

            dalPreciosIngredientes.Actualizar(precioIngredienteDAL);
            dal.Guardar();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calcula el precio total de una receta, que consta de consultar cada ingrediente de la receta en el listado
        /// de precios y calcular cuanto vale la cantidad que lleva ese ingrediente dentro de la receta
        /// El precio del ingrediente en el listado de precios tiene asignada una cantidad y unidad, que
        /// no necesariamente sera la misma que lleve la receta a preparar
        /// </summary>
        /// <param name="receta">Receta a calcular su precio</param>
        /// <returns>Precio total de la receta</returns>
        public decimal CalularPrecio(Receta receta)
        {
            if (receta == null)
            {
                throw new OBMCateringException(Resources.BL_Validaciones_RecetaNull);
            }

            decimal precioTotal = 0m;

            foreach (IngredienteReceta ingredienteReceta in receta.Ingredientes)
            {
                Ingrediente       ingrediente       = ingredienteReceta.Ingrediente;
                PrecioIngrediente precioIngrediente = preciosIngredientesBL.Obtener(ingrediente);

                if (precioIngrediente.Precio != null && ingredienteReceta.Unidad == precioIngrediente.Unidad)
                {
                    //Regla de tres simple
                    decimal precio = (ingredienteReceta.Cantidad * precioIngrediente.Precio.Value) / precioIngrediente.Cantidad.Value;

                    precioTotal = precioTotal + precio;
                }
            }

            return(precioTotal);
        }
Ejemplo n.º 3
0
        void ValidarPrecioIngrediente(PrecioIngrediente precioIngrediente)
        {
            if (precioIngrediente == null)
            {
                throw new OBMCateringException(Resources.PreciosIngredientesBL_Validaciones_ItemNull);
            }

            if (precioIngrediente.Ingrediente == null)
            {
                throw new OBMCateringException(Resources.BL_Validaciones_IngredienteNull);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Obtiene el listado completo de precios de los ingredientes del sistema
        /// </summary>
        /// <returns>Listado de precios de los ingredientes</returns>
        public IEnumerable <PrecioIngrediente> Obtener()
        {
            Datos.PreciosIngredientesDAL          dalPreciosIngredientes = dal.ObtenerPreciosIngredientesDAL();
            IEnumerable <Datos.PrecioIngrediente> preciosIngredientesDAL = dalPreciosIngredientes.Obtener();
            List <PrecioIngrediente> preciosIngredientes = new List <PrecioIngrediente>();

            foreach (Datos.PrecioIngrediente precioIngredienteDAL in preciosIngredientesDAL)
            {
                PrecioIngrediente precioIngrediente = Obtener(precioIngredienteDAL);

                preciosIngredientes.Add(precioIngrediente);
            }

            return(preciosIngredientes);
        }