Пример #1
0
        public void AddIngredientToRecipe_IngredientFoundRecipeNotFound_ReturnsFalse()
        {
            var ingredient = new Ingredient()
            {
                Name = "Beef"
            };


            //add the ingredient to the database
            var ingredientRepository = new IngredientRepository(Context);

            ingredientRepository.Add(ingredient);

            var foundIngredient = ingredientRepository.GetAll().ToList();

            //there should only be one added record in the database
            Assert.AreEqual(1, foundIngredient.Count());

            //add an ingredient where recipe is not found and the ingredient is
            if (foundIngredient != null)
            {
                var added = ingredientRepository.AddIngredientToRecipe(456456, foundIngredient[0].IngredientId);
                //should return false
                Assert.IsFalse(added);
            }
        }
Пример #2
0
 public void UpdateDataGridWiew()
 {
     if (radioButton1.Checked)
     {
         ProductRepository repository = new ProductRepository();
         dataGridView1.DataSource = repository.GetProductConteinerDataSource().OrderBy(n => n.Name).ToList();
         dataGridView1.AutoResizeColumns();
     }
     else if (radioButton2.Checked)
     {
         IngredientRepository repos = new IngredientRepository();
         dataGridView1.DataSource = repos.GetIngredientPackageDataSource().OrderBy(n => n.Name).ToList();
         dataGridView1.AutoResizeColumns();
     }
     else
     {
         TareRepository repos = new TareRepository();
         dataGridView1.DataSource = repos.GetDataSource().Select(n => new
         {
             n.Name,
             n.Amount
         }).ToList().OrderBy(n => n.Name).ToList();
         dataGridView1.AutoResizeColumns();
     }
 }
 public IngredientController(IngredientRepository ingredientRepository, IRepository<Brand> brandRepository, IQuantityTypeRepository quantityTypeRepository, IMealRepository mealRepository)
 {
     _ingredientRepository = ingredientRepository;
     _brandRepository = brandRepository;
     _quantityTypeRepository = quantityTypeRepository;
     _mealRepository = mealRepository;
 }
Пример #4
0
        private void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            ProductRepository productRepository = new ProductRepository();
            IngredientRepository ingredientRepository = new IngredientRepository();
            IngredientsForProductRepository receiptRepository = new IngredientsForProductRepository();

            groupBox1.Enabled = radioButton1.Checked;
            if (!radioButton1.Checked)
            {
                ClearBatch();
            }

            Product currProduct = productRepository.GetDataSource().Where(n => n.Name == comboBox1.SelectedItem.ToString()).FirstOrDefault();

            var receipt = receiptRepository.GetDataSource().Where(n => n.ProductId == currProduct.Id).ToList();

            var ingredientsForProduct = ingredientRepository.GetDataSource();
            comboBox3.DataSource = receipt.Join(
                ingredientsForProduct,
                elem => elem.IngredientId,
                ingr => ingr.Id,
                (elem, ingr) => ingr.Name).ToList();

            checkBox1.Checked = false;
            comboBox2.Text = "";

            productsForRemaking.Clear();
            entryProductsContainerCollection.Clear();
            UpdateListBoxProduct();
        }
 public Dish_IngredientController(Dish_IngredientRepository repository, DishRepository dishRepository, DishController dishController, IngredientRepository ingredientRepository)
 {
     _repository           = repository ?? throw new ArgumentNullException(nameof(repository));
     _dishRepository       = dishRepository ?? throw new ArgumentNullException(nameof(dishRepository));
     _dishController       = dishController ?? throw new ArgumentNullException(nameof(dishController));
     _ingredientRepository = ingredientRepository ?? throw new ArgumentNullException(nameof(ingredientRepository));
 }
