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); } } }
public UpdateResults UpdateMenu() { var UpdateResults = new UpdateResults(); var thelist = GetMatchedMenuItemIds(); //scope by menu id foreach (var menuid in thelist) { try { var updates = GetDynamicXrefQuery(menuid); GetDataBase().Execute("Delete from MenuItemIngredients where menuitemid = " + menuid); foreach (var update in updates) { UpdateIngredientXref(update); try { UpdateIngredientNutritionalInformation(update, ref UpdateResults); } catch (Exception e) { UpdateResults.Errors.Add("Ingredient Nutrition Update: " + update.ingredientid, e.Message); } UpdateResults.IngredientsUpdated++; } UpdateResults.MenuItemsUpdated++; } catch (Exception e) { UpdateResults.Errors.Add("Menu Item Update: " + menuid,e.Message); } } return UpdateResults; }