Skip to content

Update Food (4.x)

Alex edited this page May 30, 2019 · 1 revision

Ingredient

var ingredient = new IngredientDto();
ingredient.Id = Guid.Parse("d6e1c25c-45ea-00e3-575f-443582096cec");  // Existing Item in Database
ingredient.Name = new[] { new GlobalString() { Language = "en-US", Value = "New Ingredient" } };
ingredient.CommonName = new[] { new GlobalString() { Language = "en-US", Value = "Ingredient" } };
ingredient.UserCode = "1414-3";
ingredient.UsdaCode = 1234;

ingredient.Created = new XmlDateTimeOffset
{
    DateTime = DateTime.Now.ToUniversalTime(),
    UtcOffsetInMinutes = 0
};

ingredient.Brand = new BrandDto
{
    Product = "Product",
    Supplier = "Supplier"
};

ingredient.AllergenStatements = new[]
{
    new AllergenStatementDto {AllergenGroups = new []
    {
        Guid.Parse("f01975c0-0191-0000-ff88-2a01e505d63d") // Egg
    }}
};

ingredient.Groups = new[] { Guid.Parse("021c021f-000a-0000-8d69-0b60293379ea") };

ingredient.Conversions = new[]
{
    new ConversionDto
    {
        From = new AmountDto
        {
            Quantity = new QuantityDto() { Type = QuantityType.Double, Value = "100" },
            UnitId = Guid.Parse("a7df0af5-0008-0000-7484-751e8eaf05c6") // gram
        },
        To = new AmountDto
        {
            Quantity = new QuantityDto() { Type = QuantityType.Double, Value = "1" },
            UnitId = Guid.Parse("a7df0af5-001c-0000-7484-751e8eaf05c6") // bowl
        },
    }
};

ingredient.DefiningAmount = new AmountDto
{
    Quantity = new QuantityDto() { Type = QuantityType.Double, Value = "100" },
    UnitId = Guid.Parse("a7df0af5-0008-0000-7484-751e8eaf05c6")
};

ingredient.AmountCost = new AmountCostDto
{
    Amount = ingredient.DefiningAmount,
    Cost = 5.5m
};

ingredient.NutrientProfileId = Guid.NewGuid();

var nutrientProfile = new NutrientProfileDto();
nutrientProfile.Id = ingredient.NutrientProfileId;
nutrientProfile.DefiningAmount = ingredient.DefiningAmount;
nutrientProfile.NutrientIdVector = new[]
{
    new NutrientQuantityDto
    {
        NutrientId = Guid.Parse("84a8709a-0000-0000-ebf9-90cea7d9d44f"),
        Quantity = new QuantityDto
        {
            Type = QuantityType.Double,
            Value = "10"
        }
    }
};

var ingredientEdit = new IngredientsEditDto
{
    Ingredients = new[] {ingredient}, // Array of ingredients with the same nutrient profile
    NutrientProfile = nutrientProfile,    
    EditDetails = new EditDetailsDto()
    {
        EditMessage = "Updating Ingredient",
        EditCaller = new EditCallerDto
        {
            Name = "Our PLM System"
        }
    }
};

var newFoodRequest = new NewFoodRequest
{
    IngredientsEdits = new[] {ingredientEdit}
};

var newFoodResponse = foodEditServiceClient.NewFood(newFoodRequest);

Recipe

var recipe = new RecipeDto();
recipe.Id = Guid.Parse("d6e1c25c-45ea-00e3-575f-443582096cec");  // Existing Item in Database
recipe.Name = new [] { new GlobalString() { Language = "en-US", Value = "New Recipe" } };
recipe.CommonName = new[] { new GlobalString() { Language = "en-US", Value = "Recipe" } };
recipe.UserCode = "1414-3";

recipe.Created = new XmlDateTimeOffset
{
    DateTime = DateTime.Now.ToUniversalTime(),
    UtcOffsetInMinutes = 0
};

recipe.Brand = new BrandDto
{
    Product = "Product",
    Supplier = "Supplier"
};

recipe.AllergenStatements = new []
{
    new AllergenStatementDto {AllergenGroups = new []
    {
        Guid.Parse("f01975c0-0191-0000-ff88-2a01e505d63d") // Egg
    }}
}; 

recipe.Groups = new[] {Guid.Parse("021c021f-000a-0000-8d69-0b60293379ea")};

