Пример #1
0
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Recipes
                    .Single(e => e.RecipeId == model.RecipeId);

                entity.RecipeName      = model.RecipeName;
                entity.Description     = model.Description;
                entity.IngredientItems = model.IngredientItems;
                entity.Procedure       = model.Procedure;
                entity.HasGluten       = model.HasGluten;
                entity.HasNuts         = model.HasNuts;
                entity.HasEggs         = model.HasEggs;
                entity.HasSoy          = model.HasSoy;
                entity.IsVegan         = model.IsVegan;
                entity.IsVegetarian    = model.IsVegetarian;
                entity.IsPescatarian   = model.IsPescatarian;
                entity.IsKetoFriendly  = model.IsKetoFriendly;
                entity.Difficulty      = model.Difficulty;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #2
0
 private void RichTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
 {
     if (e.Changes.Count > 1 && e.UndoAction != UndoAction.Clear)
     {
         RecipeEdit.ScrollToEnd();
     }
 }
        public ActionResult UpdateRecipeWithIngredients(int id)
        {
            var iservice = new IngredientService();
            List <Ingredient> ingredients = iservice.GetIngredientList().ToList();

            var query = from i in ingredients
                        select new SelectListItem()
            {
                Value = i.IngredientId.ToString(),
                Text  = i.IngredientName
            };

            ViewBag.IngredientId = query;

            var service = CreateRecipeService();
            var detail  = service.GetRecipeById(id);
            var model   =
                new RecipeEdit
            {
                RecipeId    = detail.RecipeId,
                RecipeName  = detail.RecipeName,
                Ingredients = detail.Ingredients,
            };

            return(View(model));
        }
Пример #4
0
    private void OnRecipeUpdated(RecipeEdit obj)
    {
        RecipeListViewDto?existingRecipe = Recipies !.FirstOrDefault(x => x.ID == obj.ID);

        if (existingRecipe != null)
        {
            mapper.Map(obj, existingRecipe);
        }
    }
Пример #5
0
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Recipes
                    .Single(e => e.Id == model.Id);

                entity.Name        = model.Name;
                entity.Description = model.Description;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #6
0
        public ActionResult Edit(int id)
        {
            var service = CreateRecipeService();
            var detail  = service.GetRecipeById(id);
            var model   =
                new RecipeEdit
            {
                RecipeId   = detail.RecipeId,
                RecipeName = detail.RecipeName,
                //Directions = detail.Directions,
                //Ingredients = detail.Ingredients
            };

            return(View(model));
        }
Пример #7
0
        public bool UpdateRecipeWithIngredients(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var recipe = ctx
                             .Recipes
                             .Single(e => e.OwnerId == _userId && e.RecipeId == model.RecipeId);
                var ingredient = ctx
                                 .Ingredients
                                 .Single(e => e.IngredientId == model.IngredientId);
                recipe.ListOfIngredients.Add(ingredient);

                return(ctx.SaveChanges() == 1);
            }
        }
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Recipes
                    .Single(e => e.RecipeId == model.RecipeId && e.OwnerId == _userId);

                entity.RecipeName         = model.RecipeName;
                entity.RecipeIngredients  = model.RecipeIngredients;
                entity.RecipeInstructions = model.RecipeInstructions;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #9
0
        public IHttpActionResult Put(RecipeEdit recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateRecipeServices();

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

            return(Ok());
        }
Пример #10
0
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx
                             .Recipes
                             .Single(e => e.OwnerId == _userId && e.RecipeId == model.RecipeId);
                entity.RecipeName  = model.RecipeName;
                entity.RecipeType  = model.RecipeType;
                entity.PageNumber  = model.PageNumber;
                entity.CuisineType = model.CuisineType;


                return(ctx.SaveChanges() == 1);
            }
        }
Пример #11
0
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Recipes
                    .Single(e => e.RecipeId == model.RecipeId && e.UserId == _userId);

                entity.RecipeName      = model.RecipeName;
                entity.HowManyPortions = model.HowManyPortionsDoesItMake;
                entity.ListOfFoodIds   = model.ListOfFoodIds;

                return(ctx.SaveChanges() > 0);
            }
        }
        public IHttpActionResult Put([FromUri] int id, [FromBody] RecipeEdit updatedRecipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateRecipeService();

            if (!service.UpdateRecipe(updatedRecipe, id))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Пример #13
0
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Recipes
                    .Single(e => e.RecipeId == model.RecipeId && e.OwnerId == _userId);

                entity.RecipeName = model.RecipeName;
                //entity.Directions = model.Directions;
                //entity.Ingredients = model.Ingredients;
                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #14
0
        public ActionResult Edit(int id)
        {
            var svc    = CreateRecipeService();
            var detail = svc.GetRecipeById(id);
            var model  =
                new RecipeEdit
            {
                RecipeID          = detail.RecipeID,
                RecipeName        = detail.RecipeName,
                RecipeShared      = detail.RecipeShared,
                RecipeDescription = detail.RecipeDescription,
                RecipeSteps       = detail.RecipeSteps,
                Ingredient        = detail.Ingredients
            };

            return(View(model));
        }
Пример #15
0
        public bool UpdateRecipe(RecipeEdit model, int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Recipes
                    .Single(e => e.RecipeId == id && e.UserId == _userId.ToString());
                entity.RecipeName   = model.RecipeName;
                entity.RecipeAuthor = model.RecipeAuthor;
                entity.Ingredients  = model.Ingredients;
                entity.Instructions = model.Instructions;
                entity.Category     = model.Category;

                return(ctx.SaveChanges() == 1);
            }
        }
        public bool EditRecipe(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Recipes
                    .Single(e => e.RecipeId == model.RecipeId && e.OwnerId == _userId);
                entity.RecipeName    = model.RecipeName;
                entity.Ingredients   = model.Ingredients;
                entity.TypeOfCuisine = model.TypeOfCuisine;
                entity.TypeOfDish    = model.TypeOfDish;
                entity.Instructions  = model.Instructions;
                entity.SourceId      = model.SourceId;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #17
0
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                           .Recipes
                           .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Name = model.Name;
                entity.Description = model.Description;
                entity.DateModified = DateTimeOffset.UtcNow;
                if (model.Season.Fall) { entity.Season.Fall = true;} else { entity.Season.Fall = false; }
                if (model.Season.Spring) { entity.Season.Spring = true;} else { entity.Season.Spring = false; }
                if (model.Season.Summer) { entity.Season.Summer = true;} else { entity.Season.Summer = false; }
                if (model.Season.Winter) { entity.Season.Winter = true;} else { entity.Season.Winter = false; }

                return context.SaveChanges() != 0;
            }
        }
