public int AddFowardingServer(IUnitOfWork uow, ForwardingServer forwardingServer) { var mappedForwardingServer = Mapper.Map<SQL.Models.ForwardingServer>(forwardingServer); var id = Convert.ToInt32(uow.Db.Insert(mappedForwardingServer)); Mapper.Map(mappedForwardingServer, forwardingServer); return id; }
// PUT api/dnsentries/5 public void Put(int id, ForwardingServer forwardingServer) { using (var uow = unitOfWorkProvider.GetUnitOfWork()) { forwardingServersRepository.UpdateForwardingServer(uow, forwardingServer); uow.Commit(); } }
// POST api/dnsentries public void Post(ForwardingServer forwardingServer) { using (var uow = unitOfWorkProvider.GetUnitOfWork()) { forwardingServersRepository.AddFowardingServer(uow, forwardingServer); uow.Commit(); } }
private DnsEntry ForwardRequestToServer(DnsRequest dnsRequest, ForwardingServer forwardingServer, RecordType recordType) { var client = new DnsClient(IPAddress.Parse(forwardingServer.IpV4), 2000); var answer = client.Resolve(dnsRequest.Name, recordType); if (answer != null && answer.AnswerRecords.Any()) { var record = answer.AnswerRecords.FirstOrDefault(r => r.RecordType == recordType); //if (record.RecordType != RecordType.A) // return null; if (record == null) return null; if (record.RecordType != RecordType.A) return null; var dnsEntry = new DnsEntry() { Name = record.Name, IpV4 = ((ARecord)record).Address.ToString() }; return dnsEntry; } return null; }
public void Should_Create_Forwarding_Server_Entry() { new ModelMappings().Create(); var forwardingServer = new ForwardingServer() { Name = "test", IpV4 = "192.168.1.1", }; IUnitOfWorkProvider unitOfWorkProvider = new NPocoUnitOfWorkProvider(); using (var uow = unitOfWorkProvider.GetUnitOfWork()) { IForwardingServersRepository repository = new ForwardingServersRepository(); repository.DeleteAllEntries(uow); var id = repository.AddFowardingServer(uow, forwardingServer); uow.Commit(); id.Should().BeGreaterThan(0, "because a valid ID should have been returned when the entry was created."); forwardingServer.Id.Should().Be(id, "because a valid ID should have been returned when the entry was created."); } }
public void Should_Update_Forwarding_Server_Entry() { new ModelMappings().Create(); var forwardingServer = new ForwardingServer() { Name = "testing", IpV4 = "192.168.1.1", }; IUnitOfWorkProvider unitOfWorkProvider = new NPocoUnitOfWorkProvider(); using (var uow = unitOfWorkProvider.GetUnitOfWork()) { IForwardingServersRepository repository = new ForwardingServersRepository(); repository.DeleteAllEntries(uow); var id = repository.AddFowardingServer(uow, forwardingServer); forwardingServer.Name = "test2"; repository.UpdateForwardingServer(uow, forwardingServer); var updatedEntry = repository.GetForwardingServer(uow, forwardingServer.Id); updatedEntry.Name.Should().Be(forwardingServer.Name); } }
public void UpdateForwardingServer(IUnitOfWork uow, ForwardingServer forwardingServer) { uow.Db.Update(Mapper.Map<SQL.Models.ForwardingServer>(forwardingServer)); }