recipe.Conversions = new[]
{
    new ConversionDto
    {
        From = new AmountDto
        {
            Quantity = new QuantityDto() { Type = QuantityType.Double, Value = "100" },
            UnitId = Guid.Parse("a7df0af5-0008-0000-7484-751e8eaf05c6") // gram
        },
        To = new AmountDto
        {
            Quantity = new QuantityDto() { Type = QuantityType.Double, Value = "1" },
            UnitId = Guid.Parse("a7df0af5-001f-0000-7484-751e8eaf05c6") // Serving
        },
    }
};

recipe.Items = new[] {new FoodItemDto
{
    FoodId = Guid.Parse("d6e1c25c-45ea-00e3-575f-443582096cec"), // Existing Food in Database
    Amount = new AmountDto
    {
        Quantity = new QuantityDto() { Type = QuantityType.Double, Value = "100" },
        UnitId = Guid.Parse("a7df0af5-0008-0000-7484-751e8eaf05c6") // gram
    }
}};

var labelProfile = new LabelProfileDto
{
    Authority = new AuthorityDto
    {
        Id = new Guid("BBF4846D-8400-43BB-944D-6021FDA98225"), 
        Regulation = Regulations.UnitedStates2016
    },
    LabelFormat = LabelFormat.Full,
    LabelStyle = LabelStyle.Tabular,
    ServingSize = new[]
    {
        new GlobalString
        {
            Language = "en-US",
            Value = "1 Pizza Pie"
        }
    },
    ServingsPerContainer = new[]
    {
        new GlobalString
        {
            Language = "en-US",
            Value = "1"
        }
    }
};

var recipeEdit = new RecipeEditDto
{
    Recipe = recipe,
    LabelProfile = null,
    EditDetails = new EditDetailsDto()
    {
        EditMessage = "Updating Recipe",
        EditCaller = new EditCallerDto
        {
            Name = "Our PLM System"
        }
    }
};

var newFoodRequest = new NewFoodRequest
{
    RecipeEdits = new[] {recipeEdit}
};

var newFoodResponse = foodEditServiceClient.NewFood(newFoodRequest);

Composite Ingredient

var compositeIngredient = new CompositeIngredientDto();
compositeIngredient .Id = Guid.Parse("d6e1c25c-45ea-00e3-575f-443582096cec");  // Existing Item in Database
compositeIngredient.Name = new [] { new GlobalString() { Language = "en-US", Value = "New CompositeIngredient" } };
compositeIngredient.CommonName = new[] { new GlobalString() { Language = "en-US", Value = "CompositeIngredient" } };
compositeIngredient.UserCode = "1414-3";

compositeIngredient.Created = new XmlDateTimeOffset
{
    DateTime = DateTime.Now.ToUniversalTime(),
    UtcOffsetInMinutes = 0
};

compositeIngredient.Brand = new BrandDto
{
    Product = "Product",
    Supplier = "Supplier"
};

compositeIngredient.AllergenStatements = new []
{
    new AllergenStatementDto {AllergenGroups = new []
    {
        Guid.Parse("f01975c0-0191-0000-ff88-2a01e505d63d") // Egg
    }}
}; 

compositeIngredient.Groups = new[] {Guid.Parse("021c021f-000a-0000-8d69-0b60293379ea")};

compositeIngredient.Items = new[] {new FoodItemDto
{
    FoodId = Guid.Parse("d6e1c25c-45ea-00e3-575f-443582096cec"), // Existing Ingredient in Database
    Amount = new AmountDto
    {
        Quantity = new QuantityDto() { Type = QuantityType.Double, Value = "100" },
        UnitId = Guid.Parse("a7df0af5-0008-0000-7484-751e8eaf05c6") // gram
    }
}};

var compositeIngredientEdit = new CompositeIngredientEditDto
{
    CompositeIngredient = compositeIngredient,
    EditDetails = new EditDetailsDto()
    {
        EditMessage = "Updating Composite Ingredient",
        EditCaller = new EditCallerDto
        {
            Name = "Our PLM System"
        }
    }
};

var newFoodRequest = new NewFoodRequest
{
    CompositeIngredientEdits = new[] {compositeIngredientEdit}
};

var newFoodResponse = foodEditServiceClient.NewFood(newFoodRequest);