public async Task GetNonExistingPurchasersForCountryFromDatabaseTest() { // arrange HAVIdatabaseContext dbContext = CreateDbContext(); CountryRepository countryRepository = new CountryRepository(dbContext); Country country = new Country() { Id = 0, ProfileId = 0, CountryName = "Name", CountryCode = "Code", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; PurchaserRepository repository = new PurchaserRepository(dbContext); await countryRepository.AddCountry(country); // act List <Purchaser> result = await repository.GetPurchasersForCountry(1); // assert Assert.IsTrue(result.Count == 0); dbContext.Dispose(); }
public IActionResult Index(Country newCountry) { // Add the new country to the repository countryRepository.AddCountry(newCountry); // loop though the list for countries foreach (Country item in countryRepository.Countries) { // add new selectitem elements to the countriesDropdown list // make element selected if it is an element with newCountry ConutryCode if (item.CountryCode == newCountry.CountryCode) { countriesDropdown.Add(new SelectListItem { Text = item.Name, Value = item.CountryCode, Selected = true }); } else { countriesDropdown.Add(new SelectListItem { Text = item.Name, Value = item.CountryCode }); } } ViewData["Countries"] = countriesDropdown; return(View(newCountry)); }
public void CountryRepositoryFunction_AddCountry_FunctionalityTest() { GeographyContextTest context = new GeographyContextTest(true); CountryRepository countryRepo = new CountryRepository(context); ContinentRepository continentRepo = new ContinentRepository(context); Continent continent = new Continent("Continent60"); context.SaveChanges(); continentRepo.AddContinent(continent); context.SaveChanges(); countryRepo.AddCountry(4, "Country60", 20, 30.0f); context.SaveChanges(); var countryFromRepo = countryRepo.GetCountry(4, 2); continentRepo.HasCountries(4).Should().BeTrue(); countryFromRepo.Name.Should().Be("Country60"); countryFromRepo.Population.Should().Be(20); countryFromRepo.Surface.Should().Be(30.0f); countryFromRepo.Continent.Name.Should().Be("Continent60"); }
public async Task DeleteExistingCountryTest() { // arrange HAVIdatabaseContext dbContext = CreateDbContext(); CountryRepository repository = new CountryRepository(dbContext); Country country = new Country() { Id = 0, ProfileId = 0, CountryCode = "Code", CountryName = "Name", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; Country addedCountry = await repository.AddCountry(country); // act Country result = await repository.DeleteCountryAsync(addedCountry.Id); // assert Assert.IsTrue(result == addedCountry); dbContext.Dispose(); }
public IActionResult Index(Country newCountry) { countryRepository.AddCountry(newCountry); foreach (Country item in countryRepository.CountriesSorted) { if (item.CountryCode == newCountry.CountryCode) { countriesDropdown.Add(new SelectListItem { Text = item.Name, Value = item.CountryCode, Selected = true }); } else { countriesDropdown.Add(new SelectListItem { Text = item.Name, Value = item.CountryCode }); } } ViewData["Countries"] = countriesDropdown; return(View(newCountry)); }
public async Task GetExistingCountryWithEverythingFromDatabaseTest() { // arrange HAVIdatabaseContext dbContext = CreateDbContext(); CountryRepository repository = new CountryRepository(dbContext); Country country = new Country() { Id = 1, ProfileId = 1, CountryCode = "Code", CountryName = "Name", Profile = new Profile() { Id = 1, Username = "******", Password = "******", Usertype = 0 } }; Country addedCountry = await repository.AddCountry(country); // act Country result = await repository.GetCountryEverything(addedCountry.Id); // assert Assert.IsTrue(result == addedCountry); Assert.IsTrue(result.Profile != null); dbContext.Dispose(); }
public async Task UpdateExistingCountryInDatabaseTest() { // arrange HAVIdatabaseContext dbContext = CreateDbContext(); CountryRepository repository = new CountryRepository(dbContext); Country country = new Country() { Id = 0, ProfileId = 0, CountryCode = "Code", CountryName = "Name", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; Country addedCountry = await repository.AddCountry(country); addedCountry.CountryName = "Denmark"; addedCountry.CountryCode = "DK"; addedCountry.Profile.Username = "******"; addedCountry.Profile.Password = "******"; // act Country result = await repository.UpdateCountry(addedCountry); // assert Assert.IsTrue(result == addedCountry); dbContext.Dispose(); }
public async Task GetExistingCountriesFromDatabaseTest() { // arrange HAVIdatabaseContext dbContext = CreateDbContext(); CountryRepository repository = new CountryRepository(dbContext); Country country1 = new Country() { Id = 0, ProfileId = 0, CountryCode = "Code", CountryName = "Name", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; Country country2 = new Country() { Id = 0, ProfileId = 0, CountryCode = "Code", CountryName = "Name", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; Country addedCountry1 = await repository.AddCountry(country1); Country addedCountry2 = await repository.AddCountry(country2); // act List <Country> result = (List <Country>) await repository.GetCountries(); // assert Assert.IsTrue(result.Count == 2); Assert.IsTrue(result.Contains(addedCountry1)); Assert.IsTrue(result.Contains(addedCountry2)); dbContext.Dispose(); }
public long AddCountry(CountryObject countryAccount) { try { return(_countryRepository.AddCountry(countryAccount)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult Create(CountryVM model) { try { string countryId = string.Empty; model.CreatedBy = LogInManager.LoggedInUserId; #region Check Country Code Available. if (this.CheckCountryCodeAvailable(model.Id, model.Code) == false) { return(Json(new { IsSuccess = false, errorMessage = string.Format("Country Code : {0} already exist.", model.Code) }, JsonRequestBehavior.AllowGet)); } #endregion countryId = countryRepository.AddCountry(model); if (!string.IsNullOrWhiteSpace(countryId)) { return(Json(new { IsSuccess = true, data = new { CountryId = countryId } }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, errorMessage = "Country details not saved successfully." }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { Utility.Utility.LogError(e, "Create"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }
public async Task <ActionResult <Country> > CreateCountry(Country country) { try { if (country == null) { return(BadRequest()); } var createdCountry = await _countryRepository.AddCountry(country); return(createdCountry); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database.")); } }
public IActionResult Index(Country newCountry) { countryRepository.AddCountry(newCountry); foreach (Country item in countryRepository.CountriesSorted) { // create a selectListItem for the dropdown list SelectListItem selectListItem = new SelectListItem { Text = item.Name, Value = item.CountryCode }; if (item.CountryCode == newCountry.CountryCode) { selectListItem.Selected = true; } countriesDropdown.Add(selectListItem); } ViewBag.Countries = countriesDropdown; return(View(newCountry)); }
public async Task GetExistingArticlesForSupplierFromDatabaseTest() { // arrange HAVIdatabaseContext dbContext = CreateDbContext(); CountryRepository countryRepository = new CountryRepository(dbContext); Country country = new Country() { Id = 0, ProfileId = 0, CountryName = "Name", CountryCode = "Code", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; PurchaserRepository purchaserRepository = new PurchaserRepository(dbContext); Purchaser purchaser = new Purchaser() { Id = 0, ProfileId = 0, CountryId = 1, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; await countryRepository.AddCountry(country); await purchaserRepository.AddPurchaser(purchaser); SupplierRepository supplierRepository = new SupplierRepository(dbContext); Supplier supplier = new Supplier() { Id = 1, ProfileId = 0, CompanyName = "Name", CompanyLocation = "Location", FreightResponsibility = "EXW", PalletExchange = 1, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; ArticleRepository repository = new ArticleRepository(dbContext); Article article1 = new Article() { Id = 0, PurchaserId = 1, CountryId = 1, SupplierId = 1, ArticleInformationId = 0, InternalArticleInformationId = 0, VailedForCustomer = "Customer", DateCreated = DateTime.Now, ArticleInformationCompleted = 0, InternalArticalInformationCompleted = 0, ArticleState = 0, ErrorReported = 0, ErrorField = "Field", ErrorMessage = "Message", ErrorOwner = "Owner", ArticleInformation = new ArticleInformation(), InternalArticleInformation = new InternalArticleInformation() }; Article article2 = new Article() { Id = 0, PurchaserId = 1, CountryId = 1, SupplierId = 1, ArticleInformationId = 0, InternalArticleInformationId = 0, VailedForCustomer = "Customer", DateCreated = DateTime.Now, ArticleInformationCompleted = 0, InternalArticalInformationCompleted = 0, ArticleState = 0, ErrorReported = 0, ErrorField = "Field", ErrorMessage = "Message", ErrorOwner = "Owner", ArticleInformation = new ArticleInformation(), InternalArticleInformation = new InternalArticleInformation() }; await supplierRepository.AddSupplier(supplier); Article addedArticle1 = await repository.AddArticle(article1); Article addedArticle2 = await repository.AddArticle(article2); // act List <Article> result = (List <Article>) await repository.GetArticlesForSupplier(1); // assert Assert.IsTrue(result.Count == 2); Assert.IsTrue(result.Contains(addedArticle1)); Assert.IsTrue(result.Contains(addedArticle2)); dbContext.Dispose(); }
public IActionResult addCountry([FromBody] Country T) { return(Ok(countryRepository.AddCountry(T))); }
public int AddCountry(Country country) { using var repo = new CountryRepository(configuration); return(repo.AddCountry(country)); }