예제 #1
0
        public int CreateRecipe(RecipeCreate model)
        {
            using (var context = new CookbookContext())
            {
                var season = new Season()
                {
                    AuthorID = userId,
                    Summer = model.Season.Summer,
                    Fall = model.Season.Fall,
                    Winter = model.Season.Winter,
                    Spring = model.Season.Spring
                };

                context.Seasons.Add(season);
                context.SaveChanges();

                var entity = new Recipe()
                {
                    AuthorID = userId,
                    Name = model.Name,
                    SeasonID = season.ID,
                    Description = model.Description,
                    DateCreated = DateTimeOffset.UtcNow,
                };

                context.Recipes.Add(entity);
                context.SaveChanges();
                return entity.ID;
            }
        }
        public bool CreateRecipe(RecipeCreate model)
        {
            bool saved;

            var entity =
                new Recipe()
            {
                //EnteredBy = model.EnteredBy,
                RecipeName   = model.RecipeName,
                RecipeAuthor = model.RecipeAuthor,
                IsPublic     = model.IsPublic,
                Ingredients  = model.Ingredients,
                Instructions = model.Instructions,
                Category     = model.Category,
                UserId       = _userId.ToString()
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Recipes.Add(entity);
                saved = ctx.SaveChanges() == 1;
            }

            var service = CreateUserRecipeService();

            service.CreateUserRecipeAuto(entity);

            return(saved);
        }
예제 #3
0
        public IEnumerable <IngredientList> GetIngredients()
        {
            using (var ctx = new ApplicationDbContext())
            {
                var query =
                    ctx
                    .Ingredients
                    .Where(e => e.IngredientShared == true || e.IngredientOwner == _userId)
                    .Select(
                        e =>
                        new IngredientList
                {
                    IngredientOwner    = e.IngredientOwner,
                    IngredientID       = e.IngredientID,
                    IngredientName     = e.IngredientName,
                    IngredientShared   = e.IngredientShared,
                    IngredientQuantity = e.IngredientQuantity,
                    IngredientQuantityUnitOfMeasurement = e.IngredientQuantityUnitOfMeasurement,
                    Protein       = e.Protein,
                    Carbohydrates = e.Carbohydrates,
                    Fat           = e.Fat,
                    Calories      = e.Calories,
                    DietaryFiber  = e.DietaryFiber
                }
                        );

                var viewModel = new RecipeCreate
                {
                    RecipeIngredientList = new MultiSelectList(query, "IngredientID", "Ingredient")
                };

                return(query.ToArray());
            }
        }
