public ActionResult Delete(int id) { try { string countryId = string.Empty; countryId = countryRepository.DeleteCountry(id, LogInManager.LoggedInUserId); if (!string.IsNullOrWhiteSpace(countryId)) { return(Json(new { IsSuccess = true, data = new { CountryId = id } }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, errorMessage = "Country details not deleted successfully." }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { Utility.Utility.LogError(e, "Delete"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }
public async Task <List <Country> > Delete(int id) { var CountryRep = new CountryRepository(_db); var Result = await CountryRep.DeleteCountry(id); return(Result); }
// DELETE /api/country public async Task <IHttpActionResult> Delete(int id) { using (var db = new CountryRepository()) { await db.DeleteCountry(id); } return(Ok()); }
public bool DeleteCountry(long countryAccountId) { try { return(_countryRepository.DeleteCountry(countryAccountId)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(false); } }
public void CountryRepositoryFunction_DeleteCountry_FunctionalityTest() { GeographyContextTest context = new GeographyContextTest(true); CountryRepository countryRepo = new CountryRepository(context); Country country = countryRepo.GetCountry(4, 2); country.Name.Should().Be("Country60"); country.Population.Should().Be(20); country.Surface.Should().Be(30.0f); country.Continent.Name.Should().Be("Continent60"); countryRepo.DeleteCountry(1); context.SaveChanges(); countryRepo.IsInDatabase(1).Should().BeFalse(); countryRepo.IsInDatabase(2).Should().BeTrue(); }
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 }
/// <summary> /// This method is used for deleting Country based on country id /// </summary> /// <remarks> /// DateCreated: 24th Oct 2016 /// Edited By: Rakesh (25-Oct-2016) , Phani (3-Nov-2016) /// </remarks> /// <param name="id">contains Country Id</param> public void DeleteCountry(int id) { objCountryRepository.DeleteCountry(id); }
public IActionResult deleteCountry(int id) { return(Ok(countryRepository.DeleteCountry(id))); }
public async Task <ManipulateCountriesCommandResponse> Handle(ManipulateCountriesCommand request, CancellationToken cancellationToken) { ManipulateCountriesCommandResponse response = new ManipulateCountriesCommandResponse() { IsSuccessful = false }; List <Countries> countries = _CountryRepository.getCountry(request.CountryIds); if (request.CountryIds.Count != countries.Count) { throw new RulesException("Invalid", @"Country not found"); } using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { if (request.Operation == "Publish") { foreach (var country in countries) { country.IsPublished = true; _CountryRepository.Update <Countries>(country); } } else if (request.Operation == "UnPublish") { foreach (var country in countries) { country.IsPublished = false; _CountryRepository.Update <Countries>(country); } } else if (request.Operation == "Delete") { foreach (Countries country in countries) { List <Images> images = _CountryRepository.getImages(new List <int?> { country.PngimageId, country.SvgimageId }); foreach (var image in images) { _CountryRepository.DeleteImage(image); } foreach (var countryContents in country.CountryContents.ToList()) { country.CountryContents.Remove(countryContents); _CountryRepository.Delete <CountryContents>(countryContents); } _CountryRepository.DeleteCountry(country); } } else { throw new RulesException("Operation", @"The Operation " + request.Operation + " is not valied"); } await _cacheService.ClearCacheAsync("countriesCacheKey"); await _cacheService.ClearCacheAsync("imagesCacheKey"); await _CountryRepository.UnitOfWork .SaveEntitiesAsync(); response.IsSuccessful = true; scope.Complete(); } var countryDocs = _context.GetAll(Constants.CountriesDiscriminator); var imageDocs = _context.GetAll(Constants.ImagesDiscriminator); using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { if (request.Operation == "Publish" || request.Operation == "UnPublish") { foreach (var country in countries) { foreach (var doc in countryDocs.Where(d => d.GetPropertyValue <int>("CountryId") == country.CountryId)) { var eventsource = new CountryCommandEvent() { id = doc.GetPropertyValue <Guid>("id"), EventType = ServiceBusEventType.Update, Discriminator = Constants.CountriesDiscriminator, CountryId = country.CountryId, IsPublished = country.IsPublished, CreatedBy = doc.GetPropertyValue <string>("CreatedBy"), CreatedDate = doc.GetPropertyValue <DateTime>("CreatedDate"), UpdatedBy = doc.GetPropertyValue <string>("UpdatedBy"), UpdatedDate = doc.GetPropertyValue <DateTime>("UpdatedDate"), PNGImageId = doc.GetPropertyValue <int?>("PNGImageId"), SVGImageId = doc.GetPropertyValue <int?>("SVGImageId"), CountryContentId = doc.GetPropertyValue <int>("CountryContentId"), DisplayName = doc.GetPropertyValue <string>("DisplayName"), DisplayNameShort = doc.GetPropertyValue <string>("DisplayNameShort"), LanguageId = doc.GetPropertyValue <int?>("LanguageId"), PartitionKey = "" }; await _Eventcontext.PublishThroughEventBusAsync(eventsource); } } } else if (request.Operation == "Delete") { foreach (var item in countries) { var pngimgevent = new ImageCommandEvent() { id = imageDocs.FirstOrDefault(d => d.GetPropertyValue <int>("ImageId") == item.PngimageId).GetPropertyValue <Guid>("id"), EventType = ServiceBusEventType.Delete, Discriminator = Constants.ImagesDiscriminator, PartitionKey = imageDocs.FirstOrDefault(d => d.GetPropertyValue <int>("ImageId") == item.SvgimageId).GetPropertyValue <int>("CountryId").ToString() }; await _Eventcontext.PublishThroughEventBusAsync(pngimgevent); var svgimgevent = new ImageCommandEvent() { id = imageDocs.FirstOrDefault(d => d.GetPropertyValue <int>("ImageId") == item.SvgimageId).GetPropertyValue <Guid>("id"), EventType = ServiceBusEventType.Delete, Discriminator = Constants.ImagesDiscriminator, PartitionKey = imageDocs.FirstOrDefault(d => d.GetPropertyValue <int>("ImageId") == item.SvgimageId).GetPropertyValue <int>("CountryId").ToString() }; await _Eventcontext.PublishThroughEventBusAsync(svgimgevent); foreach (var doc in countryDocs.Where(d => d.GetPropertyValue <int>("CountryId") == item.CountryId)) { var countryevent = new CountryCommandEvent() { id = doc.GetPropertyValue <Guid>("id"), EventType = ServiceBusEventType.Delete, Discriminator = Constants.CountriesDiscriminator, PartitionKey = doc.GetPropertyValue <int>("LanguageId").ToString() }; await _Eventcontext.PublishThroughEventBusAsync(countryevent); } } } scope.Complete(); } return(response); }