public async Task <IHttpActionResult> PutIPAddress(int id, IPAddress iPAddress)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != iPAddress.id)
            {
                return(BadRequest());
            }

            db.Entry(iPAddress).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IPAddressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GetIPAddress(int id)
        {
            IPAddress iPAddress = await db.IPAddresses.FindAsync(id);

            if (iPAddress == null)
            {
                return(NotFound());
            }

            return(Ok(iPAddress));
        }
        public async Task <IHttpActionResult> DeleteIPAddress(int id)
        {
            IPAddress iPAddress = await db.IPAddresses.FindAsync(id);

            if (iPAddress == null)
            {
                return(NotFound());
            }

            db.IPAddresses.Remove(iPAddress);
            await db.SaveChangesAsync();

            return(Ok(iPAddress));
        }
        public async Task <IHttpActionResult> PostIPAddress()
        {
            var           ip            = "141.8.56.32";
            IpStackClient ipStackClient = new IpStackClient();
            IPDetails     ipDetails     = ipStackClient.GetDetails(ip);

            IPAddress ipaddress = new IPAddress
            {
                ip             = ipDetails.ip,
                continent_code = ipDetails.continent_code,
                continent_name = ipDetails.continent_name,
                country_code   = ipDetails.country_code,
                country_name   = ipDetails.country_name,
                region_code    = ipDetails.region_code,
                region_name    = ipDetails.region_name,
                city           = ipDetails.city,
                zip            = ipDetails.zip,
                latitude       = ipDetails.latitude,
                longitude      = ipDetails.longitude
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.IPAddresses.Add(ipaddress);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (IPAddressExists(ipaddress.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = ipaddress.id }, ipaddress));
        }