Пример #18
0
        //public RecipeIngredients GetIngredients(int id)
        //{
        //    using (var ctx = new ApplicationDbContext())
        //    {
        //        var entity =
        //            ctx
        //            .Recipes
        //            .Single(e => e.RecipeId == id);
        //        return
        //         new RecipeIngredients
        //         {
        //             Ingredients = entity.RecipeIngredients
        //         };
        //    }
        //}

        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Recipes
                    .Single(e => e.RecipeId == model.RecipeId);

                entity.RecipeId           = model.RecipeId;
                entity.RecipeName         = model.RecipeName;
                entity.RecipeIngredients  = model.RecipeIngredients;
                entity.Instructions       = model.Instructions;
                entity.Servings           = model.Servings;
                entity.CaloriesPerServing = model.CaloriesPerServing;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #19
0
        public ActionResult Edit(int id)
        {
            var service = CreateRecipeService();
            var detail  = service.GetRecipebyId(id);
            var model   =
                new RecipeEdit
            {
                ID          = detail.ID,
                Name        = detail.Name,
                Description = detail.Description,
                Actions     = new ActionList()
                {
                    LarderId   = detail.ID,
                    Directions = detail.Actions.Directions
                },
                Ingredients = new IngredientList()
                {
                    LarderId    = detail.ID,
                    Ingredients = detail.Ingredients.Ingredients
                },
                Season = new Data.Models.Season()
            };

            if (detail.Seasons.Contains("Spring"))
            {
                model.Season.Spring = true;
            }
            if (detail.Seasons.Contains("Summer"))
            {
                model.Season.Summer = true;
            }
            if (detail.Seasons.Contains("Winter"))
            {
                model.Season.Winter = true;
            }
            if (detail.Seasons.Contains("Fall"))
            {
                model.Season.Fall = true;
            }

            return(View(model));
        }
Пример #20
0
        public ActionResult Edit(int id)
        {
            var service = CreateRecipeService();
            var detail  = service.GetRecipeById(id);

            var userId = Guid.Parse(User.Identity.GetUserId());



            var model =
                new RecipeEdit
            {
                RecipeId    = detail.RecipeId,
                RecipeName  = detail.RecipeName,
                RecipeType  = detail.RecipeType,
                CuisineType = detail.CuisineType,
                PageNumber  = detail.PageNumber,
            };

            return(View(model));
        }
Пример #21
0
    /// <inheritdoc/>
    public void OnNavigatedTo(NavigationContext navigationContext)
    {
        if (Recipe != null)
        {
            return;
        }

        journal = navigationContext.NavigationService.Journal;
        var recipeID = navigationContext.Parameters[nameof(Recipe)] as Guid?;

        if (recipeID.HasValue)
        {
            Recipe = recipeService.GetMapped <RecipeEdit>(recipeID.Value);
        }
        else
        {
            Recipe           = new RecipeEdit();
            IsEditing        = true;
            IsRecipeCreation = true;
        }
    }
Пример #22
0
        public bool Edit(RecipeEdit recipe)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    new Recipe()
                {
                    RecipeOwner       = _userId,
                    RecipeName        = recipe.RecipeName,
                    RecipeShared      = recipe.RecipeShared,
                    RecipeDescription = recipe.RecipeDescription,
                    RecipeID          = recipe.RecipeID
                };

                ICollection <RecipeStep> steps = entity.RecipeSteps;
                foreach (var step in steps)
                {
                    if (step != null)
                    {
                        entity.RecipeSteps.Add(step);
                    }
                }
                ;

/*
 *              var ingredients = recipe.SelectedIngredientIDs;
 *              var service = CreateIngredientService();
 *              foreach (var ingredient in ingredients)
 *              {
 *                  var selected = service.GetRecipeIngredientById(ingredient);
 *                  ctx.RecipeIngredients.Add(new RecipeIngredient()
 *                  {
 *                      IngredientID = selected.IngredientID
 *                  });
 *              }*/

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #23
0
        public ActionResult UpdateRecipeWithIngredients(int id, RecipeEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            if (model.RecipeId != id)
            {
                ModelState.AddModelError("", "Id mismatch");
                return(View(model));
            }
            var service = CreateRecipeService();

            if (service.UpdateRecipeWithIngredients(model))
            {
                TempData["SaveResult"] = "Your recipe was updated!";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your recipe could not be updated.");
            return(View());
        }
Пример #24
0
 private void OnRecipeCreated(RecipeEdit obj) => UpdateRecipiesSource();