protected override async void OnSaveExecute() { try { await _dataService.SaveAsync(); } catch (DbUpdateConcurrencyException ex) { var dbValue = ex.Entries.Single().GetDatabaseValues(); if (dbValue == null) { MessageDialogService.ShowInfoDialog("The entity has been deleted by another user"); RaiseDetailDeletedEvent(Id); return; } var result = MessageDialogService.ShowOkCancelDialog("The entity has been changed in the meantime by someone else." + "Click OK to save changes anyway, click Cancel to reload the entity from the database.", "Question"); if (result == MessageDialogResult.OK) { var entry = ex.Entries.Single(); entry.OriginalValues.SetValues(entry.GetDatabaseValues()); await _dataService.SaveAsync(); } else { await ex.Entries.Single().ReloadAsync(); await LoadAsync(Friend.Id); } } HasChanges = _dataService.HasChanges(); Id = Friend.Id; RaiseDetailSavedEvent(Friend.Id, $"{Friend.FirstName} {Friend.LastName}"); }
private async void OnRemoveExecute() { var isReferenced = await _programmingLanguageRepository.IsReferencedByFriendAsync(SelectedProgrammingLanguage.Id); if (isReferenced) { MessageDialogService.ShowInfoDialog($"language {SelectedProgrammingLanguage.Name} is referenced by Friends!"); return; } SelectedProgrammingLanguage.PropertyChanged -= Language_PropertyChanged; _programmingLanguageRepository.Remove(SelectedProgrammingLanguage.Model); ProgrammingLanguages.Remove(SelectedProgrammingLanguage); SelectedProgrammingLanguage = null; HasChanges = _programmingLanguageRepository.HasChanges(); ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged(); }
private async void OnRemoveCommand() { var isReferenced = await _repository.IsReferencedByFriendAsync(SelectedProgrammingLanguage.Id); if (isReferenced) { MessageDialogService.ShowInfoDialog($"Cannot delete referenced language: {SelectedProgrammingLanguage.Name}"); return; } SelectedProgrammingLanguage.PropertyChanged -= Wrapper_PropertyChanged; //odłącz eventy od usuwanego elementu _repository.Remove(SelectedProgrammingLanguage.Model); //wywal z repo ProgrammingLanguages.Remove(SelectedProgrammingLanguage); //wywal z listy SelectedProgrammingLanguage = null; //wybrany teraz jest null HasChanges = _repository.HasChanges(); // w repo zaszły zmiany więc ustawiamy flagę w modelu ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged(); // odpalamy event i sprawdzamy czy Save może być aktywny }
protected async override void OnSaveExecute() { try { await _programmingLanguageRepository.SaveAsync(); HasChanges = _programmingLanguageRepository.HasChanges(); RaiseCollectionSavedEvent(); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } MessageDialogService.ShowInfoDialog($"Error while saving the entities. Details {ex.Message}"); await LoadAsync(Id); } }
protected override async void OnDeleteExecute() { if (await _friendRepository.HasMeetingAsync(Friend.Id)) { MessageDialogService.ShowInfoDialog($"{Friend.LastName} {Friend.FirstName} can't be delete, as this friend is part of at least one meeting"); return; } var result = MessageDialogService.ShowOkCancelDialog($"Do you really want to delete the friend {Friend.LastName} {Friend.FirstName}?", "Question"); if (result == MessageDialogResult.OK) { _friendRepository.Remove(Friend.Model); await _friendRepository.SaveAsync(); RaiseDetailDeletedEvent(Friend.Id); } }
protected override async void OnDeleteExecute() { if (await _dataService.HasMeetingsAsync(Friend.Id)) { MessageDialogService.ShowInfoDialog($"{Friend.FirstName} {Friend.LastName} cannot be deleted!"); return; } var result = MessageDialogService.ShowOkCancelDialog($"Do you really want to delete friend {Friend.FirstName} {Friend.LastName}", "Question"); if (result == MessageDialogResult.OK) { _dataService.Remove(Friend.Model); await _dataService.SaveAsync(); RaiseDetailDeletedEvent(Friend.Id); } }
protected async override void OnSaveExecute() { try { await _programmingLanguageRepository.SaveAsync(); HasChanges = _programmingLanguageRepository.HasChanges(); RaiseCollectionSaveEvent(); } catch (Exception e) { while (e.InnerException != null) { e = e.InnerException; } MessageDialogService.ShowInfoDialog("Error while saving language: " + e.Message); await LoadAsync(Id); } }
protected override async void OnDeleteMeetingExecute() { var hasMeetings = await _friendRepository.HasMeetingsAsync(Friend.Id); if (hasMeetings) { MessageDialogService.ShowInfoDialog($"Friend '{Friend.FirstName} {Friend.LastName}' has a meetings! "); } var result = MessageDialogService.ShowOkCancelDialog($"You really want to delete friend '{Friend.FirstName} {Friend.LastName}'?", "Question"); if (result == MessageDialogResult.OK) { _friendRepository.Remove(Friend.Model); await _friendRepository.SaveAsync(); RaiseDetailDeletedEvent(Friend.Id); } }
protected override async void OnDeleteExecute() { if (await _repository.HasMeetingsAsync(Friend.Id)) { MessageDialogService.ShowInfoDialog($"Cannot delete {Friend.FirstName} {Friend.LastName} because being in meeting"); return; } var result = await MessageDialogService.ShowOkCancelDialog("Delete?", "Confirm"); if (result == MessageDialogResult.Cancel) { return; } _repository.Remove(Friend.Model); await _repository.SaveAsync(); RaiseDetailDeletedEvent(Friend.Id); }
private async Task <WeatherModel> GetWeather() { IRepository repo = new Repository(); //var testWeatherModel = CreateTestWeatherModel(); WeatherModel localWeatherResult = new WeatherModel(); try { localWeatherResult = repo.GetWeatherDataByAutoIP(key, Days.One); localWeatherResult = FixWeatherIconLink(localWeatherResult); localWeatherResult = ConvertWeatherKmphToMps(localWeatherResult); //var cityWeatherResult = repo.GetWeatherData(key, GetBy.CityName, "goeteborg", Days.One); } catch (Exception) { await MessageDialogService.ShowInfoDialog($"The Weather data could not be loaded."); } return(localWeatherResult); }
/// <summary> /// Save Customer Entity repository and fire EventAfterDetailSaved /// </summary> /// <exception cref="DbUpdateConcurrencyException">Customer data can not be saved, as data was changed in the meanwhile !</exception> protected override async void OnCommandSaveExecute() { try { await _repository.SaveAsync(); } catch (DbUpdateConcurrencyException) { MessageDialogService.ShowInfoDialog("Customer data can not be saved, as data was changed in the meanwhile !", "Save failed"); return; } HasChanges = false;// _repository.HasChanges(); //after saving the (new) Customer set ViewModel-Id to Customer-Id and fire event Id = Customer.Id; RaiseEventAfterDetailSaved(Id); //Update Tab-Header in the UI, as display name might depend on other properties OnPropertyChanged(nameof(TabDisplayName)); }
protected override async void OnDeleteExecute() { if (await _friendRepository.HasMeetingsAsync(Friend.Id)) { MessageDialogService.ShowInfoDialog($"{Friend.FirstName} " + $"{Friend.LastName} не может быть удален, т.к. участвует во встрече."); return; } var result = MessageDialogService.ShowOkCancelDialog( $"Действительно ли хотите удалить {Friend.FirstName} {Friend.LastName}?", "Question"); if (result == MessageDialogResult.OK) { _friendRepository.Remove(Friend.Model); await _friendRepository.SaveAsync(); RaiseDetailDeletedEvent(Friend.Id); } }
private async void GetWeather(DateTime dateFrom, DateTime dateTo) { IRepository repo = new Repository(); var dateNow = DateTime.Today; int fromForecastDays = -1; int toForecastDays = -1; if (dateFrom.Date <= dateNow.AddDays(7).Date&& dateFrom.Date >= dateNow.Date) { var timeSpan = dateFrom.Date - dateNow.Date; fromForecastDays = timeSpan.Days; } if (dateTo.Date <= dateNow.AddDays(7).Date&& dateTo.Date >= dateNow.Date) { var timeSpan = dateTo.Date - dateNow.Date; toForecastDays = timeSpan.Days; } var localWeatherResult = new WeatherModel(); try { localWeatherResult = repo.GetWeatherDataByAutoIP(key, Days.Seven); //var cityWeatherResult = repo.GetWeatherData(key, GetBy.CityName, "goeteborg", Days.One); } catch (Exception) { await MessageDialogService.ShowInfoDialog($"The Weather data could not be loaded."); return; } WeatherDisplayModel weatherDisplayModelFromDate; if (fromForecastDays >= 0 && fromForecastDays <= 7) { weatherDisplayModelFromDate = new WeatherDisplayModel() { Icon = "http:" + localWeatherResult.forecast.forecastday[fromForecastDays].day.condition.icon, Text = $"Date: {localWeatherResult.forecast.forecastday[fromForecastDays].date} " + $"Temp: Min {localWeatherResult.forecast.forecastday[fromForecastDays].day.mintemp_c}°C, " + $"Max {localWeatherResult.forecast.forecastday[fromForecastDays].day.maxtemp_c}°C" }; } else { weatherDisplayModelFromDate = new WeatherDisplayModel() { Icon = "", Text = $"No weather data can be found at this date..." }; } WeatherDisplayModel weatherDisplayModelToDate; if (toForecastDays >= 0 && toForecastDays <= 7) { weatherDisplayModelToDate = new WeatherDisplayModel() { Icon = "http:" + localWeatherResult.forecast.forecastday[toForecastDays].day.condition.icon, Text = $"Date: {localWeatherResult.forecast.forecastday[toForecastDays].date} " + $"Temp: Min {localWeatherResult.forecast.forecastday[toForecastDays].day.mintemp_c}°C, " + $"Max {localWeatherResult.forecast.forecastday[toForecastDays].day.maxtemp_c}°C" }; } else { weatherDisplayModelToDate = new WeatherDisplayModel() { Icon = "", Text = $"No weather data can be found at this date..." }; } WeatherModels.Clear(); WeatherModels.Add(weatherDisplayModelFromDate); WeatherModels.Add(weatherDisplayModelToDate); }