public async void CannotEditRecipeIngredient()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CannotEditRecipeIngredient").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                RecipeIngredients recipeIng = new RecipeIngredients();
                recipeIng.RecipeID      = 1;
                recipeIng.IngredientsID = 1;
                recipeIng.Quantity      = "1 pound";
                RecipeIngredients recipeIng2 = new RecipeIngredients();
                recipeIng2.RecipeID      = 1;
                recipeIng2.IngredientsID = 2;
                recipeIng2.Quantity      = "1 cup";
                RecipeIngredients recipeIng3 = new RecipeIngredients();
                recipeIng3.RecipeID      = 1;
                recipeIng3.IngredientsID = 3;
                recipeIng3.Quantity      = "10 stone";

                //Act
                RecipeIngredientsController recipeIngredientsController = new RecipeIngredientsController(context, configuration);
                await recipeIngredientsController.Post(recipeIng);

                await recipeIngredientsController.Post(recipeIng2);

                var result = await recipeIngredientsController.Put(5, 5, recipeIng3);

                //Assert
                Assert.IsType <BadRequestObjectResult>(result);
            }
        }
        public bool Update(RecipeIngredients model)
        {
            bool res = false;

            string sqlConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            using (SqlConnection conn = new SqlConnection(sqlConnectionString))
            {
                conn.Open();

                using (SqlCommand cmd = new SqlCommand("RecipeIngredients_Update", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", model.Id);
                    cmd.Parameters.AddWithValue("@Number", model.Number);
                    cmd.Parameters.AddWithValue("@Measurements", model.Measurements);
                    cmd.Parameters.AddWithValue("@Ingredient", model.Ingredient);
                    cmd.Parameters.AddWithValue("@RecipeId", model.RecipeId);

                    cmd.ExecuteNonQuery();

                    res = true;
                }

                conn.Close();
            }

            return(res);
        }
        public List <RecipeIngredients> SelectAll()
        {
            List <RecipeIngredients> recipeIngredientsList = new List <RecipeIngredients>();

            string sqlConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            using (SqlConnection conn = new SqlConnection(sqlConnectionString))
            {
                conn.Open();

                using (SqlCommand cmd = new SqlCommand("RecipeIngredients_SelectAll", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        RecipeIngredients model = Mapper(reader);
                        recipeIngredientsList.Add(model);
                    }
                }

                conn.Close();
            }

            return(recipeIngredientsList);
        }
 private void DeleteIngredientExecute(object obj)
 {
     if (obj is Ingredient ingredient)
     {
         RecipeIngredients.Remove(ingredient);
     }
 }
        public RecipeIngredients SelectById(int id)
        {
            RecipeIngredients model = new RecipeIngredients();

            string sqlConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            using (SqlConnection conn = new SqlConnection(sqlConnectionString))
            {
                conn.Open();

                using (SqlCommand cmd = new SqlCommand("RecipeIngredients_SelectById", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", id);
                    SqlDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        model = Mapper(reader);
                    }
                }

                conn.Close();
            }

            return(model);
        }
        public IHttpActionResult PutRecipeIngredients(int id, RecipeIngredients recipeIngredients)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != recipeIngredients.ID)
            {
                return(BadRequest());
            }

            db.Entry(recipeIngredients).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeIngredientsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public int Create(RecipeIngredients model)
        {
            int res = 0;

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("RecipeIngredients_Insert", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Number", model.Number);
                    cmd.Parameters.AddWithValue("@Measurements", model.Measurements);
                    cmd.Parameters.AddWithValue("@Ingredient", model.Ingredient);
                    cmd.Parameters.AddWithValue("@RecipeId", model.RecipeId);


                    SqlParameter param = new SqlParameter("@Id", SqlDbType.Int);
                    param.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(param);

                    cmd.ExecuteNonQuery();
                    res = (int)cmd.Parameters["@Id"].Value;
                }
                conn.Close();
            }
            return(res);
        }
