Ejemplo n.º 1
0
        public Component FindComponentById(int componentId, OdbcConnection connection)
        {
            ComponentDto componentDto;

            var commandText = $"SELECT {Components.Quantity}, {Components.IngredientId}, {Components.UnitId} FROM {Components.TableName} WHERE {Components.Id} = {componentId};";
            var command     = new OdbcCommand(commandText, connection);

            using (OdbcDataReader reader = command.ExecuteReader())
            {
                if (!reader.Read())
                {
                    throw new ComponentIdNotFoundOdbcDataException(componentId);
                }

                componentDto = new ComponentDto
                {
                    Id           = componentId,
                    IngredientId = reader.GetInt32(1),
                    Quantity     = reader.GetDouble(0),
                    UnitId       = reader.GetInt32(2)
                };
            }

            Ingredient ingredient = ingredientDataProvider.FindIngredientById(componentDto.IngredientId, connection);
            Unit       unit       = unitDataProvider.FindUnitById(componentDto.UnitId, connection);

            return(new Component(
                       id: componentDto.Id,
                       ingredient: ingredient,
                       quantity: componentDto.Quantity,
                       unit: unit
                       ));
        }
Ejemplo n.º 2
0
        public Component ReadComponentFromNode(XmlNode componentNode, XmlDocument document)
        {
            var _Id           = int.Parse(componentNode.Attributes[ComponentElement.Id].Value.ToString());
            var _IngredientId = int.Parse(componentNode.Attributes[ComponentElement.IngredientId].Value.ToString());
            var _Quantity     = double.Parse(componentNode.Attributes[ComponentElement.Quantity].Value.ToString());
            var _UnitId       = int.Parse(componentNode.Attributes[ComponentElement.UnitId].Value.ToString());
            var componentDto  = new ComponentDto
            {
                Id           = _Id,
                IngredientId = _IngredientId,
                Quantity     = _Quantity,
                UnitId       = _UnitId
            };

            Ingredient ingredient = ingredientDataProvider.FindIngredientById(componentDto.IngredientId, document);
            Unit       unit       = unitDataProvider.FindUnitById(componentDto.UnitId, document);

            return(new Component(
                       id: componentDto.Id,
                       ingredient: ingredient,
                       quantity: componentDto.Quantity,
                       unit: unit
                       ));
        }