public static void EnsureDatabaseSeeded(this RecipeContext context) { context.Database.Migrate(); var rp1 = new Recipe() { RecipeId = 1, Name = "Pasta", Description = "Pasta med kødsovs", Ingrediens = "Pasta", }; var rp2 = new Recipe() { RecipeId = 2, Name = "Pizza", Description = "Pizza med skinke og ost", Ingrediens = "Dej, ost, skinke", }; var rp3 = new Recipe() { RecipeId = 3, Name = "Rugbrød", Description = "Rugbrød med hamburgeryg", Ingrediens = "Rugbrød, smør, hamburgeryg", }; context.Add(rp1); context.Add(rp2); context.Add(rp3); context.SaveChanges(); }
public async Task <IActionResult> Post(Ingredient ingredient) { _context.Add(ingredient); await _context.SaveChangesAsync(); return(Ok(ingredient.Id)); }
public async Task <IActionResult> Create(PreparationStepViewModel PreparationStepViewModel) { if (ModelState.IsValid) { var recipeId = PreparationStepViewModel.NewStep.RecipeId; var stepListCurrentRecipe = _context.PreparationSteps .Where(p => p.RecipeId == recipeId) .ToList(); int highestRank; if (stepListCurrentRecipe.Count > 0) { highestRank = stepListCurrentRecipe .Max(p => p.Rank); } else { highestRank = 0; } PreparationStepViewModel.NewStep.Rank = ++highestRank; _context.Add(PreparationStepViewModel.NewStep); await _context.SaveChangesAsync(); return(RedirectToAction("List", new { recipeId = recipeId })); } return(View()); }
public async Task <IActionResult> Post(UserFridgeIngredient userIngredient) { _context.Add(userIngredient); await _context.SaveChangesAsync(); return(Ok(userIngredient.Id)); }
public async Task <IActionResult> Post(UserShoppingList userIngredient) { _context.Add(userIngredient); await _context.SaveChangesAsync(); return(Ok(userIngredient)); }
public IActionResult CreateChef(Chef userImput) { if (ModelState.IsValid) { // do somethng! maybe insert into db? then we will redirect dbContext.Add(userImput); // OR _context.Users.Add(NewPerson); dbContext.SaveChanges(); return(Redirect("/")); } else { // Oh no! We need to return a ViewResponse to preserve the ModelState, and the errors it now contains! return(View("NewChef", userImput)); } }
public async Task <IActionResult> Post(User user) { _context.Add(user); await _context.SaveChangesAsync(); return(Ok(user.Id)); }
public async Task <IActionResult> Post(UserRecipePost recipe) { _context.Users_RecipePost.Attach(recipe); _context.Add(recipe); await _context.SaveChangesAsync(); return(Ok(recipe.Id)); }
public int Insert(TDto dtoToInsert) { var entity = mapper.Map <TEntity>(dtoToInsert); recipeContext.Add(entity); recipeContext.SaveChanges(); return(entity.Id); }
public async Task <IActionResult> Create([Bind("Id,Name")] Recipe recipe) { if (ModelState.IsValid) { _context.Add(recipe); await _context.SaveChangesAsync(); return(RedirectToAction("List", "Ingredients", new { RecipeId = recipe.Id })); } return(View(recipe)); }
public async Task <IActionResult> Create([Bind("Id,Name,Time,Difficulty,NumberOfLikes,Ingredients,Process,TipsAndTricks")] Recipe recipe) { if (ModelState.IsValid) { _context.Add(recipe); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(recipe)); }
public async Task <IActionResult> Create([Bind("ID,Name,Products,Description,Time,Difficulty,Rating")] Recipe recipe) { if (ModelState.IsValid) { _context.Add(recipe); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(recipe)); }
public int InsertIngredientsListItem(int recipeId, IngredientsListItemForCreationDto ingredientListItemForCreationDto) { var ingredientsList = recipeContext.IngredientsLists.SingleOrDefault(il => il.RecipeId == recipeId); if (ingredientsList == null) { ingredientsList = new IngredientsList { RecipeId = recipeId }; recipeContext.Add(ingredientsList); } var ingredientsListItem = mapper.Map <IngredientsListItem>(ingredientListItemForCreationDto); ingredientsListItem.IngredientsList = ingredientsList; recipeContext.Add(ingredientsListItem); recipeContext.SaveChanges(); return(ingredientsListItem.Id); }
public async Task <IActionResult> Create([Bind("RecipeId,RecipeTitle,RecipeDescription,RecipeUploadDate,RecipeUploader,Ingredient1,Ingredient2,Ingredient3,Ingredient4,Ingredient5,Ingredient6,Ingredient7,Ingredient8,Ingredient9,Ingredient10,Ingredient11,Ingredient12,Ingredient13,Ingredient14,Ingredient15,Ingredient16,Ingredient17,Ingredient18,Ingredient19,Ingredient20,StepNumber1,Step1Description,StepNumber2,Step2Description,StepNumber3,Step3Description,StepNumber4,Step4Description,StepNumber5,Step5Description,StepNumber6,Step6Description,StepNumber7,Step7Description,StepNumber8,Step8Description,StepNumber9,Step9Description,StepNumber10,Step10Description,StepNumber11,Step11Description,StepNumber12,Step12Description,StepNumber13,Step13Description,StepNumber14,Step14Description,StepNumber15,Step15Description,StepNumber16,Step16Description,StepNumber17,Step17Description,StepNumber18,Step18Description,StepNumber19,Step19Description,StepNumber20,Step20Description")] Recipe recipe) { if (ModelState.IsValid) { _context.Add(recipe); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(recipe)); }
public IActionResult Create(Recipe recipe) { if (ModelState.IsValid) { _context.Add(recipe); var newStuff = _context.SaveChanges(); return(RedirectToAction("Favorites")); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(IngredientViewModel ingredientViewModel) { if (ModelState.IsValid) { var recipeId = ingredientViewModel.NewIngredient.RecipeId; _context.Add(ingredientViewModel.NewIngredient); await _context.SaveChangesAsync(); return(RedirectToAction("List", new { recipeId = recipeId })); } return(View()); }
public static void Main(string[] args) { using (var context = new RecipeContext()) { //The line below clears and resets the databse. context.Database.EnsureDeleted(); // Create the database if it does not exist context.Database.EnsureCreated(); // Add some video games. //Note that the Id field is autoincremented by default context.Add(new Recipe { Name = "Несквик с пивом", ImageName = "https://memepedia.ru/wp-content/uploads/2019/01/neskvik-s-pivom-mem.jpg", Type = "basic", Description = "Вкусно", Category = "drink", Likes = 10 }); context.Add(new Recipe { Name = "Вода", ImageName = "https://habrastorage.org/webt/dr/t2/0d/drt20dqcbde8mixwozur-22if2e.jpeg", Type = "basic", Description = "Очень вкусно", Category = "drink", Likes = 23 }); context.Add(new Recipe { Name = "Сок", ImageName = "https://www.koolinar.ru/all_image/recipes/140/140004/recipe_4ef47f29-51b7-466e-a7fb-b587a6aa4beb_large.jpg", Type = "basic", Description = "Не вкусно", Category = "drink", Likes = 19 }); context.Add(new Recipe { Name = "Курица", ImageName = "https://images11.domashnyochag.ru/upload/img_cache/7ba/7ba76875cfb0a438f97f603b7b6bcfad_cropped_740x537.jpg", Type = "basic", Description = "Сойдет", Category = "food", Likes = 5 }); context.Add(new Recipe { Name = "Пирог", ImageName = "https://e2.edimdoma.ru/data/recipes/0000/4786/4786-ed4_wide.jpg?1484599305", Type = "basic", Description = "Норм", Category = "food", Likes = 15 }); context.Add(new Recipe { Name = "Торт", ImageName = "https://static.1000.menu/img/content/36945/sochnyi-biskvitnyi-tort_1563566405_9_max.jpg", Type = "basic", Description = "Есть пробитие", Category = "food", Likes = 6 }); context.SaveChanges(); //var allRecipes = context.Recipes.ToList(); } // using (var context = new ApplicationDbContext(new DbContextOptions<ApplicationDbContext>())) // { // } CreateHostBuilder(args).Build().Run(); }
public async Task Add(Ingredient ingredient) { _context.Add(ingredient); await _context.SaveChangesAsync(); }
public IActionResult AddFavorites([Bind("Title,Href,Ingredients,Thumbnail")] Recipe r) { db.Add(r); db.SaveChanges(); return(RedirectToAction("Favorites")); }
public async Task Add(Recipe recipe) { _context.Add(recipe); await _context.SaveChangesAsync(); }
public void Add <T>(T entity) where T : class { _logger.LogInformation($"Adding an object of type {entity.GetType()} to the context."); _context.Add(entity); }