async void SaveClicked(object sender, EventArgs e) { try { //city.Province = null; city.ProvinceID = getProvinceID(); if (city.ProvinceID > 0) { CityRepository r = new CityRepository(); if (city.ID == 0) { await r.AddCity(city); } else { await r.UpdateCity(city); } thisApp.needCityRefresh = true; await Navigation.PopAsync(); } else { await DisplayAlert("Province Not Selected:", "You must set the province for the city.", "Ok"); } } catch (AggregateException ex) { string errMsg = ""; foreach (var exception in ex.InnerExceptions) { errMsg += Environment.NewLine + exception.Message; } await DisplayAlert("One or more exceptions has occurred:", errMsg, "Ok"); } catch (ApiException apiEx) { var sb = new StringBuilder(); sb.AppendLine("Errors:"); foreach (var error in apiEx.Errors) { sb.AppendLine("-" + error); } thisApp.needCityRefresh = true; await DisplayAlert("Problem Saving the City:", sb.ToString(), "Ok"); } catch (Exception ex) { if (ex.GetBaseException().Message.Contains("connection with the server")) { await DisplayAlert("Error", "No connection with the server.", "Ok"); } else { await DisplayAlert("Error", "Could not complete operation.", "Ok"); } } }
public long AddCity(CityObject cityAccount) { try { return(_cityRepository.AddCity(cityAccount)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public async Task AddNewCityToListOfCitiesIsSuccessful() { // Arrange var cityRepository = new CityRepository(_dapperConfig.ConnectionString); var expectedCity = new City { Name = $"Test City { Guid.NewGuid() }", Description = "City added via testing" }; // act await cityRepository.AddCity(expectedCity); var listOfCities = (await cityRepository.GetListOfCities()).ToList(); var actualCity = listOfCities.First(city => city.Name == expectedCity.Name); // Assert Assert.Equal(expectedCity.Name, actualCity.Name); Assert.Equal(expectedCity.Description, actualCity.Description); }
private async Task <object> City(ResolveFieldContext <object> context) { var city = context.GetArgument <City>("city"); City result; if (city.CityID == Guid.Empty) { result = await _cityRepository.AddCity(city); } else { result = await _cityRepository.UpdateCity(city); } if (result == null) { context.Errors.Add(new ExecutionError($"Could not find city with specified cityID '{city.CityID}'. Nothing updated / added.")); } return(city); }
public ActionResult Create(CityVM model) { try { string cityId = string.Empty; model.CreatedBy = LogInManager.LoggedInUserId; cityId = cityRepository.AddCity(model); if (!string.IsNullOrWhiteSpace(cityId)) { return(Json(new { IsSuccess = true, data = new { CityId = cityId } }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, errorMessage = "City details not saved successfully." }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { Utility.Utility.LogError(e, "Create"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }