コード例 #1
0
        public async Task <NutritionFact> AddNutritionFact(NutritionFact nutritionFact)
        {
            await _context.NutritionFacts.AddAsync(nutritionFact);

            await _context.SaveChangesAsync();

            return(nutritionFact);
        }
コード例 #2
0
        private void UpdateIngredientNutritionalInformation(UpdateObject update, ref UpdateResults results)
        {
            // need to get the xmlimportitem

            var xmlimport = GetXmlIngredientByGuid(update.xmlingredientguid.ToString());

            if (xmlimport == null)
            {
                throw new ApplicationException("XmlImportIngredient not found");
            }

            //need to blow out the previous facts
            GetDataBase().Execute(" update NutritionFacts set active = 0 where ingredientid =@0", update.ingredientid);

            //translate field to nutrition type
            foreach (var facttype in GetDataBase().Fetch <NutritionFactType>(" select * from NutritionFactTypes"))
            {
                try
                {
                    var fact = GetNutritionFact(update.ingredientid, facttype.nutritionfacttypeid);
                    if (fact == null)
                    {
                        fact = new NutritionFact();
                        fact.ingredientid        = update.ingredientid;
                        fact.nutritionfacttypeid = facttype.nutritionfacttypeid;
                        fact.ServiceObjectId     = new Guid();
                        fact.DataObjectId        = new Guid();
                    }

                    fact.active = true;
                    fact.value  = GetFactValueFromImport(xmlimport, facttype.nutritionfacttypeid);

                    if (fact.IsNew())
                    {
                        fact.Insert();
                    }
                    else
                    {
                        fact.Update();
                    }
                    results.NutrionalFactsUpdates++;
                }
                catch (Exception e)
                {
                    results.Errors.Add("NutrionalFact:" + facttype.name + " for Ingredient:" + update.ingredientid, e.Message);
                }
            }
        }
コード例 #3
0
        private void UpdateIngredientNutritionalInformation(UpdateObject update, ref UpdateResults results)
        {
            // need to get the xmlimportitem

            var xmlimport = GetXmlIngredientByGuid(update.xmlingredientguid.ToString());

            if ( xmlimport == null)
                throw new ApplicationException("XmlImportIngredient not found");

            //need to blow out the previous facts
            GetDataBase().Execute(" update NutritionFacts set active = 0 where ingredientid =@0", update.ingredientid);

            //translate field to nutrition type
            foreach (var facttype in GetDataBase().Fetch<NutritionFactType>(" select * from NutritionFactTypes"))
            {
                try
                {
                    var fact = GetNutritionFact(update.ingredientid, facttype.nutritionfacttypeid);
                    if (fact == null)
                    {
                        fact = new NutritionFact();
                        fact.ingredientid = update.ingredientid;
                        fact.nutritionfacttypeid = facttype.nutritionfacttypeid;
                        fact.ServiceObjectId = new Guid();
                        fact.DataObjectId = new Guid();
                    }

                    fact.active = true;
                    fact.value = GetFactValueFromImport(xmlimport, facttype.nutritionfacttypeid);

                    if (fact.IsNew())
                        fact.Insert();
                    else
                        fact.Update();
                    results.NutrionalFactsUpdates++;
                }
                catch (Exception e)
                {
                    results.Errors.Add("NutrionalFact:" + facttype.name + " for Ingredient:" + update.ingredientid, e.Message);
                }
            }
        }