コード例 #1
0
        public void UpdateRecipe(WhatYouGotLibrary.Models.Recipe recipe)
        {
            Entities.Recipe currentRecipe = _context.Recipe.Find(recipe.Id);
            Entities.Recipe newRecipe     = Mapper.Map(recipe);

            _context.Entry(currentRecipe).CurrentValues.SetValues(newRecipe);
        }
コード例 #2
0
ファイル: DTOConverter.cs プロジェクト: torcher/BadMelon
        public static Recipe ConvertToDTO(this Entities.Recipe recipe)
        {
            List <Ingredient> ingredients = recipe.Ingredients.ConvertToDTOs();
            var steps = recipe.Steps.ConvertToDTOs();

            return(new Recipe {
                ID = recipe.ID, Name = recipe.Name, Ingredients = ingredients, Steps = steps
            });
        }
コード例 #3
0
        /// <summary>
        /// Method to convert a recipe to an entity class so it can be added to the database
        /// </summary>
        /// <param name="recipe">The recipe to be converted</param>
        /// <returns>An instance of the recipe entity</returns>
        private Entities.Recipe CreateRecipeEntity(RecipeDTO recipe)
        {
            var recipeEntity = new Entities.Recipe
            {
                Name = recipe.Name
            };

            return(recipeEntity);
        }
コード例 #4
0
ファイル: DTOConverter.cs プロジェクト: torcher/BadMelon
 public static Entities.Step ConvertToEntity(this Step step, Entities.Recipe Recipe)
 {
     return(new Entities.Step
     {
         ID = step.ID,
         Recipe = Recipe,
         RecipeId = Recipe.ID,
         Order = step.Order,
         Text = step.Text,
         CookTime = step.CookTime.FromRecipeFormat(),
         PrepTime = step.PrepTime.FromRecipeFormat()
     });
 }
コード例 #5
0
        public ActionResult CreateRecipe(AddRecipeViewModel model)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                var recipe = new Entities.Recipe
                {
                    Name            = model.Name,
                    Description     = model.Description,
                    Vegetarian      = model.Vegetarian,
                    PreparationTime = model.PreparationTime,
                    Added           = DateTime.Now,
                    Author          = null
                };

                List <Ingredient> ingredients = new List <Ingredient>();
                ICollection <IngredientCreateViewModel> ingredientsInfo;
                if (CookieHelper.TryReadCookie <ICollection <IngredientCreateViewModel> >(
                        currentRecipeCookie, createdRecipeIngredients, out ingredientsInfo))
                {
                    foreach (var ingr in ingredientsInfo)
                    {
                        ingredients.Add(new Ingredient {
                            Name      = ingr.Alias,
                            ProductId = ingr.ProductId,
                            Product   = ProductManager.FindById(ingr.ProductId),
                            Quantity  = ingr.Quantity,
                            Recipe    = recipe
                        });
                    }
                }
                recipe.Ingredients = ingredients;

                RecipeManager.AddToCategory(recipe, RecipeManager.FindCategoryById(model.CategoryId));
                RecipeManager.Save();

                CookieHelper.DeleteCookie(currentRecipeCookie);

                return(RedirectToAction("CreateResult"));
            }

            ViewBag.Categories        = RecipeManager.RecipeCategories.ToSelectList <Entities.RecipeCategory, RecipeCategoryInfo>();
            ViewBag.OrderedCategories = ProductManager.ProductCategories.ToOrderedSelectList();

            return(View("Create"));
        }
コード例 #6
0
        public RecipeVM Get(int id)
        {
            var model = new RecipeVM();

            Entities.Recipe recipeFromService = _recipesService.GetRecipeById(id);
            _mapper.Map(recipeFromService, model);
            // get image from azure
            if (model.ImageUrl != null)
            {
                //var base64 = _recipesService.GetBase64RecipeImage(model.ImageUrl);
                //model.ImageFile = base64;
                var url = _recipesService.GetUri(model.ImageUrl);
                model.ImageFile = url;
            }
            model.Ingredients.OrderBy(i => i.PositionNo).ToList();
            model.MethodItems.OrderBy(i => i.StepNo).ToList();
            return(model);
        }
コード例 #7
0
ファイル: DTOConverter.cs プロジェクト: torcher/BadMelon
 public static ICollection <Entities.Step> ConvertToEntities(this Step[] steps, Entities.Recipe recipe) => steps.Select(s => s.ConvertToEntity(recipe)).ToArray();
コード例 #8
0
        public WhatYouGotLibrary.Models.Recipe GetRecipeById(int id)
        {
            Entities.Recipe recipe = _context.Recipe.Find(id);

            return(Mapper.Map(recipe));
        }
コード例 #9
0
 public void DeleteRecipeById(int id)
 {
     Entities.Recipe recipe = _context.Recipe.Find(id);
     _context.Remove(recipe);
 }
コード例 #10
0
 public void AddRecipe(WhatYouGotLibrary.Models.Recipe recipe)
 {
     Entities.Recipe newRecipe = Mapper.Map(recipe);
     _context.Add(newRecipe);
 }
コード例 #11
0
        public ActionResult CreateRecipe(AddRecipeViewModel model)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);
            if (ModelState.IsValid)
            {
                var recipe = new Entities.Recipe
                {
                    Name = model.Name,
                    Description = model.Description,
                    Vegetarian = model.Vegetarian,
                    PreparationTime = model.PreparationTime,
                    Added = DateTime.Now, 
                    Author = null
                };

                List<Ingredient> ingredients = new List<Ingredient>();
                ICollection<IngredientCreateViewModel> ingredientsInfo;
                if (CookieHelper.TryReadCookie<ICollection<IngredientCreateViewModel>>(
                    currentRecipeCookie, createdRecipeIngredients, out ingredientsInfo))
                {
                    foreach (var ingr in ingredientsInfo)
	                {
		                ingredients.Add(new Ingredient{ 
                            Name = ingr.Alias, 
                            ProductId = ingr.ProductId,
                            Product = ProductManager.FindById(ingr.ProductId), 
                            Quantity = ingr.Quantity,
                            Recipe = recipe});
	                }
                }
                recipe.Ingredients = ingredients;

                RecipeManager.AddToCategory(recipe, RecipeManager.FindCategoryById(model.CategoryId));
                RecipeManager.Save();

                CookieHelper.DeleteCookie(currentRecipeCookie);

                return RedirectToAction("CreateResult");
            }

            ViewBag.Categories = RecipeManager.RecipeCategories.ToSelectList<Entities.RecipeCategory, RecipeCategoryInfo>();
            ViewBag.OrderedCategories = ProductManager.ProductCategories.ToOrderedSelectList();

            return View("Create");
        }