public async Task Submit() { try { IsBusy = true; RecipeModel recipeModel = new RecipeModel { Name = RecipeName, Ingredients = RecipeIngredients.ToList(), Instruction = RecipeInstructions, NameOfImage = ImagePath, IsPublic = IsPublic, }; if (recipeModel.NameOfImage == ImageConstants.LoadDefaultImage) { recipeModel.NameOfImage = ""; } if (_addOrEdit == AddOrEdit.Add) { await _recipesEndPointAPI.InsertRecipe(recipeModel); DependencyService.Get <IMessage>().LongAlert("Dodano pomyślnie!"); MessagingService.Current.SendMessage(EventMessages.AddOrEditViewModelPage); } else if (_addOrEdit == AddOrEdit.Edit) { recipeModel.RecipeId = _recipeId; var result = await _recipesEndPointAPI.EditRecipe(recipeModel); if (result) { if (recipeModel.NameOfImage == "") { recipeModel.NameOfImage = ImageConstants.LoadDefaultImage; } OnPropertyChanged(nameof(ImagePath)); OnPropertyChanged(nameof(CanDeleteImage)); DependencyService.Get <IMessage>().LongAlert("Zaktualizowano pomyślnie!"); MessagingService.Current.SendMessage(EventMessages.AddOrEditViewModelPage); } } } catch (Exception ex) { // _logger.Error("Got exception", ex); await Application.Current.MainPage.DisplayAlert("Błąd", ex.Message, "Ok"); } finally { IsBusy = false; } }
public async Task AddRecipeSubmit() { try { RecipeModel recipeModel = new RecipeModel { Name = RecipeName, Ingredients = RecipeIngredients.ToList(), Instruction = RecipeInstructions, NameOfImage = ImagePath, IsPublic = IsPublic, }; if (recipeModel.NameOfImage == ImageConstants.DefaultImage) { recipeModel.NameOfImage = ""; } if (_addOrEdit == AddOrEdit.Add) { await _recipesEndPointAPI.InsertRecipe(recipeModel); reloadNeeded = true; await _eventAggregator.PublishOnUIThreadAsync(new LogOnEvent(reloadNeeded), new CancellationToken()); } else if (_addOrEdit == AddOrEdit.Edit) { recipeModel.RecipeId = _recipeId; var result = await _recipesEndPointAPI.EditRecipe(recipeModel); if (result) { if (recipeModel.NameOfImage == "") { recipeModel.NameOfImage = ImageConstants.DefaultImage; } NotifyOfPropertyChange(() => ImagePath); NotifyOfPropertyChange(() => CanDeleteFileModel); reloadNeeded = true; MessageBox.Show("Zaktualizowano pomyślnie!", "Zaktualizowano", MessageBoxButton.OK, MessageBoxImage.Information); await _eventAggregator.PublishOnUIThreadAsync(new LogOnEvent(reloadNeeded), new CancellationToken()); } } } catch (Exception ex) { _logger.Error("Got exception", ex); MessageBox.Show(ex.Message, ex.GetType().ToString()); } }