Inheritance: System.Entity
Esempio n. 1
0
 public void SaveIngredient(Ingredient ingredient)
 {
     try {
         ingredientRepository.SaveOrUpdate(ingredient);
     } catch(Exception e) {
         throw new IngredientInsertionException("Error inserting ingredient.", e) {Ingredient = ingredient};
     }
 }
        protected override void LoadTestData()
        {
            var ingredientRepository = new IngredientRepository();
            ingredient = ingredientRepository.SaveOrUpdate(new Ingredient {Name = "Pannbiff"});

            user = new UserRepository().Save(new User { Username = "******" });
            user2 = new UserRepository().Save(new User { Username = "******" });
            var user3 = new UserRepository().Save(new User { Username = "******" });
            NHibernateSession.Current.Flush();

            var userIngredientRepository = new UserIngredientRepository();

            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 10, User = user, Date = now});
            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 100, User = user, Date = now});
            userIngredientRepository.SaveOrUpdate(new UserIngredient {Ingredient = ingredient, Measure = 200, User = user, Date = now.AddDays(-1)});

            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 10, User = user2, Date = now });
            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 100, User = user3, Date = now });
            userIngredientRepository.SaveOrUpdate(new UserIngredient { Ingredient = ingredient, Measure = 200, User = user2, Date = now.AddDays(-1) });

            NHibernateSession.Current.Flush();
        }
 public void shouldGetZeroInNutrientIngredientValueWhenNoNutrientIngredient()
 {
     decimal nutrientIngredientValue = new Ingredient().GetNutrientIngredientDisplayValue(null as IngredientNutrient);
     Assert.That(nutrientIngredientValue, Is.EqualTo(0));
 }
Esempio n. 4
0
        public void createIngredientIfNotExist(string name)
        {
            var ingredientRepository = new IngredientRepository();
            //var ingredientNutrientRepository = new IngredientNutrientRepository();

            var nutriantRepository = new NutrientRepository();
            var energyInKcalNutrient = nutriantRepository.GetByName(NutrientEntity.EnergyInKcal.ToString());
            var fatInG = nutriantRepository.GetByName(NutrientEntity.FatInG.ToString());

            if (ingredientRepository.Get(name) == null) {
                var ingredient = new Ingredient {Name = name, WeightInG = 100};
                ingredient.IngredientNutrients = new List<IngredientNutrient> {new IngredientNutrient {Nutrient = energyInKcalNutrient, Value = 100, Ingredient = ingredient},
                                                                                                            new IngredientNutrient {Nutrient = fatInG, Value = 200, Ingredient = ingredient}};
                ingredientRepository.SaveOrUpdate(ingredient);
            }
        }
Esempio n. 5
0
        public IList<Ingredient> CreateIngredientFromFileContents(string fileContents)
        {
            IList<Ingredient> ingredients = new List<Ingredient>();
            var rows = fileContents.Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
            for (var j = 1; j < rows.Length; j++) {
                var columns = rows[j].Split('\t');
                var ingredient = new Ingredient();
                var ingredientNutrients = new List<IngredientNutrient>();
                var i = 0;
                ingredient.Name = columns[i++];
                ingredient.WeightInG = GetDecimalValue(j, columns, i++);

                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FibresInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.EnergyInKJ, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.EnergyInKcal, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.CarbonHydrateInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.DVitaminInµG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.AscorbicAcidInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.IronInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.CalciumInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.NatriumInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.ProteinInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.AlcoholInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.SaturatedFatInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.MonoUnSaturatedFatInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.PolyUnSaturatedFatInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC4C10InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC12InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC14InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC16InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC18InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC20InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC16_1InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC18_1InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC18_2InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC18_3InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC20_4InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC20_5InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC22_5InG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.MonosaccharidesInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.DisaccharidesInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.SucroseInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.RetinolEquivalentInµG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.RetinolInµG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.EVitaminInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.TokopherolInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.CaroteneInµG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.ThiamineInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.RiboflavinInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.NiacinEquivalentInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.NiacinInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.VitaminB6InmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.VitaminB12InµG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FolicAcidInµG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.PhosphorusInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.PotassiumInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.MagnesiumInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.SeleniumInµG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.ZincInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.CholesteroleInmG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.AshInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.AquaInG, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.WasteInPercent, GetDecimalValue(j, columns, i++));
                addIngredientNutrient(ingredient, ingredientNutrients, NutrientEntity.FatAcidC22_6InG, GetDecimalValue(j, columns, i++));

                ingredient.IngredientNutrients = ingredientNutrients;
                ingredients.Add(ingredient);
            }
            return ingredients;
        }
Esempio n. 6
0
 private void addIngredientNutrient(Ingredient ingredient, ICollection<IngredientNutrient> ingredientNutrients, NutrientEntity entity, decimal value)
 {
     var ingredientNutrient = new IngredientNutrient {Ingredient = ingredient, Nutrient = nutrientBusinessLogic.GetNutrient(entity), Value = value};
     ingredientNutrients.Add(ingredientNutrient);
 }