Пример #6
0
 public void shouldImportIngredients()
 {
     new IngredientImporterEngine("Hibernate.cfg.xml", true).Import(@"TestData\Ingredients.csv");
     IList<Ingredient> ingredients = new IngredientRepository().GetAll().OrderBy(x => x.Name).ToList();
     Assert.That(ingredients.First().Name, Is.EqualTo("Abborre"));
     Assert.That(ingredients.Last().Name, Is.EqualTo("Örtte drickf"));
 }
        public void DeleteWithIdThatDoesntExistThrowsException()
        {
            int id = 1000;
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_delete").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)

            /*using (var db = new Project1Context(options))
             * {
             *  var repo = new IngredientRepository(db);
             *
             *  Ingredients ingredient = new Ingredients { Name = "Test Delete", Stock = 10 };
             *  repo.Save(ingredient);
             *  repo.SaveChanges();
             *  id = ingredient.Id;
             * }*/

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var         repo       = new IngredientRepository(db);
                Ingredients ingredient = (Ingredients)repo.GetById(id);

                Assert.Null(ingredient);

                Assert.Throws <ArgumentException>(() => repo.Delete(id));
            }
        }
        public void GetByNameThatDoesntExistsReturnsNull()
        {
            string name = "Not existing name";

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_getByName").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new IngredientRepository(db);

                Ingredients ingredient = new Ingredients {
                    Name = "Test By Name", Stock = 10
                };
                repo.Save(ingredient);
                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var repo = new IngredientRepository(db);
                List <Ingredients> listIngredients = (List <Ingredients>)repo.GetByName(name);

                Assert.Empty(listIngredients);
            }
        }
        public void CreateIngredientsWorks()
        {
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_create").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var         repo       = new IngredientRepository(db);
                Ingredients ingredient = new Ingredients {
                    Name = "Test", Stock = 10
                };
                repo.Save(ingredient);
                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                Ingredients ingredient = db.Ingredients.First(m => m.Name == "Test");
                Assert.Equal("Test", ingredient.Name);
                Assert.Equal(10, ingredient.Stock);
                Assert.NotEqual(0, ingredient.Id); // should get some generated ID
            }
        }