Beispiel #8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Find RecipesModel
            FindAndMaybeSetDb();

            // Load Ingredients collection
            ingredients = new Ingredients(Db);

            // Load Categories collection
            categories = new Categories(Db);

            // Load Recipe Ingredients collection
            recipeIngredients = new RecipeIngredients(Db);

            // Load Steps collection and set an empty step
            steps = new Steps(Db);

            // Ensure steps are loaded based on Order property
            LbSteps.DataContext = Recipes.Current.Steps.OrderBy(s => s.Order);

            // Refresh all controls that use these categories
            RefreshStep();
            RefreshIngredients();
            RefreshCategories();

            // Prevent false flag pending changes to recipe
            PendingChanges = false;
        }
        public async void CanGetAllRecipeIngredient()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanGetAllRecipeIngredient").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                RecipeIngredients recipeIng = new RecipeIngredients();
                recipeIng.RecipeID      = 1;
                recipeIng.IngredientsID = 1;
                recipeIng.Quantity      = "1 pound";
                RecipeIngredients recipeIng2 = new RecipeIngredients();
                recipeIng2.RecipeID      = 1;
                recipeIng2.IngredientsID = 2;
                recipeIng2.Quantity      = "1 cup";
                RecipeIngredients recipeIng3 = new RecipeIngredients();
                recipeIng3.RecipeID      = 1;
                recipeIng3.IngredientsID = 3;
                recipeIng3.Quantity      = "10 stone";

                //Act
                RecipeIngredientsController recipeIngredientsController = new RecipeIngredientsController(context, configuration);
                await recipeIngredientsController.Post(recipeIng);

                await recipeIngredientsController.Post(recipeIng2);

                await recipeIngredientsController.Post(recipeIng3);

                var result = recipeIngredientsController.Get().ToList();

                //Assert
                Assert.Equal(3, result.Count);
            }
        }
        public async void CannotCreateRecipeIngredient()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CannotCreateRecipeIngredient").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                RecipeIngredients recipeIng = new RecipeIngredients();
                recipeIng.RecipeID      = 1;
                recipeIng.IngredientsID = 1;
                recipeIng.Quantity      = "1 pound";
                RecipeIngredients recipeIng2 = new RecipeIngredients();
                recipeIng2.RecipeID      = 1;
                recipeIng2.IngredientsID = 2;
                recipeIng2.Quantity      = "1 cup";

                //Act
                RecipeIngredientsController recipeIngredientsController = new RecipeIngredientsController(context, configuration);
                await recipeIngredientsController.Post(recipeIng);

                await recipeIngredientsController.Post(recipeIng2);

                var result = await recipeIngredientsController.Delete(4, 4);

                //Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Beispiel #11
0
        public IActionResult AddRecipe(string recipeName, string recipePrice, string[] ingredientList)
        {
            int lastInsertedId = 0;

            // Recipe entry
            Recipes recipe = new Recipes()
            {
                RecipeName  = recipeName,
                RecipePrice = recipePrice
            };

            _context.Recipes.Add(recipe);
            _context.SaveChanges();

            lastInsertedId = recipe.RecipeId;

            // Recipe_Ingredients entry (one to many)
            for (int i = 0; i < ingredientList.Length; i++)
            {
                RecipeIngredients recipeIngredients = new RecipeIngredients()
                {
                    IngredientItemId = int.Parse(ingredientList[i]),
                    RecipeId         = lastInsertedId
                };

                _context.RecipeIngredients.Add(recipeIngredients);
                _context.SaveChanges();
            }

            return(RedirectToAction("Recipes", "Recipe", new { status = "Success" }));
        }
