Exemple #1
0
        public IActionResult EditRecipe(int id, string order_by = null)
        {
            var recipe_model = CastRecipeToModel(_recipeRepository.GetById(id));

            recipe_model.OrderBy = order_by;

            return(View(recipe_model));
        }
        public IActionResult Get(int id)
        {
            var userProfile = GetCurrentUserProfile();
            var recipe      = _recipeRepository.GetById(id);

            if (recipe == null || recipe.UserProfileId != userProfile.Id)
            {
                return(NotFound());
            }
            return(Ok(recipe));
        }
        public void GetById_FromSeeded_DoesNotThrowAndEqualsSeeded()
        {
            //Arrange
            RecipeDetailModel detailModel = RecipeMapper.MapEntityToDetailModel(DAL.Seeds.RecipeSeeds.RecipeEntity);

            //Act
            RecipeDetailModel returnedModel = _repositorySUT.GetById(detailModel.Id);

            //Assert
            Assert.Equal(detailModel, returnedModel);
        }
Exemple #4
0
        public RecipeDetailModel GetById(Guid id)
        {
            var recipeEntity = recipeRepository.GetById(id);

            recipeEntity.IngredientAmounts = ingredientAmountRepository.GetByRecipeId(id);
            foreach (var ingredientAmount in recipeEntity.IngredientAmounts)
            {
                ingredientAmount.Ingredient = ingredientRepository.GetById(ingredientAmount.IngredientId);
            }
            return(mapper.Map <RecipeDetailModel>(recipeEntity));
        }
Exemple #5
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            int    id     = Convert.ToInt32(listViewRecipes.SelectedItems[0].Text);
            Recipe recipe = repository.GetById(id);
            var    form   = new FormNewRecipe(recipe, true);

            listViewRecipes.Items.Clear();
            form.ShowDialog();
            DisableButtons();
        }
Exemple #6
0
        //
        // GET: /Recipe/Edit/5

        public ActionResult Edit(Guid id)
        {
            Recipe recipe = RecipeRepository.GetById(id);

            if (recipe == null)
            {
                return(HttpNotFound());
            }
            return(View(recipe));
        }
Exemple #7
0
        public ActionResult Delete(int id)
        {
            var recipe = RecipeRepository.GetById(id);

            RecipeRepository.DeleteSpecials(recipe.Guid);
            RecipeRepository.Delete(recipe.Guid);
            RecipeRepository.DeleteVotes(recipe.Guid);
            ViewBag.Response           = Globals.InfoRecipeDeleted;
            SessionHandler.ForceReload = true;
            return(View("Response"));
        }
Exemple #8
0
 public ActionResult <Recipe> Get(int id)
 {
     try
     {
         return(Ok(_repo.GetById(id)));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Exemple #9
0
        private RecipeModel Load(int id = 0)
        {
            var model = GetModel();

            if (id != 0)
            {
                var recipe = RecipeRepository.GetById(id);
                if (recipe != null)
                {
                    var category         = RecipeRepository.GetCategoryById(recipe.CategoryId).HtmlDecode();
                    var specials         = RecipeRepository.GetSpecialsForRecipe(recipe.Guid);
                    var selectedSpecials = (from item in specials
                                            from special in model.AllSpecials
                                            where item.SpecialId == special.Id
                                            select special).ToList();
                    var selectedSpecialsAsString = (from item in specials
                                                    from special in model.AllSpecials
                                                    where item.SpecialId == special.Id
                                                    select special).Aggregate(string.Empty, (current, special) => current + (special.Name.ToLower() + ", "));
                    var dishType  = string.Empty;
                    var avgRating = RatingRepository.GetAvarage(recipe.Guid);
                    if (recipe.DishTypeId.HasValue)
                    {
                        dishType = RecipeRepository.GetDishTypeById(recipe.DishTypeId.Value);
                    }

                    if (selectedSpecialsAsString.EndsWith(", "))
                    {
                        selectedSpecialsAsString = selectedSpecialsAsString.TrimEnd(',', ' ');
                    }

                    model.Recipe = recipe;
                    model.Recipe.Name.HtmlDecode();
                    model.Recipe.Ingredients.HtmlDecode();
                    model.Recipe.Description.HtmlDecode();
                    model.Category             = category;
                    model.DishType             = dishType;
                    model.AvarageRating        = avgRating;
                    model.Specials             = selectedSpecialsAsString;
                    model.SelectedSpecials     = selectedSpecials;
                    SessionHandler.CurrentGuid = model.Recipe.Guid;
                    SessionHandler.CurrentId   = model.Recipe.Id.ToString();
                }
                else
                {
                    LogHandler.Log(nameof(RecipeController), LogType.Info, string.Format("Recipe with id: {0} could not be found", id));
                    throw new HttpException(404, "Not found");
                }
            }
            return(model);
        }
Exemple #10
0
        public void GetById_Test()
        {
            // Arrange - Create the repository
            var repository = new RecipeRepository(_context);

            // Arrange - Setup expectations
            var expectedId = 1;

            // Act - Make the repository call
            repository.FullEagerLoad();
            var actual = repository.GetById(expectedId);

            // Assert - Verify the entity
            VerifyEntity(actual, expectedId);
        }
Exemple #11
0
 public Recipe GetById(int id)
 {
     return(recipeRepository.GetById(id));
 }
Exemple #12
0
 public Recipe GetById(int id)
 {
     return(_repo.GetById(id));
 }
        public RecipeModel GetById(int id)
        {
            var author = _recipeRepository.GetById(id);

            return(_recipeMapper.MapRecipeEntityToRecipeModel(author));
        }
    public static void getRecipeIntoGlobal(int id)
    {
        RecipeRepository rr = new RecipeRepository();

        Global.foods = rr.GetById(id);
    }
 public RecipeDetailModel GetRecipe(Guid id)
 {
     return(recipeRepository.GetById(id));
 }