public IActionResult UpateRecipe(string userId, RecipesModel recipe) { RecipesDal db = new RecipesDal(); var updated = db.UpdateRecipeAsync(userId, recipe); return(Ok(updated.Result)); }
public List <RecipesModel> ReadRecipes() { try { OpenSqlConnection(); CreateCommandSc("SelectAllRecipes"); SqlDataReader sqlDataReader = GetExecuteReader(); List <RecipesModel> recipesList = new List <RecipesModel>(); while (sqlDataReader.Read()) { RecipesModel recipesModel = new RecipesModel(); recipesModel.RecipeId = Convert.ToInt32(sqlDataReader["RecipeId"]); recipesModel.Name = sqlDataReader["Name"].ToString(); recipesModel.Description = sqlDataReader["Description"].ToString(); recipesList.Add(recipesModel); } return(recipesList); } catch (SqlException ex) { throw new System.Exception(ex.Message); } finally { CloseSqlConnection(); } }
public EditRecipePage() { InitializeComponent(); _recipe = new RecipesModel(); BindingContext = _recipe; isNew = true; }
public IActionResult GetRecipe(string title) { RecipesDal db = new RecipesDal(); RecipesModel recipe = db.GetRecipeAsync(title).Result; return(Ok(recipe)); }
private async void NavigateNotification(NotificationsTypesEnum NotificationType, int NotificationID) { if (NotificationType == NotificationsTypesEnum.Chat) { //TODO } else if (NotificationType == NotificationsTypesEnum.Cooker) { OrdersModel model = new OrdersModel(); CookerViewModel cooker = await model.GetCooker(NotificationID); await PageTemplate.CurrentPage.NavigateAsync(new SingleCookerPage(cooker) { Title = cooker.Name }); } else if (NotificationType == NotificationsTypesEnum.Recipe) { RecipesModel model = new RecipesModel(); RecipeViewModel recipe = await model.GetRecipeFromID(NotificationID); await PageTemplate.CurrentPage.NavigateAsync(new SingleRecipePage(recipe) { Title = recipe.Title }); } else { await PageTemplate.CurrentPage.NavigateAsync(Utility.PageParser(PageNavigateEnums.NotificationsPage)); } }
public IActionResult AddRecipe(string userId, RecipesModel recipe) { RecipesDal db = new RecipesDal(); var user = db.AddRecipeAsync(userId, recipe); return(Ok(user)); }
public IActionResult AddUser(string userId, RecipesModel recipe) { RecipesDal db = new RecipesDal(); var deleted = db.RemoveRecipeAsync(userId, recipe); return(Ok(deleted.Result)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } UserModel user; if (User.IsInRole("admin") && Input.localUserId != null) { user = await _userManager.FindByIdAsync(Input.localUserId); } else { user = await _userManager.FindByNameAsync(User.Identity.Name); } if (user == null) { return(NotFound($"User not found'{user.Id}'.")); } if (Input.localRecipesId != 0 && Input.localUserId == user.Id) { recipesToChange = await _dbContext.Recipes.FindAsync(Input.localRecipesId); if (recipesToChange == null) { return(NotFound($"Recipe not found'{Input.localRecipesId}'.")); } recipesToChange.Name = Input.Name; recipesToChange.Text = Input.Text; recipesToChange.UserId = Input.localUserId; recipesToChange.PreviewImg = Input.PreviewImg; recipesToChange.PreviewText = Input.PreviewText; recipesToChange.Date = DateTime.Now.ToShortDateString(); recipesToChange.CategoryName = Input.Category; recipesToChange.Difficulty = Input.Difficulty; recipesToChange.CoockingTime = new string(Input.CoockingTime + "÷"); recipesToChange.Portions = Input.Portions; recipesToChange.Ingredients = Input.Ingredients; await _dbContext.SaveChangesAsync(); StatusMessage = "Recipe updated"; string url = Url.Page("/Account/Manage/MyRecipes", new { UserId = user.Id }); return(Redirect(url)); } var recipes = new RecipesModel { Name = Input.Name, Text = Input.Text, UserId = user.Id, PreviewImg = Input.PreviewImg, PreviewText = Input.PreviewText, Date = DateTime.Now.ToShortDateString(), CategoryName = Input.Category }; await _dbContext.Recipes.AddAsync(recipes); user.Posts += 1; await _dbContext.SaveChangesAsync(); StatusMessage = "Recipe added"; return(RedirectToPage("/Account/Manage/AddRecipes")); }
public EditRecipePage(RecipesModel recipe) { InitializeComponent(); _originalRecipe = recipe; mealPicker.SelectedIndex = mealPicker.Items.IndexOf(_originalRecipe.MealType); difficultyPicker.SelectedIndex = difficultyPicker.Items.IndexOf(_originalRecipe.Difficulty); BindingContext = recipe; }
public void InsertRecipe(RecipesModel recipesModel) { using (var context = new WebShopContext()) { context.RecipesModel.Add(recipesModel); context.SaveChanges(); } }
private void lwRecipes_Loaded(object sender, RoutedEventArgs e) { using (var db = new RecipesModel()) { var allRecipes = db.Recipes.ToList(); fillListView(allRecipes); } tbSearch.IsEnabled = true; lwRecipes.IsEnabled = true; }
public ActionResult <RecipesModel> Delete(int id) { RecipesModel.DeleteData(id); var getData = RecipesModel.Get(id); getData.Message = "Recipe successfully removed!"; return(getData); }
public async System.Threading.Tasks.Task AddRecipeAsync(string username, RecipesModel recipe) { var userId = GetUserId(username); recipe.UserId = userId; BsonDocument newRecipe = ExtractRecipe(recipe); var collection = _database.GetCollection <BsonDocument>("Recipes"); await collection.InsertOneAsync(newRecipe); }
public ActionResult <RecipesModel> Patch(int id, [FromBody] RecipesModel.Recipe recipe) { recipe.id = id; RecipesModel.UpdateData(recipe); var getData = RecipesModel.Get(id); getData.Message = "Recipe successfully updated!"; return(getData); }
private void cbCategories_Loaded(object sender, RoutedEventArgs e) { using (var db = new RecipesModel()) { var allCategories = db.Categories.ToList(); foreach (var category in allCategories) { cbCategories.Items.Add(category.DisplayName); } } cbCategories.Items.Add("Összes"); cbCategories.SelectedItem = "Összes"; cbCategories.IsEnabled = true; }
private void cbCategories_SelectionChanged(object sender, SelectionChangedEventArgs e) { using (var db = new RecipesModel()) { if (!((string)cbCategories.SelectedItem).Equals("Összes")) { var allRecipesInCategory = db.Recipes.Where(r => r.Categories.DisplayName == (string)cbCategories.SelectedItem).ToList(); fillListView(allRecipesInCategory); } else { lwRecipes.RaiseEvent(new RoutedEventArgs(ListView.LoadedEvent)); } } }
public async Task <IActionResult> AddRecipe(RecipeViewModel recipe) { var model = new RecipesModel { RecipeName = recipe.RecipeName, RecipeDescription = recipe.RecipeDescription, RecipeDifficulty = recipe.RecipeDifficulty, RecipeIngredients = recipe.RecipeIngredients, RecipePrepareTime = recipe.RecipePrepareTime, RecipeServings = recipe.RecipeServings, RecipeSteps = recipe.RecipeSteps, Image = await _fileManager.SaveImage(recipe.Image) }; db.InsertRecord("Recipes", model); return(View("ShowRecipe", model)); }
public void InsertRecipe(RecipesModel recipesModel) { string curFile = @"C:\temp\Recipes.json"; if (File.Exists(curFile)) { List <RecipesModel> listRecipes = ReadRecipes(); listRecipes.Add(recipesModel); var jsonString = JsonSerializer.Serialize(listRecipes); File.WriteAllText("C:\\temp\\Recipes.json", jsonString); } else { List <RecipesModel> listRecipes = new List <RecipesModel>(); listRecipes.Add(recipesModel); var jsonString = JsonSerializer.Serialize(listRecipes); File.WriteAllText("C:\\temp\\Recipes.json", jsonString); } }
public ActionResult <RecipesModel> Post([FromBody] RecipesModel.Recipe recipe) { var getData = new RecipesModel(); try { int newestId = RecipesModel.InsertData(recipe); getData = RecipesModel.Get(newestId); getData.Message = "Recipe successfully created!"; } catch { getData.Recipes = null; getData.Message = "Recipe creation failed!"; getData.RequiredMessage = "title, making_time, serves, ingredients, cost"; } return(getData); }
public void InsertRecipe(RecipesModel recipesModel) { try { OpenSqlConnection(); SqlCommand sqlCommand = CreateCommandSc("InsertRecipe"); sqlCommand.Parameters.Add(new SqlParameter("@Name", recipesModel.Name)); sqlCommand.Parameters.Add(new SqlParameter("@Description", recipesModel.Description)); ExecutedNonQuery(); } catch (SqlException ex) { throw new System.Exception(ex.Message); } finally { CloseSqlConnection(); } }
public void UpdateRecipe(RecipesModel recipesModel) { using (var context = new WebShopContext()) { var result = context.RecipesModel.SingleOrDefault(b => b.RecipeId == recipesModel.RecipeId); if (result != null) { try { context.RecipesModel.Attach(recipesModel); context.Entry(recipesModel).State = EntityState.Modified; context.SaveChanges(); } catch (Exception ex) { throw; } } } }
public async Task <IActionResult> Edit(RecipeViewModel rec) { var changeRecipe = new RecipesModel { RecipeId = rec.RecipeId, RecipeName = rec.RecipeName, RecipeDescription = rec.RecipeDescription, RecipeIngredients = rec.RecipeIngredients, RecipeDifficulty = rec.RecipeDifficulty, RecipePrepareTime = rec.RecipePrepareTime, RecipeServings = rec.RecipeServings, RecipeSteps = rec.RecipeSteps, }; if (rec.Image == null) { changeRecipe.Image = rec.CurrentImage; } else { if (!string.IsNullOrEmpty(rec.CurrentImage)) { _fileManager.RemoveImage(rec.CurrentImage); } changeRecipe.Image = await _fileManager.SaveImage(rec.Image); } if (changeRecipe.RecipeId != null) { db.UpsertRecord("Recipes", changeRecipe.RecipeName, changeRecipe); } else { RedirectToAction("RecipesList"); } return(View("ShowRecipe", changeRecipe)); }
private static BsonDocument ExtractRecipe(RecipesModel recipe) { var method = new List <BsonDocument>(); foreach (var s in recipe.Method) { var step = new BsonDocument { { "Step", s.StepNumber }, { "Description", s.Description } }; method.Add(step); } var ingredients = new List <BsonDocument>(); foreach (var i in recipe.Ingredients) { var ingredient = new BsonDocument { { "Description", i.Description }, { "Amount", i.Amount } }; } var newRecipe = new BsonDocument { { "Title", recipe.Title }, { "Method", new BsonArray(method.ToArray()) }, { "Ingredients", new BsonArray(ingredients.ToArray()) }, { "Notes", recipe.Notes }, { "UserId", recipe.UserId } }; return(newRecipe); }
private void tbSearch_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { using (var db = new RecipesModel()) { List <Recipes> searchedRecipes = null; if (tbSearch.Text.Length > 0 && !((string)cbCategories.SelectedItem).Equals("Összes")) { searchedRecipes = db.Recipes.Where(r => r.Categories.DisplayName.Equals((string)cbCategories.SelectedItem) && r.Title.Contains(tbSearch.Text)).ToList(); } else if (tbSearch.Text.Length > 0) { searchedRecipes = db.Recipes.Where(r => r.Title.Contains(tbSearch.Text)).ToList(); } else { searchedRecipes = db.Recipes.ToList(); } fillListView(searchedRecipes); } } }
public RecipeDetailPage(RecipesModel recipe) { InitializeComponent(); _recipe = recipe; BindingContext = recipe; }
public void Update(RecipesModel recipesModel) { recipesData.UpdateRecipe(recipesModel); }
public void Insert(RecipesModel recipesModel) { recipesData.InsertRecipe(recipesModel); }
public void UpdateRecipe(RecipesModel recipesModel) { throw new NotImplementedException(); }
public Categories(RecipesModel recipesModel) { Db = recipesModel; RefreshList(); }
public Steps(RecipesModel recipesModel) { Db = recipesModel; }