public ActionResult ToggleState(string id) { var response = new JsonResultBody(); try { Country country = _repository.GetCountryById(id); response.Data = _repository.Delete(country); } catch (DbEntityValidationException ex) { response.Status = System.Net.HttpStatusCode.InternalServerError; foreach (DbEntityValidationResult result in ex.EntityValidationErrors) { response.Errors = (from ve in result.ValidationErrors select ve.ErrorMessage).ToList(); } } catch (Exception exApp) { response.Status = System.Net.HttpStatusCode.InternalServerError; response.Errors.Add(exApp.Message); } return(Json(response)); }
public void DeleteCountry() { Console.Clear(); Console.WriteLine("Введите страну которую хотите удалить - "); var cityName = CheckNullString(Console.ReadLine()); using (var repository = new CountryRepository()) { try { var id = repository.GetCountry(cityName); repository.Delete(id); } catch (Exception exception) { Console.WriteLine(exception.Message); Console.WriteLine("Нажмите Enter чтобы продолжить!"); Console.ReadKey(); return; } } Console.WriteLine("Данные удалены!"); Console.WriteLine("Нажмите Enter чтобы продолжить!"); Console.ReadKey(); }
public async Task <ActionResult> DeleteConfirmed(int id) { var country = await _repository.FindById(id); await _repository.Delete(country); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { Country country = repo.Get(c => c.Id == id); repo.Delete(country); repo.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Delete(int id) { using var repo = new CountryRepository(configuration); repo.Delete(id); return(Ok()); }
public ActionResult Delete(int id) { int ConId = id; // countryRepository.Delete(ConId); var e = countryRepository.GetById(id); // TODO: Add delete logic here countryRepository.Delete(e); return(RedirectToAction("Index")); }
public async Task <bool> Delete(Guid id) { Country country = await CountryRepository.GetById(id); if (country == null) { return(false); } return(await CountryRepository.Delete(country)); }
public HttpResponseMessage Delete(int userId, int countryId) { var repo = new CountryRepository(); var entity = repo.Delete(userId, countryId); var json = JsonConvert.SerializeObject(entity); return(new HttpResponseMessage { Content = new StringContent(json, Encoding.UTF8, "application/json") }); }
public IActionResult Delete(int Id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { return(Ok(_countryRepository.Delete(Id))); } catch { return(BadRequest(ModelState)); } }
public void Country_Repository_Delete() { var oldList = repo.GetAll().ToList(); var country = repo.GetById(1); var result = repo.Delete(country); context.SaveChanges(); Assert.IsNotNull(result); Assert.AreEqual("USA", result.Name); var newList = repo.GetAll().ToList(); Assert.IsNotNull(newList); Assert.AreEqual(oldList.Count - 1, newList.Count); }
public async Task DeleteCountry_RemovesFromDb() { // Arrange var lCreatedEntity = await countryRepository.Add(new Entities.CountryEntity { Name = "test" }); // Act await countryRepository.Delete(lCreatedEntity); // Assert var lResult = await countryRepository.GetById(lCreatedEntity.Id); Assert.IsNull(lResult); Assert.IsTrue(lCreatedEntity.Id > 0); }
public void CountriesCRUDTest() { var sessionFactory = SessionFactory.CreateSessionFactory(true); const string country1 = "CountryName1"; const string country2 = "CountryName2"; var countries = new List<Country> { TestEntities.CreateCountry(10000, "EnglishName1", country1), TestEntities.CreateCountry(10001, "EnglishName2", country2) }; var session = SessionManager.CurrentSession; var repository = new CountryRepository(session); repository.SaveUpdateCountries(countries); var fromDb = repository.GetAll(); Assert.True(fromDb.ToList().Count(c => c.CountryName == country1 || c.CountryName == country2) == 2 ); var updateCountry = countries.First(); const string country3 = "CountryName3"; const string englishName3 = "EnglishName3"; updateCountry.EnglishName = englishName3; updateCountry.CountryName = country3; repository.SaveUpdate(updateCountry); var updatedCountry = repository.GetById(updateCountry.CountryId); Assert.True(updatedCountry.CountryName == updateCountry.CountryName); Assert.True(updatedCountry.EnglishName == updateCountry.EnglishName); foreach (var country in countries) { repository.Delete(country); } session.Flush(); fromDb = repository.GetAll(); Assert.True(fromDb.ToList().Count(c => c.CountryName == country1 || c.CountryName == country2) == 0); }
public void Country_Repository_Create() { Console.WriteLine("Ejecutando NEW"); //Arrange Country c = new Country() { Name = "UK" }; //Act objRepo.Add(c); databaseContext.SaveChanges(); var lst = objRepo.GetAll().ToList(); //Assert Assert.AreEqual(4, lst.Count); Assert.AreEqual("UK", lst.Last().Name); objRepo.Delete(c); databaseContext.SaveChanges(); }
public bool Delete(int id) { return(_countryRepository.Delete(id)); }
public async Task <UpdateCountryCommandResponse> Handle(UpdateCountryCommand request, CancellationToken cancellationToken) { UpdateCountryCommandResponse response = new UpdateCountryCommandResponse() { IsSuccessful = false }; var country = new Countries(); Images pngImage = new Images(); Images svgImage = new Images(); var countryDocs = _context.GetAll(Constants.CountriesDiscriminator); var imageDocs = _context.GetAll(Constants.ImagesDiscriminator); var contentToDelete = new List <int>(); using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { List <int> objCountryId = new List <int>(); objCountryId.Add(request.CountryId); country = _CountryRepository.getCountry(objCountryId)[0]; List <Images> images = _CountryRepository.getImages(new List <int?> { country.PngimageId, country.SvgimageId }); if (request.ImagesData.JPGData == "" || request.ImagesData.JPGName == "" || request.ImagesData.SVGData == "" || request.ImagesData.SVGData == "") { throw new ArgumentNullException(nameof(request)); } ImageData imageData = new ImageData() { JPGData = request.ImagesData.JPGData, JPGName = request.ImagesData.JPGName, SVGData = request.ImagesData.SVGData, SVGName = request.ImagesData.SVGName }; List <string> urls = await _Eventblobcontext.PublishThroughBlobStorageAsync(imageData); foreach (Images img in images) { if (img.FileType == "svg") { img.Name = request.ImagesData.SVGName; img.ImageType = (int)ImageType.FlagSVG; img.FilePath = urls[1]; img.FileType = "svg"; img.UpdatedBy = ""; img.UpdatedDate = DateTime.UtcNow; _CountryRepository.Update(img); svgImage = img; } else { img.Name = request.ImagesData.JPGName; img.ImageType = (int)ImageType.FlagPNG; img.FilePath = urls[0]; img.FileType = "png"; img.UpdatedBy = ""; img.UpdatedDate = DateTime.UtcNow; _CountryRepository.Update(img); pngImage = img; } } foreach (var content in request.LanguageNames) { var countryContents = country.CountryContents.Where(s => s.LanguageId == content.LanguageID).FirstOrDefault(); if (countryContents == null) { CountryContents objCountryContents = new CountryContents(); objCountryContents.DisplayName = content.CountryName; objCountryContents.DisplayNameShort = content.ShortName; objCountryContents.LanguageId = content.LanguageID; country.CountryContents.Add(objCountryContents); } else { countryContents.DisplayName = content.CountryName; countryContents.DisplayNameShort = content.ShortName; countryContents.LanguageId = content.LanguageID; _CountryRepository.Update(countryContents); } } // List<ResourceGroupContents> ResourceGroupContents = resourceGroup.ResourceGroupContents.Where(s => s.ResourceGroupId == request.ResourceGroupId).ToList(); foreach (var resourceContent in country.CountryContents.ToList()) { if (request.LanguageNames.Where(s => s.LanguageID == resourceContent.LanguageId).Count() == 0) { contentToDelete.Add((int)resourceContent.LanguageId); country.CountryContents.Remove(resourceContent); _CountryRepository.Delete(resourceContent); } } country.UpdatedBy = ""; country.UpdatedDate = DateTime.Now; await _CountryRepository.UnitOfWork .SaveEntitiesAsync(); await _cacheService.ClearCacheAsync("countriesCacheKey"); await _cacheService.ClearCacheAsync("imagesCacheKey"); response.IsSuccessful = true; scope.Complete(); } using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var pngImageEvent = new ImageCommandEvent() { id = imageDocs.FirstOrDefault(d => d.GetPropertyValue <int>("ImageId") == pngImage.ImageId).GetPropertyValue <Guid>("id"), EventType = ServiceBusEventType.Update, Discriminator = Constants.ImagesDiscriminator, ImageId = pngImage.ImageId, ImageType = pngImage.ImageType, Name = pngImage.Name, CountryId = pngImage.CountryId, Keyword = pngImage.Keyword ?? string.Empty, Source = pngImage.Source ?? string.Empty, Description = pngImage.Description ?? string.Empty, Copyright = pngImage.Copyright ?? string.Empty, FilePath = pngImage.FilePath, FileType = pngImage.FileType, CreatedBy = pngImage.CreatedBy, CreatedDate = pngImage.CreatedDate, UpdatedBy = pngImage.UpdatedBy, UpdatedDate = pngImage.UpdatedDate, EmpGuid = pngImage.EmpGuid ?? string.Empty, IsEdited = true, PartitionKey = "" }; await _Eventcontext.PublishThroughEventBusAsync(pngImageEvent); var svgImageEvent = new ImageCommandEvent() { id = imageDocs.FirstOrDefault(d => d.GetPropertyValue <int>("ImageId") == svgImage.ImageId).GetPropertyValue <Guid>("id"), EventType = ServiceBusEventType.Update, Discriminator = Constants.ImagesDiscriminator, ImageId = svgImage.ImageId, ImageType = svgImage.ImageType, Name = svgImage.Name, CountryId = svgImage.CountryId, Keyword = svgImage.Keyword ?? string.Empty, Source = svgImage.Source ?? string.Empty, Description = svgImage.Description ?? string.Empty, Copyright = svgImage.Copyright ?? string.Empty, FilePath = svgImage.FilePath, FileType = svgImage.FileType, CreatedBy = svgImage.CreatedBy, CreatedDate = svgImage.CreatedDate, UpdatedBy = svgImage.UpdatedBy, UpdatedDate = svgImage.UpdatedDate, EmpGuid = svgImage.EmpGuid ?? string.Empty, IsEdited = true, PartitionKey = "" }; await _Eventcontext.PublishThroughEventBusAsync(svgImageEvent); foreach (var item in country.CountryContents) { var doc = countryDocs.FirstOrDefault(d => d.GetPropertyValue <int>("CountryId") == country.CountryId && d.GetPropertyValue <int?>("LanguageId") == item.LanguageId); var eventSourcing = new CountryCommandEvent() { id = doc != null?doc.GetPropertyValue <Guid>("id") : Guid.NewGuid(), EventType = doc != null ? ServiceBusEventType.Update : ServiceBusEventType.Create, CountryId = country.CountryId, SVGImageId = country.SvgimageId, PNGImageId = country.PngimageId, IsPublished = country.IsPublished, CreatedBy = country.CreatedBy, CreatedDate = country.CreatedDate, UpdatedBy = country.UpdatedBy, UpdatedDate = country.UpdatedDate, CountryContentId = item.CountryContentId, DisplayName = item.DisplayName, DisplayNameShort = item.DisplayNameShort, LanguageId = item.LanguageId, Discriminator = Constants.CountriesDiscriminator, PartitionKey = "" }; await _Eventcontext.PublishThroughEventBusAsync(eventSourcing); } foreach (int i in contentToDelete) { var deleteEvt = new CountryCommandEvent() { id = countryDocs.FirstOrDefault(d => d.GetPropertyValue <int>("CountryId") == country.CountryId && d.GetPropertyValue <int>("LanguageId") == i).GetPropertyValue <Guid>("id"), EventType = ServiceBusEventType.Delete, Discriminator = Constants.CountriesDiscriminator, PartitionKey = "" }; await _Eventcontext.PublishThroughEventBusAsync(deleteEvt); } scope.Complete(); } return(response); }
public void Delete() { mCountryRepository.Delete(this); }
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); }