public ActionResult Create([Bind(Include = "IngredientId,IngredientName,IngredientCost")] Ingredient ingredient) { string recipe = this.Session["RecipeName"] as string; //add recipeIngredient link for association table int recipeId = db.Recipes.Where(r => r.RecipeName.Equals(recipe)).Single().RecipeId; if (ModelState.IsValid) { bool ingredientExists = db.Ingredients.Where(i => i.IngredientName.Equals(ingredient.IngredientName)).Count() == 1 ? true : false; if (!ingredientExists) { db.Ingredients.Add(ingredient); db.SaveChanges(); } RecipeIngredient recipeIngredient = new RecipeIngredient() { RecipeId = db.Recipes.Single(r => r.RecipeName.Equals(recipe)).RecipeId, IngredientId = db.Ingredients.Single(r => r.IngredientName.Equals(ingredient.IngredientName)).IngredientId }; db.RecipeIngredients.Add(recipeIngredient); db.SaveChanges(); return(RedirectToAction("Details", "Recipes", new { id = recipeId })); } return(View(ingredient)); }
public ActionResult Create(Instruction instruction, int RecipeId) { instruction.RecipeId = RecipeId; _db.Instructions.Add(instruction); _db.SaveChanges(); return(RedirectToAction("Create", new { id = RecipeId })); }
public ActionResult Create([Bind(Include = "RecipeId,RecipeName")] Recipe recipe) { string user = this.Session["Username"] as string; if (ModelState.IsValid) { int userId = db.Users.Where(u => u.Username.Equals(user)).Single().UserId; bool recipeExists = db.Recipes.Where(r => r.RecipeName.Equals(recipe.RecipeName)).Count() == 1 ? true : false; if (!recipeExists) { //System.Diagnostics.Debug.WriteLine("Doesn't exist"); db.Recipes.Add(recipe); db.SaveChanges(); } UserRecipe userRecipe = new UserRecipe() { UserId = db.Users.Single(u => u.Username.Equals(user)).UserId, RecipeId = db.Recipes.Single(r => r.RecipeName.Equals(recipe.RecipeName)).RecipeId }; db.UserRecipes.Add(userRecipe); db.SaveChanges(); return(RedirectToAction("Index", "Users")); } return(View(recipe)); }
public ActionResult Create(Ingredient ingredient, int RecipeId) { _db.Ingredients.Add(ingredient); if (RecipeId != 0) { _db.IngredientRecipe.Add(new IngredientRecipe() { RecipeId = RecipeId, IngredientId = ingredient.IngredientId }); } _db.SaveChanges(); return(RedirectToAction("Create", new { id = RecipeId })); }
public ActionResult Create(Tag tag, int RecipeId) { _db.Tags.Add(tag); if (RecipeId != 0) { _db.RecipeTag.Add(new RecipeTag() { RecipeId = RecipeId, TagId = tag.TagId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(Recipe recipe, int TagId) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); recipe.User = currentUser; _db.Recipes.Add(recipe); if (TagId != 0) { _db.RecipeTag.Add(new RecipeTag() { TagId = TagId, RecipeId = recipe.RecipeId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(Recipe recipe) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); recipe.User = currentUser; _db.Recipes.Add(recipe); _db.SaveChanges(); return(RedirectToAction("Create", "Ingredients", new { id = recipe.RecipeId })); }
private void addProductBtn_Click(object sender, RoutedEventArgs e) { var productName = productNameTB.Text; var category = productTypeComboBox.Text; if (productTypeComboBox.SelectedItem != null) { var productType = new ProductType { Type = category }; var product = new Product { Name = productName, ProductType = productType }; _context.Products.Add(product); _context.SaveChanges(); productList.ItemsSource = _context.Products.ToList(); } else { MessageBox.Show("Prosze wybrac typ produkt."); } }
public IActionResult Registration([FromBody] User user) { if (db.Users.Any(u => u.Login.Equals(user.Login, System.StringComparison.CurrentCultureIgnoreCase))) { return(BadRequest("В системе существует пользователь с данным login")); } var security = Security.GenerateHashPasswordAndSalt(user.Password); db.Users.Add(new User() { Login = user.Login, Name = user.Name, Surname = user.Surname, Password = security.Item1, Salt = security.Item2, DateRegistration = System.DateTime.Now, Role = "user" }); db.SaveChanges(); return(StatusCode(201)); }
public ActionResult Create(Category category) { _db.Categories.Add(category); _db.SaveChanges(); return(RedirectToAction("Index")); }
public bool Save() { return(_recipeBookContext.SaveChanges() >= 0); }