// PUT api/values/192.168.1.1
        public IHttpActionResult Put([FromBody] GeolocationDomain data)
        {
            GeolocationDomainResult geolocationDomain = _geolocationLogic.Value.PutValue(data);

            if (!geolocationDomain.Succesful)
            {
                if (geolocationDomain.ErrorCode == 404)
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent(geolocationDomain.ErrorMsg)
                    };
                    throw new HttpResponseException(resp);
                }
                else
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        Content = new StringContent(geolocationDomain.ErrorMsg)
                    };
                    throw new HttpResponseException(resp);
                }
            }
            return(Json(geolocationDomain));
        }
        /// <summary>
        /// Update existing geolocation in database
        /// </summary>
        /// <param name="data">geolocation data</param>
        /// <returns>status of operation with updated geolocation data</returns>
        public GeolocationDomainResult PutValue(GeolocationDomain data)
        {
            GeolocationDomainResult geolocationDomainResult = new GeolocationDomainResult();

            geolocationDomainResult.Succesful = true;
            using (var db = _geolocationsRepositories.GetGeolocationEntities())
            {
                try
                {
                    geolocations g = new geolocations();
                    g = db.geolocations.Where(p => p.ip == data.Ip).FirstOrDefault();
                    if (g != null)
                    {
                        geolocationDomainResult.Geolocation = new GeolocationDomain();
                        geolocationDomainResult.Geolocation = data;
                        _mapper.Map(data, g);
                        db.SaveChanges();
                    }
                    else
                    {
                        geolocationDomainResult.ErrorCode = 404;
                        geolocationDomainResult.ErrorMsg  = "The given ip address doesn't exist.";
                        geolocationDomainResult.Succesful = false;
                    }
                }
                catch (Exception ex)
                {
                    geolocationDomainResult.ErrorCode = 0;
                    geolocationDomainResult.ErrorMsg  = "Internal DataBase Error.";
                    geolocationDomainResult.Succesful = false;
                    Logger.Log.Error(ex);
                }
            }
            return(geolocationDomainResult);
        }
        // POST api/values
        public IHttpActionResult Post([FromBody] GeolocationDomain data)
        {
            GeolocationDomainResult geolocationDomain = _geolocationLogic.Value.AddValue(data);

            if (!geolocationDomain.Succesful)
            {
                if (geolocationDomain.ErrorCode == 302)
                {
                    return(RedirectToRoute("GeolocationApiGet", new { controller = "Geolocation", ipAddress = data.Ip }));
                }
                else
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        Content = new StringContent(geolocationDomain.ErrorMsg)
                    };
                    throw new HttpResponseException(resp);
                }
            }
            return(Json(geolocationDomain));
        }