public void WhenAddingEntity_ThenGetAndUpdate() { DatabaseTestUtility.DropCreateFirebrickDatabase(); // Arrange var repository = new DomainRepository(new DatabaseFactory()); Domain newEntity = DefaultModelHelper.DummyPopulatedDomain(); // Act repository.Add(newEntity); repository.Commit(); // Use a new context and repository to verify the vehicle was added var repositoryTwo = new DomainRepository(new DatabaseFactory()); Domain loadedEntity = repositoryTwo.GetById(1); loadedEntity.HostHeader = "NewHostHeader"; repositoryTwo.Update(loadedEntity); repositoryTwo.Commit(); // Use a new context and repository to verify the vehicle was added var repositoryThree = new DomainRepository(new DatabaseFactory()); newEntity = repositoryThree.GetById(1); Assert.NotNull(newEntity); Assert.Equal("NewHostHeader", newEntity.HostHeader); }
public ActionResult Edit(long?domain_id, string domain_name, string domain_comment) { using (DomainRepository domain_repository = new DomainRepository()) { if (domain_id.HasValue) { domain_repository.Update(domain_id.Value, domain_name, domain_comment); } else { domain_id = domain_repository.CreateGlobalID(); domain_repository.Create(domain_id.Value, domain_name, domain_comment); } } return(RedirectToAction("Index")); }
public async Task <ViewModels.DomainViewModel> QueryForDomainDataAsync(string domainName) { if (!Umbler.Infra.CrossCutting.StringHelper.IsValidDomain(domainName)) { return(new ViewModels.DomainViewModel() { Name = "Dominío Invalído" }); } var domain = await _domainRepository.GetByDomainNameAsync(domainName); if (domain == null) { domain = await FillDomainDataAsync(domainName); _domainRepository.Add(domain); } if (DateTime.Now.Subtract(domain.UpdatedAt).TotalMinutes > domain.Ttl) { var refreshedDomain = await FillDomainDataAsync(domainName); domain.HostedAt = refreshedDomain.HostedAt; domain.Name = refreshedDomain.Name; domain.Ip = refreshedDomain.Ip; domain.WhoIs = refreshedDomain.WhoIs; domain.UpdatedAt = refreshedDomain.UpdatedAt; domain.Ttl = refreshedDomain.Ttl; _domainRepository.Update(); } return(Adapters.DomainEntityToDomainViewModel.GetViewModel(domain)); }