public bool CreateIngredient(IngredientCreate model) { var ingredient = new Ingredient() { OwnerId = _userId, RecipeId = model.RecipeId, IngredientName = model.IngredientName, Directions = model.Directions, Quantity = model.Quantity, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { var addedIngredient = ctx.Ingredients.Add(ingredient); ctx.SaveChanges(); RecipeListService Rls = new RecipeListService(_userId); RecipeListCreate Rlc = new RecipeListCreate { RecipeID = model.RecipeId, IngredientID = addedIngredient.IngredientId }; return(Rls.CreateRecipeList(Rlc)); } }
public bool CreateRecipeList(RecipeListCreate model) { var entity = new RecipeList() { OwnerId = _userId, Recipeid = model.RecipeID, IngredientId = model.IngredientID, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.RecipeList.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(RecipeListCreate model) { if (!ModelState.IsValid) { return(View(model)); } var userID = Guid.Parse(User.Identity.GetUserId()); var service = new RecipeListService(userID); //if (service.CreateRecipeList(model)) //{ // return RedirectToAction("Index"); //} return(View(model)); }