public int UpdateRecipe(RecipeDto recipeDto) { int recipeId; using (var context = new IngredientChecklistEntities()) { var recipe = context.Recipes.FirstOrDefault(r => r.Id == recipeDto.Id); recipeId = recipe.Id; recipe.Name = recipeDto.Name; var oldIngredients = (from item in recipe.Ingredients select item); context.Ingredients.RemoveRange(oldIngredients); context.SaveChanges(); foreach (var ing in recipeDto.Ingredients) { Ingredient ingredient = new Ingredient { Name = ing.Name, }; recipe.Ingredients.Add(ingredient); } context.SaveChanges(); } return(recipeId); }
public ActionResult Edit(int id) { using (IngredientChecklistEntities db = new IngredientChecklistEntities()) { var recipe = db.Recipes.SingleOrDefault(x => x.Id == id); return(View(recipe)); } }
public PartialViewResult GetItem(int id) { using (IngredientChecklistEntities db = new IngredientChecklistEntities()) { var charts = db.Ingredients.ToList(); var model = charts.Where(x => x.RecipeId == id).ToList(); return(PartialView("_GetItem", model)); } }
public User GetUserById(int id) { User user; using (var context = new IngredientChecklistEntities()) { user = context.Users.FirstOrDefault(u => u.Id == id); } return(user); }
public ActionResult Edit(Recipe recipes) { using (IngredientChecklistEntities db = new IngredientChecklistEntities()) { recipes.UserId = Convert.ToInt32(Session["UserID"]); db.Entry(recipes).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index", "Home", null)); }
public User GetUserByUserName(string userName) { User user; using (var context = new IngredientChecklistEntities()) { user = context.Users.FirstOrDefault(u => u.UserName == userName); } return(user); }
public User ValidateUser(string userName, string password) { User user; using (var context = new IngredientChecklistEntities()) { user = context.Users.FirstOrDefault(u => u.UserName == userName && u.Password == password); } return(user); }
public bool UpdateRecipeIngredient(IngredientDto ingredientDto) { using (var context = new IngredientChecklistEntities()) { var ingredient = context.Ingredients.FirstOrDefault(i => i.Id == ingredientDto.Id); ingredient.IsChecked = ingredientDto.IsChecked; context.SaveChanges(); } return(true); }
public RecipeDto GetRecipeById(int id) { RecipeDto recipeDto = new RecipeDto(); using (var context = new IngredientChecklistEntities()) { var recipe = context.Recipes.FirstOrDefault(r => r.Id == id); recipeDto = Mapper.Map <RecipeDto>(recipe); } return(recipeDto); }
public ActionResult Create(Recipe recipes) { using (IngredientChecklistEntities db = new IngredientChecklistEntities()) { Recipe recipe1 = new Recipe(); recipe1.Name = recipes.Name; recipe1.UserId = Convert.ToInt32(Session["UserID"]); db.Recipes.Add(recipe1); db.SaveChanges(); } return(RedirectToAction("Index", "Home", null)); }
public ActionResult DeleteIngredient(int id) { using (IngredientChecklistEntities entities = new IngredientChecklistEntities()) { Ingredient updatedCustomer = (from c in entities.Ingredients where c.Id == id select c).FirstOrDefault(); entities.Ingredients.Remove(updatedCustomer); entities.SaveChanges(); } return(Json(new { success = true, responseText = "Delete sucessfully!" }, JsonRequestBehavior.AllowGet)); }
public JsonResult InsertIngredient(Ingredient ingredient) { using (IngredientChecklistEntities entities = new IngredientChecklistEntities()) { int RecipeID = Convert.ToInt32(Session["RecipeID"]); ingredient.RecipeId = RecipeID; ingredient.IsChecked = false; entities.Ingredients.Add(ingredient); entities.SaveChanges(); } return(Json(ingredient)); }
public ActionResult Recipe() { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Login", null)); } using (IngredientChecklistEntities db = new IngredientChecklistEntities()) { int userID = Convert.ToInt32(Session["UserID"]); var recipe = db.Recipes.Where(x => x.UserId == userID).ToList(); return(View(recipe)); } }
public bool ResetRecipeIngredientSelection(int recipeId) { using (var context = new IngredientChecklistEntities()) { var ingredients = context.Ingredients.Where(i => i.RecipeId == recipeId); foreach (var ingredient in ingredients) { ingredient.IsChecked = false; } context.SaveChanges(); } return(true); }
// GET: Ingredients public ActionResult Index() { if (Session["UserID"] == null) { return(RedirectToAction("Index", "Login", null)); } using (IngredientChecklistEntities db = new IngredientChecklistEntities()) { int RecipeID = Convert.ToInt32(Session["RecipeID"]); List <Ingredient> ingredients = db.Ingredients.Where(x => x.RecipeId == RecipeID).ToList(); ingredients.Insert(0, new Ingredient()); return(View(ingredients)); } }
public ActionResult UpdateIngredient(Ingredient ingredient) { if (ingredient.Id != 0) { using (IngredientChecklistEntities entities = new IngredientChecklistEntities()) { Ingredient updatedIngredient = (from c in entities.Ingredients where c.Id == ingredient.Id select c).FirstOrDefault(); updatedIngredient.Name = ingredient.Name; entities.SaveChanges(); } } return(Json(new { success = true, responseText = "Updated sucessfully!" }, JsonRequestBehavior.AllowGet)); }
public List <RecipeDto> GetListRecipeByUser(int userId) { List <RecipeDto> listRecipe = new List <RecipeDto>(); using (var context = new IngredientChecklistEntities()) { var recipes = context.Recipes.Where(r => r.UserId == userId); foreach (var recipe in recipes) { var recipeDto = Mapper.Map <RecipeDto>(recipe); listRecipe.Add(recipeDto); } } return(listRecipe); }
public ActionResult Index(User user) { using (IngredientChecklistEntities db = new IngredientChecklistEntities()) { var users = db.Users.SingleOrDefault(x => x.UserName == user.UserName && x.Password == user.Password); if (users != null) { Session["UserID"] = users.Id.ToString(); Session["FullName"] = users.FullName.ToString(); return(RedirectToAction("Index", "Home", null)); } else { return(RedirectToAction("Index", "Login", null)); } } }
// GET: Cooking public ActionResult Index() { if (Session["UserID"] == null) { return(RedirectToAction("Index", "Login", null)); } using (IngredientChecklistEntities db = new IngredientChecklistEntities()) { int userID = Convert.ToInt32(Session["UserID"]); var recipes = db.Recipes.Where(x => x.UserId == userID).ToList(); List <SelectListItem> RecipesList = recipes.Select(r => new SelectListItem { Text = r.Name, Value = r.Id.ToString() }).ToList(); ViewBag.Recipes = RecipesList; var ingredients = new List <Ingredient>(); return(View(ingredients)); } }
public int AddRecipe(RecipeDto recipeDto) { Recipe recipe = new Recipe { Name = recipeDto.Name, UserId = recipeDto.UserId, }; foreach (var ing in recipeDto.Ingredients) { Ingredient ingredient = new Ingredient { Name = ing.Name, }; recipe.Ingredients.Add(ingredient); } using (var context = new IngredientChecklistEntities()) { context.Recipes.Add(recipe); context.SaveChanges(); } return(recipe.Id); }