Exemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            try
            {
                string cityId = string.Empty;

                cityId = cityRepository.DeleteCity(id, LogInManager.LoggedInUserId);

                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 deleted successfully."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "Delete");
                return(Json(new { IsSuccess = false, errorMessage = e.Message }));
            }
        }
Exemplo n.º 2
0
 public bool DeleteCity(long cityAccountId)
 {
     try
     {
         return(_cityRepository.DeleteCity(cityAccountId));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(false);
     }
 }
Exemplo n.º 3
0
        async void DeleteClicked(object sender, EventArgs e)
        {
            var answer = await DisplayAlert("Confirm Delete", "Are you certain that you want to delete " + city.Summary + "?", "Yes", "No");

            if (answer == true)
            {
                try
                {
                    //city.Province = null;
                    CityRepository er = new CityRepository();
                    await er.DeleteCity(city);

                    thisApp.needCityRefresh = true;
                    await Navigation.PopAsync();
                }
                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);
                    }
                    await DisplayAlert("Problem Deleting 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");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void DeleteCity_ReturnsProperCount()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>()
                            .UseInMemoryDatabase(databaseName: $"CityDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var currentUser = new Mock <ICurrentUserService>();

            currentUser.SetupGet(c => c.UserId).Returns("testuser");
            var currentUserService = currentUser.Object;

            var fakeCityOne = new FakeCity {
            }.Generate();
            var fakeCityTwo = new FakeCity {
            }.Generate();
            var fakeCityThree = new FakeCity {
            }.Generate();

            //Act
            using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService()))
            {
                context.Cities.AddRange(fakeCityOne, fakeCityTwo, fakeCityThree);

                var service = new CityRepository(context, new SieveProcessor(sieveOptions));
                service.DeleteCity(fakeCityTwo);

                context.SaveChanges();

                //Assert
                var cityList = context.Cities.ToList();

                cityList.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                cityList.Should().ContainEquivalentOf(fakeCityOne);
                cityList.Should().ContainEquivalentOf(fakeCityThree);
                Assert.DoesNotContain(cityList, c => c == fakeCityTwo);

                context.Database.EnsureDeleted();
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            #region Add
            //using (CountryRepository countryRepository = new CountryRepository())
            //{
            //    Console.WriteLine("Сколько стран добавить?");
            //    int countCity = int.Parse(Console.ReadLine());
            //    for (int i = 0; i < countCity; i++)
            //    {
            //        Console.WriteLine("Введите названия стран?");
            //        string nameCountry = Console.ReadLine();
            //        Countries country = new Countries
            //        {
            //            Name = nameCountry
            //        };
            //        countryRepository.AddCountry(country);
            //    }
            //}
            //using (CityRepository streetRepository = new CityRepository())
            //{
            //    Console.WriteLine("Сколько городов добавить?");
            //    int countCity = int.Parse(Console.ReadLine());
            //    for (int i = 0; i < countCity; i++)
            //    {
            //        Console.WriteLine("Введите названия города?");
            //        string nameCity = Console.ReadLine();
            //        Console.WriteLine("Введите Id страны?");
            //        int idCountry = int.Parse(Console.ReadLine());
            //        var getCountryId = streetRepository.GetCountryById(idCountry);
            //        while (getCountryId == null)
            //        {
            //            Console.WriteLine("Такого Id нет, Введите заново!");
            //            Console.ReadLine();
            //            idCountry = int.Parse(Console.ReadLine());
            //        }
            //        City city = new City
            //        {
            //            Name = nameCity,
            //            CountryId = idCountry
            //        };
            //        streetRepository.AddCity(city);
            //    }
            //}
            //using (StreetRepository streetRepository = new StreetRepository())
            //{
            //    Console.WriteLine("Сколько улиц добавить?");
            //    int countStreet = int.Parse(Console.ReadLine());
            //    for (int i=0; i<countStreet; i++)
            //    {
            //        Console.WriteLine("Введите названия улиц?");
            //        string nameStreet = Console.ReadLine();
            //        Console.WriteLine("Введите Id города?");
            //        int idCity = int.Parse(Console.ReadLine());
            //        var getCityId = streetRepository.GetCityById(idCity);
            //        while (getCityId == null)
            //        {
            //            Console.WriteLine("Такого Id нет, Введите заново!");
            //            Console.ReadLine();
            //            idCity = int.Parse(Console.ReadLine());
            //        }
            //        Street street = new Street
            //        {
            //            Name =  nameStreet,
            //            CityId = idCity
            //        };
            //        streetRepository.AddStreet(street);
            //    }
            //}
            #endregion

            #region Change
            //using (CountryRepository changeCountryRepository = new CountryRepository())
            //{
            //    Console.WriteLine("Введите Id страны которую хотите изменить?");
            //    int idCountry = int.Parse(Console.ReadLine());
            //    var getId = changeCountryRepository.GetCountryById(idCountry);
            //    while (getId == null)
            //    {
            //        Console.WriteLine("Такого Id нет, Введите заново!");
            //        Console.ReadLine();
            //        idCountry = int.Parse(Console.ReadLine());
            //    }
            //    Console.WriteLine("Введите название страны?");
            //    string nameCountry = Console.ReadLine();
            //    changeCountryRepository.ChangeCountry(nameCountry, idCountry);
            //}
            //using (CityRepository changeCityRepository = new CityRepository())
            //{
            //    Console.WriteLine("Введите Id города которую хотите изменить?");
            //        int idCity = int.Parse(Console.ReadLine());
            //        var getId = changeCityRepository.GetCityById(idCity);
            //        while (getId == null)
            //        {
            //            Console.WriteLine("Такого Id нет, Введите заново!");
            //            Console.ReadLine();
            //            idCity = int.Parse(Console.ReadLine());
            //        }

            //        Console.WriteLine("Введите Id страны?");
            //        int idCountry = int.Parse(Console.ReadLine());
            //        var getCountryId = changeCityRepository.GetCountryById(idCountry);
            //        while (getCountryId == null)
            //        {
            //            Console.WriteLine("Такого Id нет, Введите заново!");
            //            Console.ReadLine();
            //            idCountry = int.Parse(Console.ReadLine());
            //        }
            //        Console.WriteLine("Введите название города?");
            //        string nameCity = Console.ReadLine();
            //    changeCityRepository.ChangeCity(nameCity, idCity);
            //}
            //using (StreetRepository changeStreetRepository = new StreetRepository())
            //{
            //    Console.WriteLine("Введите Id улицы которую хотите изменить?");
            //    int idCity = int.Parse(Console.ReadLine());
            //    var getId = changeStreetRepository.GetCityById(idCity);
            //    while (getId == null)
            //    {
            //        Console.WriteLine("Такого Id нет, Введите заново!");
            //        Console.ReadLine();
            //        idCity = int.Parse(Console.ReadLine());
            //    }
            //    Console.WriteLine("Введите Id города?");
            //    int idStreet = int.Parse(Console.ReadLine());
            //    var getCityId = changeStreetRepository.GetCityById(idStreet);
            //    while (getCityId == null)
            //    {
            //        Console.WriteLine("Такого Id нет, Введите заново!");
            //        Console.ReadLine();
            //        idStreet = int.Parse(Console.ReadLine());
            //    }
            //    Console.WriteLine("Введите название улицы?");
            //    string nameStreet = Console.ReadLine();
            //    changeStreetRepository.ChangeStreet(nameStreet, idCity);
            //}
            #endregion

            #region Delete
            using (StreetRepository deleteStreetRepository = new StreetRepository())
            {
                Console.WriteLine("Введите Id улицы которую хотите удалить?");
                int idCity = int.Parse(Console.ReadLine());
                var getId  = deleteStreetRepository.GetCityById(idCity);
                while (getId == null)
                {
                    Console.WriteLine("Такого Id нет, Введите заново!");
                    Console.ReadLine();
                    idCity = int.Parse(Console.ReadLine());
                }
                deleteStreetRepository.DeleteStreet(idCity);
            }
            using (CityRepository deleteCityRepository = new CityRepository())
            {
                Console.WriteLine("Введите Id города которую хотите удалить?");
                int idCity = int.Parse(Console.ReadLine());
                var getId  = deleteCityRepository.GetCityById(idCity);
                while (getId == null)
                {
                    Console.WriteLine("Такого Id нет, Введите заново!");
                    Console.ReadLine();
                    idCity = int.Parse(Console.ReadLine());
                }
                deleteCityRepository.DeleteCity(idCity);
            }
            using (CountryRepository deleteCountryRepository = new CountryRepository())
            {
                Console.WriteLine("Введите Id страны которую хотите удалить?");
                int idCountry = int.Parse(Console.ReadLine());
                var getId     = deleteCountryRepository.GetCountryById(idCountry);
                while (getId == null)
                {
                    Console.WriteLine("Такого Id нет, Введите заново!");
                    Console.ReadLine();
                    idCountry = int.Parse(Console.ReadLine());
                }

                deleteCountryRepository.DeleteCountry(idCountry);
            }


            #endregion
        }