private async void RemoveFavorites_Clicked(object sender, EventArgs e) { SaveRecipe recipeModel = new SaveRecipe() { Id = viewModel.Id, Name = viewModel.Title, Ingredients = viewModel.Ingredients, Preparation = viewModel.Preparation, Favorite = false }; try { Connection.CreateTable <SaveRecipe>(); int rowsQuantity = Connection.Update(recipeModel); if (rowsQuantity > 0) { await DisplayAlert("Mensagem", "Receita Removida dos Favoritos", "OK"); await Navigation.PopAsync(); } else { await DisplayAlert("Erro", "Não foi possivel desfavoritar a receita", "OK"); } } catch (Exception err) { await DisplayAlert("Erro ", err.Message, "OK"); } }
private async void Create_Clicked(object sender, EventArgs e) { if (!RecipeIsValid(viewModel.Title)) { SaveRecipe recipeModel = new SaveRecipe() { Name = viewModel.Title, Ingredients = viewModel.Ingredients, Preparation = viewModel.Preparation, Favorite = false }; try { Connection.CreateTable <SaveRecipe>(); int rowsQuantity = Connection.Insert(recipeModel); if (rowsQuantity > 0) { await DisplayAlert("Sucesso!", "Receita cadastrada com sucesso", "OK"); await Navigation.PopAsync(); } } catch (Exception err) { await DisplayAlert("Falha!", "Receita não cadastrada! \n" + err.Message, "OK"); } } else { await DisplayAlert("Atenção", "Receita já cadastrada", "OK"); await Navigation.PopAsync(); } }
public async Task <IActionResult> Createreceipe([FromBody] SaveRecipe saveRecipe) { try { if (!ModelState.IsValid) { return(BadRequest()); } var receipe = mapper.Map <SaveRecipe, receipe>(saveRecipe); receipe.CreateDate = DateTime.Now; CookbookRepository.Createreceipe(receipe); await unitofWork.Complete(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> Updatereceipe(int id, [FromBody] SaveRecipe saveRecipe) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var recipe = await CookbookRepository.Getreceipes(id); if (recipe == null) { return(NotFound()); } mapper.Map <SaveRecipe, receipe>(saveRecipe, recipe); recipe.CreateDate = DateTime.Now; await unitofWork.Complete(); recipe = await CookbookRepository.Getreceipes(recipe.id); var result = mapper.Map <receipe, SaveRecipe>(recipe); return(Ok(result)); }
private async void Favorite_Clicked(object sender, EventArgs e) { if (!FavoriteIsValid(viewModel.Id)) { SaveRecipe recipeModel = new SaveRecipe() { Id = viewModel.Id, Name = viewModel.Title, Ingredients = viewModel.Ingredients, Preparation = viewModel.Preparation, Favorite = true }; try { Connection.CreateTable <SaveRecipe>(); int rowsQuantity = Connection.Update(recipeModel); if (rowsQuantity > 0) { await DisplayAlert("Mensagem", "Receita Favoritada", "OK"); await Navigation.PopAsync(); } else { await DisplayAlert("Erro", "Não foi possivel favoritar a receita", "OK"); } } catch (Exception err) { await DisplayAlert("Erro ", err.Message, "OK"); } } else { await DisplayAlert("Atenção", "Receita já Favoritada", "OK"); await Navigation.PopAsync(); } }
public DetailsRecipeViewModel(SaveRecipe recipeModel) { Id = recipeModel.Id; Title = recipeModel.Name; Ingredients = ""; Preparation = ""; if (recipeModel.Name != null) { var ingredients = recipeModel.Ingredients; var preparation = recipeModel.Preparation; if (ingredients != null) { Ingredients = string.Join("\n", ingredients); } if (preparation != null) { Preparation = string.Join("\n", preparation); } } OnPropertyChanged(nameof(Ingredients)); OnPropertyChanged(nameof(Preparation)); }
public FavoritePageDetails(SaveRecipe SelectedSaveRecipe) { InitializeComponent(); BindingContext = viewModel = new DetailsRecipeViewModel(SelectedSaveRecipe); }