Ejemplo n.º 1
0
        public void AddGeneralDishToDBTest_ShouldSaveDishInDBAndUpdateMongoIdProperty()
        {
            GeneralDish generalDish = new GeneralDish()
            {
                Dish = new Dish()
            };

            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<GeneralDish> basicData =
                                            new MongoEntityRepositoryBase<GeneralDish>(restaurantsDb.DB);

                basicData.Add(generalDish);
                Object savedId = generalDish.Id;
                basicData.Delete(savedId);
            }

            Assert.IsNotNull(generalDish.Id);
        }
Ejemplo n.º 2
0
        public static GeneralDish IngredientToGeneralDish(this Ingredient ingredient, string language = "en-US")
        {
            log.InfoFormat("[IngredientToGeneralDish] Ingredient.USDA_NDB_No={0}, language={1}", ingredient.USDA_NDB_No, language);
            // return null if LongDesc is null or LongDesc has no translation to this language
            string ingrName;
            string ingrDescription;
            if (ingredient.LongDesc == null || ingredient.LongDesc.GetDescription(language) == null)
            {
                log.WarnFormat("[IngredientToGeneralDish] There is no translation, Ingredient.USDA_NDB_No={0}, language={0}, add default(en-US) value.", ingredient.USDA_NDB_No, language);
                ingrName = ingredient.LongDesc.GetDescription();
                ingrDescription = "100gr " + ingredient.LongDesc.GetDescription();
            }
            else
            {
                ingrName = ingredient.LongDesc.GetDescription(language);
                ingrDescription = "100גרם " + ingredient.LongDesc.GetDescription(language);
            }

            Dish dish = new Dish()
            {
                CreatedAt = DateTime.UtcNow,
                UpdatedAt = DateTime.UtcNow,
                State = new SuspiciousState() { Index = 100 },
                IsItPublic = true,
                Name = ingrName,
                Description = ingrDescription,
                OverrideIngredients = new List<Ingredient>() { ingredient },
                NutritionFacts = ingredient.NutritionFacts != null ? ingredient.NutritionFacts : new NutritionFacts(),
                ItemLocation = new Location(0, 0),
                DefaultWeight = new WeightType()
                {
                    Desc = "100גרם",
                    Amount = 1,
                    GmWgt = 100
                }
            };

            GeneralDish generalDish = new GeneralDish()
            {
                Dish = dish
            };

            return generalDish;
        }
Ejemplo n.º 3
0
 public void UpdateGeneralDish(GeneralDish generalDish)
 {
     log.DebugFormat("[UpdateGeneralDish] GeneralDish={0}.", generalDish.Dish.Name);
     //ingredient.UpdatedAt = DateTime.UtcNow;
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<GeneralDish> basicData =
                       new MongoEntityRepositoryBase<GeneralDish>(restaurantsDb.DB);
         basicData.Update(generalDish);
     }
 }
Ejemplo n.º 4
0
        public string AddGeneralDishToDB(GeneralDish generalDish)
        {
            try
            {
                string ndbNo = (generalDish.Dish.OverrideIngredients != null && generalDish.Dish.OverrideIngredients[0].USDA_NDB_No != null) ?
                    generalDish.Dish.OverrideIngredients[0].USDA_NDB_No.ToString() : "No USDA_NDB_No";
                log.InfoFormat("[AddGeneralDishToDB] generalDish.Dish.Name={0}, ingredient.USDA_NDB_No={1}.", generalDish.Dish.Name, ndbNo);
                if (generalDish != null)
                {
                    using (Restaurants restaurantsDb = new Restaurants())
                    {
                        MongoEntityRepositoryBase<GeneralDish> basicData =
                                                    new MongoEntityRepositoryBase<GeneralDish>(restaurantsDb.DB);

                        basicData.Add(generalDish);
                    }
                    return generalDish.Id.ToString();
                }
                return null;
            }
            catch (Exception e)
            {
                log.ErrorFormat("[AddGeneralDishToDB] Exception={0}.", e);
                return null;
            }
        }