public string CreateNutritionalLabel(int foodStageId, decimal amount) { ICollection <string> includes = new List <string>(); includes.Add("NutritionalFacts"); includes.Add("NutritionalFacts.FactDefinition"); FoodStage foodStage = _service.Get(f => f.FoodStageId == foodStageId, includes); NutritionalLabel nutritionalLabel = foodStage?.CreateNutritionalLabel(amount); string result = nutritionalLabel != null ? JsonHelper <NutritionalLabel> .Serialize(nutritionalLabel) : string.Empty; return(result); }
public void Save(ICollection <TOut> classToSave, IKernel kernel) { INutritionalFactService service = kernel.Get <INutritionalFactService>(); IFoodStageService foodStageService = kernel.Get <IFoodStageService>(); IFactDefinitionService factDefinitionService = kernel.Get <IFactDefinitionService>(); ICollection <NutritionalFact> nutritionalFacts = (List <NutritionalFact>)classToSave; foreach (NutritionalFact fact in nutritionalFacts) { FoodStage foodStage = foodStageService.Get(f => f.UsdaRefId == fact.FoodStage.UsdaRefId); if (foodStage == null) { continue; } FactDefinition factDefinition = factDefinitionService.Get(f => f.UsdaNutriRefId == fact.FactDefinition.UsdaNutriRefId); fact.FoodStage = foodStage; fact.FactDefinition = factDefinition; service.Add(fact); } service.Complete(); }