Пример #10
0
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                Double.TryParse(maskedTextBox1.Text, out var weight);
                PackageRepository    repository           = new PackageRepository();
                IngredientRepository ingredientRepository = new IngredientRepository();

                string currIngredientName = comboBox1.SelectedItem.ToString();

                int id = ingredientRepository.GetDataSource().First(element => element.Name == currIngredientName).Id;
                repository.Add(new Package(id, weight), dateTimePicker1.Value);

                updateInformation();
                MessageBox.Show(@"Інгредієнт було успішно додано.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (FormatException)
            {
                MessageBox.Show(@"Некоректна вага інгредієнту.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show($"Інгредієнт не вибрано.\nБудь ласка виберіть потрібний інгредієнт", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception exception)
            {
                //TODO: Program thrown message on english when user try to add some product. Also check this problem with ingredient.
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void GetByIdWorks()
        {
            int id = 0;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_getById").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new IngredientRepository(db);

                Ingredients ingredient = new Ingredients {
                    Name = "Test By Id", Stock = 10
                };
                repo.Save(ingredient);
                repo.SaveChanges();
                id = ingredient.Id;
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var         repo       = new IngredientRepository(db);
                Ingredients ingredient = (Ingredients)repo.GetById(id);

                Assert.NotEqual(0, ingredient.Id);
                Assert.Equal("Test By Id", ingredient.Name);
                Assert.Equal(10, ingredient.Stock);
            }
        }
Пример #12
0
 public IngredientFacade(
     IngredientRepository ingredientRepository,
     IMapper mapper)
 {
     this.ingredientRepository = ingredientRepository;
     this.mapper = mapper;
 }
Пример #13
0
        private void FillOrRefreshTreeOfRecipes()
        {
            recipesTreeView.Nodes.Clear();

            var recipes = new RecipeRepository(_connectionString).GetAll();

            foreach (var recipe in recipes)
            {
                TreeNode dishNode = new TreeNode();

                if (recipesTreeView.Nodes.ContainsKey(recipe.DishID.ToString()))
                {
                    dishNode = recipesTreeView.Nodes.Find(recipe.DishID.ToString(), false).First();
                }
                else
                {
                    var dishName = new DishRepository(_connectionString).GetById(recipe.DishID)?.DishName;
                    dishNode = recipesTreeView.Nodes.Add(recipe.DishID.ToString(), dishName);
                }

                foreach (var pair in recipe.IngredientIdsAndQuantities)
                {
                    var ingr     = new IngredientRepository(_connectionString).GetById(pair.Key);
                    var unitName = new UnitRepository(_connectionString).GetAll().FirstOrDefault(x => x.UnitID == ingr.UnitID).UnitName;
                    dishNode.Nodes.Add(ingr.IngredientName + " " + pair.Value + " " + unitName);
                }
            }
        }
Пример #14
0
        private void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                this.Height     = 295;
                panel2.Enabled  = true;
                panel2.Visible  = true;
                panel3.Location = position;

                IngredientRepository source = new IngredientRepository();
                ingredientCollection = source.GetDataSource().Select(n => n.ToString()).ToList();
                bsIngredientCollection.DataSource = ingredientCollection;
                comboBox1.DataSource   = bsIngredientCollection;
                comboBox1.SelectedItem = null;
                maskedTextBox1.Text    = textBox1.Text = "";
                recept.Clear();
                listBox1.DataSource = null;
                listBox1.Items.Clear();
            }
            else
            {
                this.Height     = 125;
                panel2.Enabled  = false;
                panel2.Visible  = false;
                panel3.Location = panel2.Location;
                textBox1.Text   = "";
            }
        }
Пример #15
0
        private void Button3_Click(object sender, EventArgs e)
        {
            try
            {
                IngredientRepository source = new IngredientRepository();

                var someElement = receipt.FirstOrDefault(n => n.Key.Name == comboBox1.SelectedItem.ToString()).Key;

                if (someElement == null)
                {
                    receipt.Add(source.GetDataSource().
                                FirstOrDefault(ingredient => ingredient.Name == comboBox1.SelectedItem.ToString()) ?? throw new InvalidOperationException(),
                                Double.Parse(maskedTextBox1.Text));
                    listBox1.DataSource = receipt.Select(element => element.Key.ToString() + " " + String.Format("{0:f3}", element.Value)).ToList();
                }
                this.maskedTextBox1.Text = "";
            }
            catch (FormatException)
            {
                MessageBox.Show(@"Не всі поля заповнені.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show(@"Інгредієнт не вибраний або заповнені не всі поля для нього.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #16
0
 public ProductService(DatabaseContext context, IngredientService ingredientService)
 {
     _productRepository            = new ProductRepository(context);
     _ingredientRepository         = new IngredientRepository(context);
     _productCompositionRepository = new ProductCompositionRepository(context);
     _ingredientService            = ingredientService;
 }
 public IngredientService(DatabaseContext context, PubChemService pubChemService)
 {
     _ingredientRepository = new IngredientRepository(context);
     _hsRepository         = new HazardStatementRepository(context);
     _ihsRepository        = new IngredientHazardStatementRepository(context);
     _pubChemService       = pubChemService;
 }
Пример #18
0
        public void AddIngredient_NewRecordAddedWithProperValues()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>()
                            .UseInMemoryDatabase(databaseName: $"IngredientDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeIngredient = new FakeIngredient {
            }.Generate();

            //Act
            using (var context = new CarbonKitchenDbContext(dbOptions))
            {
                var service = new IngredientRepository(context, new SieveProcessor(sieveOptions));

                service.AddIngredient(fakeIngredient);

                context.SaveChanges();
            }

            //Assert
            using (var context = new CarbonKitchenDbContext(dbOptions))
            {
                context.Ingredients.Count().Should().Be(1);

                var ingredientById = context.Ingredients.FirstOrDefault(i => i.IngredientId == fakeIngredient.IngredientId);

                ingredientById.Should().BeEquivalentTo(fakeIngredient);
                ingredientById.IngredientId.Should().Be(fakeIngredient.IngredientId);
                ingredientById.Name.Should().Be(fakeIngredient.Name);
                ingredientById.Unit.Should().Be(fakeIngredient.Unit);
                ingredientById.Amount.Should().Be(fakeIngredient.Amount);
            }
        }
Пример #19
0
        public static void Main(string[] args)
        {
            //Setup Database
            var mj = new MakeJsonFiles(new FileClient());

            mj.CreateAllTables();

            //Poor Man DI
            var ingredientRepository        = new IngredientRepository(new FileClient());
            var recipeRepository            = new RecipeRepository(new FileClient());
            var recipeIngredientRespository = new RecipeIngredientRepository(new FileClient());
            var recipeManager = new RecipeManager(
                ingredientRepository,
                recipeRepository,
                recipeIngredientRespository
                );

            //Start Program
            var recipes = recipeManager.GetAll();

            foreach (var recipe in recipes)
            {
                var receipt = new RecipeReceipt(recipe);
                Console.WriteLine(receipt.ToString());
            }
        }
Пример #20
0
 public UnitOfWork(IDataManager dataManager)
 {
     _entities   = new Entities(dataManager);
     Ingredients = new IngredientRepository(_entities);
     Recipes     = new RecipeRepository(_entities);
     Categories  = new CategoryRepository(_entities);
 }
Пример #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            IngredientRepository            ingredientRepository            = new IngredientRepository();
            IngredientsForProductRepository ingredientsForProductRepository = new IngredientsForProductRepository();

            Ingredient selectedIngredient = ingredientRepository.GetDataSource().FirstOrDefault(n => n.Name == comboBox1.SelectedItem.ToString());

            if (selectedIngredient == null)
            {
                MessageBox.Show("Інгредієнт не вибрано.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var ingredientInReceipts = ingredientsForProductRepository.GetDataSource().Where(element => element.IngredientId == ingredient.Id).ToList();

            foreach (var item in ingredientInReceipts)
            {
                item.IngredientId = selectedIngredient.Id;

                ingredientsForProductRepository.Edit(item);
            }

            ingredientRepository.Delete(ingredient);

            MessageBox.Show("Інгредієнт успішно замінено і видалено.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Пример #22
0
        private void btnAddDish_Click(object sender, System.EventArgs e)
        {
            var dishId = _order.Dishes.Find(x => x.DishName == cmbBoxDishes.Text).DishID;

            var recipe = new RecipeRepository(_connectionString).GetById(dishId);

            if (recipe != null)
            {
                _order.DishesAndCounts.Add(dishId, (int)numInputPortion.Value);

                var ingrRep = new IngredientRepository(_connectionString);

                foreach (var ingrId in recipe.IngredientIdsAndQuantities.Keys)
                {
                    _order.Total += recipe.IngredientIdsAndQuantities[ingrId] * ingrRep.GetById(ingrId).UnitPrice *(int)numInputPortion.Value;
                }
            }
            else
            {
                MessageBox.Show("Добавьте рецепт для этого блюда");
            }


            DialogResult = DialogResult.OK;
            Close();
        }
Пример #23
0
        public IngredientRepositoryTests()
        {
            _dbContextFactory = new DbContextInMemoryFactory(nameof(IngredientRepositoryTests));
            using var dbx     = _dbContextFactory.Create();
            dbx.Database.EnsureCreated();

            _ingredientRepositorySUT = new IngredientRepository(_dbContextFactory);
        }
Пример #24
0
        public void GetAllIngredient_should_return_data()
        {
            var repo        = new IngredientRepository();
            var ingredients = repo.GetAllIngredients();

            Assert.IsNotNull(ingredients);
            Assert.IsTrue(ingredients.Any());
        }
Пример #25
0
 public StepType(IngredientRepository ingredientRepository)
 {
     Field(t => t.StepId);
     Field(t => t.RecipeId);
     Field(t => t.StepOrderId).Description("The order position of the current step in the list.");
     Field(t => t.Description);
     Field <ListGraphType <IngredientType> >(nameof(Step.Ingredients), resolve: context => ingredientRepository.GetAll());
 }
Пример #26
0
        public void GetAllIngredientMix_should_return_data()
        {
            var repo  = new IngredientRepository();
            var mixes = repo.GetAllMixes();

            Assert.IsNotNull(mixes);
            Assert.IsTrue(mixes.Any());
        }
Пример #27
0
 public IngredientsController(IngredientRepository ingredientRepository,
                              PubChemService pubChemService,
                              IngredientService ingredientService)
 {
     _ingredientRepository = ingredientRepository;
     _ingredientService    = ingredientService;
     _pubChemService       = pubChemService;
 }
Пример #28
0
        public void Setup()
        {
            //setup the connections and context
            SetupConnectionAndContext();

            //create the repository for ingredients
            ingredientRepository = new IngredientRepository(Context);
        }
        protected override void LoadTestData()
        {
            var repository = new IngredientRepository();

            repository.SaveOrUpdate(new Ingredient {Name = "Pannbiff"});
            repository.SaveOrUpdate(new Ingredient {Name = "Abborre"});
            repository.SaveOrUpdate(new Ingredient {Name = "abborgine"});
        }
Пример #30
0
    public static Ingredient LookupFood(int id)
    {
        Ingredient foo           = new Ingredient();
        var        nomrepository = new IngredientRepository();

        foo = nomrepository.GetById(id);
        return(foo);
    }
        public void shouldReturnmatchingItemsForSearchParamter()
        {
            var repository = new IngredientRepository();
            var ingredients = repository.Search("abb");

            Assert.That(ingredients.Count(), Is.GreaterThan(0));
            Assert.That(ingredients.ToList().TrueForAll(x => x.Name.StartsWith("Abb", true, Thread.CurrentThread.CurrentCulture)));
        }
        public void shouldGetIngredientByName()
        {
            var repository = new IngredientRepository() as IIngredientRepository;

            var ingredient = repository.Get("Pannbiff");

            Assert.That(ingredient.Name, Is.EqualTo("Pannbiff"));
        }
Пример #33
0
 public DishController(DishRepository repository, Order_DishRepository orderDishRepository, OrderRepository orderRepository, TransactionRepository transactionRepository, IngredientRepository ingredientRepository, Dish_IngredientRepository dishIngredientRepository)
 {
     _repository               = repository ?? throw new ArgumentNullException(nameof(repository));
     _orderDishRepository      = orderDishRepository ?? throw new ArgumentNullException(nameof(orderDishRepository));
     _orderRepository          = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
     _transactionRepository    = transactionRepository ?? throw new ArgumentNullException(nameof(transactionRepository));
     _ingredientRepository     = ingredientRepository ?? throw new ArgumentNullException(nameof(ingredientRepository));
     _dishIngredientRepository = dishIngredientRepository ?? throw new ArgumentException(nameof(dishIngredientRepository));
 }
Пример #34
0
 public IngredientRepositoryTests()
 {
     _dbContextFactory = new DbContextInMemoryFactory(nameof(IngredientRepositoryTests));
     using (var dbx = _dbContextFactory.CreateDbContext())
     {
         dbx.Database.EnsureCreatedAsync().GetAwaiter().GetResult();
     }
     _ingredientRepositorySUT = new IngredientRepository(_dbContextFactory);
 }
        public void shouldMatchBothUpperAndLowerCaseOnName()
        {
            var repository = new IngredientRepository() as IIngredientRepository;

            var ingredient = repository.Get("pannbiff");

            Assert.That(ingredient, Is.Not.Null);
            Assert.That(ingredient.Name, Is.EqualTo("Pannbiff"));
        }
Пример #36
0
 public HomeService(IMapper mapper, ItemRepository itemRepository, CategoryPortionRepository categoryPortionRepository, CategoryRepository categoryRepository, MealRepository mealRepository, IngredientRepository ingredientRepository)
 {
     _mapper                    = mapper;
     _itemRepository            = itemRepository;
     _categoryPortionRepository = categoryPortionRepository;
     _categoryRepository        = categoryRepository;
     _mealRepository            = mealRepository;
     _ingredientRepository      = ingredientRepository;
 }
Пример #37
0
 public Collector(IDatabaseContext context)
 {
     _context = context;   
     Items = new ItemRepository(_context);
     Ingredients = new IngredientRepository(_context);
     Foodplans = new FoodplanRepository(_context);
     Shoppinglists = new ShoppinglistRepository(_context);
     Recipes = new RecipeRepository(_context);
     Users = new UserRepository(_context); 
             
 }
Пример #38
0
        private void clearIngredients()
        {
            var userIngredientRepository = new UserIngredientRepository();
            var userIngredients = new UserIngredientRepository().GetAll();
            foreach (var userIngredient in userIngredients) {
                userIngredientRepository.Delete(userIngredient);
            }

            ingredientRepository = new IngredientRepository();
            var ingredients = ingredientRepository.GetAll();
            foreach (var ingredient in ingredients) {
                ingredientRepository.Delete(ingredient);
            }

            NHibernateSession.Current.Flush();
        }
Пример #39
0
 /// <summary>
 /// Initialize the database and repositories. Inject the database context to repositories.
 /// </summary>
 public BaseController()
 {
     var db = new BarContext();
     BarRepository = new BarRepository(db);
     BottleRepository = new BottleRepository(db);
     DrinkRepository = new DrinkRepository(db);
     DrinkBarRepository = new DrinkBarRepository(db);
     EventRepository = new EventRepository(db);
     IngredientDrinkRepository = new IngredientDrinkRepository(db);
     IngredientRepository = new IngredientRepository(db);
     OrderDrinkRepository = new OrderDrinkRepository(db);
     OrderRepository = new OrderRepository(db);
     QuantityRepository = new QuantityRepository(db);
     UnitRepository = new UnitRepository(db);
     UserBarRepository = new UserBarRepository(db);
     UserRepository = new UserRepository(db);
     UserRoleRepository = new UserRoleRepository(db);
 }
        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();
        }
Пример #41
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);
            }
        }
 public IngredientController()
 {
     _repository = ObjectFactory.GetRepositoryInstance<Ingredient, IngredientRepository>(new DbContextFactory().GetFitnessRecipeEntities());
 }