Beispiel #12
0
        public async Task <IActionResult> Edit(int id, [Bind("RecipeIngredientId,IngredientId,Amount,RecipeId")] RecipeIngredients recipeIngredients)
        {
            if (id != recipeIngredients.RecipeIngredientId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recipeIngredients);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecipeIngredientsExists(recipeIngredients.RecipeIngredientId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IngredientId"] = new SelectList(_context.Ingredients, "IngredientId", "IngredientId", recipeIngredients.IngredientId);
            ViewData["RecipeId"]     = new SelectList(_context.Recipes, "RecipeId", "RecipeId", recipeIngredients.RecipeId);
            return(View(recipeIngredients));
        }
Beispiel #13
0
        public void CombineIngredients()
        {
            foreach (Recipe recipe1 in Recipes)
            {
                foreach (List <RecipeIngredient> recipeIngredientsList1 in recipe1.RecipeIngredients)
                {
                    foreach (RecipeIngredient recipeIngredient1 in recipeIngredientsList1)
                    {
                        //if (recipeIngredient1.Selected)
                        {
                            recipeIngredient1.RecipeRequired = recipeIngredient1.GetRecipeRequired();



                            //search RecipeIngredients for item
                            bool found = false;
                            foreach (RecipeIngredient recipeIngredient in RecipeIngredients)
                            {
                                if (recipeIngredient.Ingredient.ExternalID == recipeIngredient1.Ingredient.ExternalID || recipeIngredient.Ingredient.Description == recipeIngredient1.Ingredient.Description)
                                {
                                    found = true;

                                    recipeIngredient.RecipeRequired += recipeIngredient1.RecipeRequired;
                                }
                            }
                            if (!found)
                            {
                                RecipeIngredients.Add(recipeIngredient1);
                            }
                        }
                    }
                }
            }
        }
Beispiel #14
0
 public void Save()
 {
     Categories.Save();
     Ingredients.Save();
     RecipeIngredients.Save();
     Recipes.Save();
 }
Beispiel #15
0
        public void CanGetRecipeIngredientsIngredientsID()
        {
            RecipeIngredients recipeIngredients = new RecipeIngredients();

            recipeIngredients.ingredientsID = 1;

            Assert.Equal(1, recipeIngredients.ingredientsID);
        }
        public void CanGetIngredientsID()
        {
            RecipeIngredients recipe = new RecipeIngredients();

            recipe.IngredientsID = 44;

            Assert.Equal(44, recipe.IngredientsID);
        }
        public void CanGetQuantity()
        {
            RecipeIngredients recipe = new RecipeIngredients();

            recipe.Quantity = "1/2 cup";

            Assert.Equal("1/2 cup", recipe.Quantity);
        }
Beispiel #18
0
        public void CanGetRecipeIngredientsQuantity()
        {
            RecipeIngredients recipeIngredients = new RecipeIngredients();

            recipeIngredients.quantity = "1 cup";

            Assert.Equal("1 cup", recipeIngredients.quantity);
        }
Beispiel #19
0
        public Dictionary <Guid, RecipeIngredients[]> GetIndexedRecipeIngredients()
        {
            if (indexedRecipeIngredients == null)
            {
                indexedRecipeIngredients = RecipeIngredients.GroupBy(r => r.RecipeId).ToDictionary(g => g.Key, i => i.ToArray());
            }

            return(indexedRecipeIngredients);
        }
Beispiel #20
0
        public void Equals_ReturnsTrueIfAllAreTheSame_RecipeIngredients()
        {
            // Arrange, Act
            RecipeIngredients firstRecipeIngredients  = new RecipeIngredients(1, 1);
            RecipeIngredients secondRecipeIngredients = new RecipeIngredients(1, 1);

            // Assert
            Assert.AreEqual(firstRecipeIngredients, secondRecipeIngredients);
        }
Beispiel #21
0
        public void CanSetRecipeIngredientsRecipeID()
        {
            RecipeIngredients recipeIngredients = new RecipeIngredients();

            recipeIngredients.recipeID = 2;
            recipeIngredients.recipeID = 1;

            Assert.Equal(1, recipeIngredients.recipeID);
        }
        public void CanSetQuantity()
        {
            RecipeIngredients recipe = new RecipeIngredients();

            recipe.Quantity = "1 oz";
            recipe.Quantity = "5 lbs";

            Assert.Equal("5 lbs", recipe.Quantity);
        }
Beispiel #23
0
        public async Task Submit()
        {
            try
            {
                IsBusy = true;

                RecipeModel recipeModel = new RecipeModel
                {
                    Name        = RecipeName,
                    Ingredients = RecipeIngredients.ToList(),
                    Instruction = RecipeInstructions,
                    NameOfImage = ImagePath,
                    IsPublic    = IsPublic,
                };

                if (recipeModel.NameOfImage == ImageConstants.LoadDefaultImage)
                {
                    recipeModel.NameOfImage = "";
                }

                if (_addOrEdit == AddOrEdit.Add)
                {
                    await _recipesEndPointAPI.InsertRecipe(recipeModel);

                    DependencyService.Get <IMessage>().LongAlert("Dodano pomyślnie!");
                    MessagingService.Current.SendMessage(EventMessages.AddOrEditViewModelPage);
                }
                else if (_addOrEdit == AddOrEdit.Edit)
                {
                    recipeModel.RecipeId = _recipeId;
                    var result = await _recipesEndPointAPI.EditRecipe(recipeModel);

                    if (result)
                    {
                        if (recipeModel.NameOfImage == "")
                        {
                            recipeModel.NameOfImage = ImageConstants.LoadDefaultImage;
                        }

                        OnPropertyChanged(nameof(ImagePath));
                        OnPropertyChanged(nameof(CanDeleteImage));

                        DependencyService.Get <IMessage>().LongAlert("Zaktualizowano pomyślnie!");
                        MessagingService.Current.SendMessage(EventMessages.AddOrEditViewModelPage);
                    }
                }
            }
            catch (Exception ex)
            {
                // _logger.Error("Got exception", ex);
                await Application.Current.MainPage.DisplayAlert("Błąd", ex.Message, "Ok");
            }
            finally
            {
                IsBusy = false;
            }
        }
        public void CanSetIngredientsID()
        {
            RecipeIngredients recipe = new RecipeIngredients();

            recipe.IngredientsID = 4;
            recipe.IngredientsID = 14;

            Assert.Equal(14, recipe.IngredientsID);
        }
        public IHttpActionResult GetRecipeIngredients(int id)
        {
            RecipeIngredients recipeIngredients = db.RecipeIngredients.Find(id);

            if (recipeIngredients == null)
            {
                return(NotFound());
            }

            return(Ok(recipeIngredients));
        }
        public async Task AddRecipeSubmit()
        {
            try
            {
                RecipeModel recipeModel = new RecipeModel
                {
                    Name        = RecipeName,
                    Ingredients = RecipeIngredients.ToList(),
                    Instruction = RecipeInstructions,
                    NameOfImage = ImagePath,
                    IsPublic    = IsPublic,
                };

                if (recipeModel.NameOfImage == ImageConstants.DefaultImage)
                {
                    recipeModel.NameOfImage = "";
                }

                if (_addOrEdit == AddOrEdit.Add)
                {
                    await _recipesEndPointAPI.InsertRecipe(recipeModel);

                    reloadNeeded = true;

                    await _eventAggregator.PublishOnUIThreadAsync(new LogOnEvent(reloadNeeded), new CancellationToken());
                }
                else if (_addOrEdit == AddOrEdit.Edit)
                {
                    recipeModel.RecipeId = _recipeId;
                    var result = await _recipesEndPointAPI.EditRecipe(recipeModel);

                    if (result)
                    {
                        if (recipeModel.NameOfImage == "")
                        {
                            recipeModel.NameOfImage = ImageConstants.DefaultImage;
                        }

                        NotifyOfPropertyChange(() => ImagePath);
                        NotifyOfPropertyChange(() => CanDeleteFileModel);

                        reloadNeeded = true;
                        MessageBox.Show("Zaktualizowano pomyślnie!", "Zaktualizowano", MessageBoxButton.OK, MessageBoxImage.Information);

                        await _eventAggregator.PublishOnUIThreadAsync(new LogOnEvent(reloadNeeded), new CancellationToken());
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Got exception", ex);
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
        public IHttpActionResult PostRecipeIngredients(RecipeIngredients recipeIngredients)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.RecipeIngredients.Add(recipeIngredients);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = recipeIngredients.ID }, recipeIngredients));
        }
        public ActionResult AddIngredient(int recipeId, string ingredient)
        {
            if (Ingredient.FindIngredientByName(ingredient).GetId() == 0)
            {
                Ingredient newIngredient = new Ingredient(ingredient);
                newIngredient.Save();
            }
            RecipeIngredients newPair = new RecipeIngredients(recipeId, Ingredient.FindIngredientByName(ingredient).GetId());

            newPair.Save();
            return(RedirectToAction("Detail", new { id = recipeId }));
        }
Beispiel #29
0
        public IActionResult Get([FromRoute] int recID, [FromRoute] int ingID)
        {
            RecipeIngredients RecIng = _context.RecipeIngredients
                                       .FirstOrDefault(i => i.RecipeID == recID && i.IngredientsID == ingID);

            if (RecIng == null)
            {
                return(NotFound());
            }

            return(Ok(RecIng));
        }
Beispiel #30
0
 async Task DeleteIngredient()
 {
     try
     {
         RecipeIngredients.Remove(SelectedIngredient);
         OnPropertyChanged(nameof(CanRecipeSubmit));
     }
     catch (Exception ex)
     {
         //_logger.Error("Got exception", ex);
         await Application.Current.MainPage.DisplayAlert("Błąd", ex.Message, "Ok");
     }
 }
        public RecipeResult CreateRecipe(AuthIdentity identity, Recipe recipe)
        {
            using (var session = this.GetSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    // Create Recipe
                    var recipes = new Recipes
                    {
                        Title = recipe.Title,
                        Description = recipe.Description,
                        CookTime = recipe.CookTime,
                        PrepTime = recipe.PreparationTime,
                        Credit = recipe.Credit,
                        CreditUrl = recipe.CreditUrl,
                        DateEntered = recipe.DateEntered,
                        ImageUrl = recipe.ImageUrl,
                        Rating = recipe.AvgRating,
                        ServingSize = recipe.ServingSize,
                        Steps = recipe.Method
                    };

                    session.Save(recipes);

                    // Create Ingredients
                    short displayOrder = 0;
                    recipe.Ingredients.ForEach(i =>
                    {
                        var dbIngredient = new RecipeIngredients
                        {
                            Recipe = recipes,
                            Ingredient = Ingredients.FromId(i.Ingredient.Id),
                            IngredientForm = i.Form != null ? IngredientForms.FromId(i.Form.FormId) : null,
                            Qty = i.Amount != null ? (float?)i.Amount.SizeHigh : null,
                            QtyLow = i.Amount != null ? (float?)i.Amount.SizeLow : null,
                            Unit = i.Amount != null ? i.Amount.Unit : Units.Unit,
                            Section = i.Section,
                            DisplayOrder = ++displayOrder
                        };

                        session.Save(dbIngredient);
                    });

                    // Create RecipeMetadata
                    var recipeMetadata = new RecipeMetadata
                    {
                        Recipe = recipes,
                        DietGlutenFree = recipe.Tags.HasTag(RecipeTag.GlutenFree),
                        DietNoAnimals = recipe.Tags.HasTag(RecipeTag.NoAnimals),
                        DietNomeat = recipe.Tags.HasTag(RecipeTag.NoMeat),
                        DietNoPork = recipe.Tags.HasTag(RecipeTag.NoPork),
                        DietNoRedMeat = recipe.Tags.HasTag(RecipeTag.NoRedMeat),
                        MealBreakfast = recipe.Tags.HasTag(RecipeTag.Breakfast),
                        MealDessert = recipe.Tags.HasTag(RecipeTag.Dessert),
                        MealDinner = recipe.Tags.HasTag(RecipeTag.Dinner),
                        MealLunch = recipe.Tags.HasTag(RecipeTag.Lunch),
                        NutritionLowCalorie = recipe.Tags.HasTag(RecipeTag.LowCalorie),
                        NutritionLowCarb = recipe.Tags.HasTag(RecipeTag.LowCarb),
                        NutritionLowFat = recipe.Tags.HasTag(RecipeTag.LowFat),
                        NutritionLowSodium = recipe.Tags.HasTag(RecipeTag.LowSodium),
                        NutritionLowSugar = recipe.Tags.HasTag(RecipeTag.LowSugar),
                        SkillCommon = recipe.Tags.HasTag(RecipeTag.CommonIngredients),
                        SkillEasy = recipe.Tags.HasTag(RecipeTag.EasyToMake),
                        SkillQuick = recipe.Tags.HasTag(RecipeTag.Quick)
                    };

                    session.Save(recipeMetadata);
                    transaction.Commit();

                    return new RecipeResult
                    {
                        RecipeCreated = true,
                        NewRecipeId = recipes.RecipeId
                    };
                }
            }
        }