예제 #4
0
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity =
                new Recipe()
            {
                AuthorId        = _userId,
                RecipeName      = model.RecipeName,
                Description     = model.Description,
                IngredientItems = model.IngredientItems,
                Procedure       = model.Procedure,
                HasGluten       = model.HasGluten,
                HasNuts         = model.HasNuts,
                HasEggs         = model.HasEggs,
                HasSoy          = model.HasSoy,
                IsVegan         = model.IsVegan,
                IsVegetarian    = model.IsVegetarian,
                IsPescatarian   = model.IsPescatarian,
                IsKetoFriendly  = model.IsKetoFriendly,
                Difficulty      = model.Difficulty
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        // GET: Recipe/Create
        public ActionResult Create()
        {
            var service = CreateRecipeService();
            var model   = new RecipeCreate();

            service.CreateRecipeModelLoadPlans(model);
            return(View(model));
        }
예제 #6
0
        public ActionResult Create()
        {
            var recipeService = CreateRecipeService();
            var viewModel     = new RecipeCreate();

            viewModel.RecipeIngredientList = recipeService.GetIngredientList();
            //ViewBag.IngredientList = ingredients.

            return(View(viewModel));
        }
예제 #7
0
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity =
                new Recipe()
            {
                Name        = model.Name,
                Description = model.Description
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #8
0
        //public IHttpActionResult Get()
        // {
        //    RecipeService recipeService = CreateRecipeService();
        //    var recipes = recipeService.GetRecipes();
        //    return Ok(recipes);
        // }

        public IHttpActionResult Post(RecipeCreate recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateRecipeService();

            if (!service.CreateRecipe(recipe))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity =
                new Recipe()
            {
                OwnerId            = _userId,
                RecipeName         = model.RecipeName,
                RecipeIngredients  = model.RecipeIngredients,
                RecipeInstructions = model.RecipeInstructions
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Create(RecipeCreate model)
        {
            var service = CreateRecipeService();

            if (!ModelState.IsValid)
            {
                return(View(service.CreateRecipeModelLoadPlans(model)));
            }

            if (service.CreateRecipe(model))
            {
                TempData["SaveResult"] = "Your Recipe was created.";
                return(RedirectToAction("Index"));
            }

            return(View(service.CreateRecipeModelLoadPlans(model)));
        }
예제 #11
0
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity =
                new Recipe()
            {
                OwnerId    = _userId,
                RecipeName = model.RecipeName,
                //Ingredients = model.Ingredients,
                //Directions = model.Directions,
                CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #12
0
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity =
                new Recipe()
            {
                RecipeName         = model.RecipeName,
                RecipeIngredients  = model.RecipeIngredients,
                CaloriesPerServing = model.Calories,
                Servings           = model.Servings,
                Instructions       = model.Instructions,
                MediaId            = model.MediaId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #13
0
        public ActionResult Create(RecipeCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateRecipeService();


            if (service.CreateRecipe(model))
            {
                TempData["SaveResult"] = "Your recipe was created!";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Recipe could not be created.");
            return(View(model));
        }
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity =
                new Recipe()
            {
                OwnerId       = _userId,
                RecipeName    = model.RecipeName,
                Ingredients   = model.Ingredients,
                Instructions  = model.Instructions,
                SourceId      = model.SourceId,
                TypeOfCuisine = model.TypeOfCuisine,
                TypeOfDish    = model.TypeOfDish
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #15
0
        public ActionResult Create(RecipeCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = CreateRecipeService();
            int?id      = service.CreateRecipe(model);

            if (id != null)
            {
                TempData["SaveResult"] = "Your recipe was created.";
                return(RedirectToAction("Add", "Plating", new { id }));
            }
            else
            {
                ModelState.AddModelError("", "Recipe could not be created.");
                return(View(model));
            }
        }
예제 #16
0
        public RecipeCreate CreateRecipeModelLoadPlans(RecipeCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var query =
                    ctx
                    .Plans
                    .Where(plan => plan.UserId == _userId && plan.IsSaved == true)
                    .Select(plan =>
                            new PlanListItem
                {
                    PlanId = plan.PlanId,
                    Title  = plan.Title
                }).ToList();

                model.Plans = query;

                return(model);
            }
        }
예제 #17
0
        public ActionResult Create(RecipeCreate recipe)
        {
            if (!ModelState.IsValid)
            {
                return(View(recipe));
            }

            var service = RecipeService();

            if (service.CreateRecipe(recipe))

            {
                TempData["SaveResult"] = "MMMMM, that's a TASTY Recipe!NOM NOM NOM";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Lame! Not you, this app...Well?.. No Recipe was created. Don't Give up!");


            return(View(recipe));
        }
예제 #18
0
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity =
                new Recipe()
            {
                UserId          = _userId,
                RecipeName      = model.RecipeName,
                ListOfFoodIds   = model.ListOfFoodIds,
                CreatedUtc      = DateTimeOffset.Now,
                HowManyPortions = model.HowManyPortionsDoesRecipeMake
            };

            using (var ctx = new ApplicationDbContext())
            {
                foreach (int i in entity.ListOfFoodIds)
                {
                    entity.ListOfFoods.Add(ctx.FoodItems.Find(i));
                }
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() > 0);
            }
        }
예제 #19
0
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity = new Recipe()
            {
                OwnerId    = _userId,
                RecipeName = model.RecipeName,
                //ListOfIngredients = model.Ingredients.Add(),
                BookId      = model.BookId,
                CuisineType = model.CuisineType,
                RecipeType  = model.RecipeType,
                PageNumber  = model.PageNumber
            };

            using (var ctx = new ApplicationDbContext())
            {
                var oneIng = ctx.Ingredients.Single(x => x.IngredientId == model.IngredientId);
                entity.ListOfIngredients.Add(oneIng);
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() > 0);
            }
            //entity.Ingredient.Add(model.ingredient)
        }
예제 #20
0
        public bool CreateRecipe(RecipeCreate model)
        {
            var nameValidatorResult = RecipeNameValidator(model.RecipeName);

            if (nameValidatorResult)
            {
                return(false);
            }
            else
            {
                var entity = new Recipe()
                {
                    UserId     = _userId,
                    RecipeName = model.RecipeName,
                };
                using (var ctx = new ApplicationDbContext())
                {
                    ctx.Recipes.Add(entity);
                    return(ctx.SaveChanges() == 1);
                }
            }
        }
예제 #21
0
        public bool CreateRecipe(RecipeCreate model)
        {
            var entity =
                new Recipe()
            {
                UserID      = _userId,
                RecipeTitle = model.RecipeTitle,
                Link        = model.Link,
                Calories    = model.Calories,
                TypeName    = model.TypeName,
                Dietary     = model.Dietary,
                Meal        = model.Meal

                              //FavoriteRecipes = model.FavoriteRecipes
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #22
0
        public bool CreateRecipe(RecipeCreate recipe)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    new Recipe()
                {
                    RecipeOwner       = _userId,
                    RecipeName        = recipe.RecipeName,
                    RecipeShared      = recipe.RecipeShared,
                    RecipeDescription = recipe.RecipeDescription,
                    RecipeID          = recipe.RecipeID
                };
                ctx.Recipes.Add(entity);

                string[] lines      = recipe.RecipeSteps.Split('\n');
                int      stepNumber = 1;
                foreach (var step in lines)
                {
                    entity.RecipeSteps.Add(new RecipeStep()
                    {
                        RecipeID = entity.RecipeID, StepNumber = stepNumber, StepInstruction = step
                    });
                    stepNumber++;
                }
                ;

                var ingredients = recipe.SelectedIngredientIDs;
                var service     = CreateIngredientService();
                foreach (var ingredient in ingredients)
                {
                    var selected = service.GetRecipeIngredientById(ingredient);
                    entity.RecipeIngredients.Add(selected);
                }

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #23
0
        public bool CreateRecipe(RecipeCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = new Recipe
                {
                    UserId      = _userId,
                    Name        = model.Name,
                    Ingredients = model.Ingredients,
                    Steps       = model.Steps,
                    Directions  = model.Directions,
                    IsSaved     = true
                };

                if (model.PlanId != null)
                {
                    entity.Plan = ctx.Plans.Single(p => p.PlanId == model.PlanId);
                }

                ctx.Recipes.Add(entity);
                return(ctx.SaveChanges() >= 1);
            }
        }