public Adopter AddAdopter(Adopter adopter)
        {
            try
            {
                connection.Open();
                var cmd = connection.CreateCommand();
                cmd.CommandText = "insert into " + Constants.AdoptersTable + "(cellnum, transaction_nr, name, username, amount, area, geom) values(@cellnum,@transaction_nr,@name,@username,@amount,@area,@geom)";
                cmd.Parameters.Add(new SqlParameter("@cellnum", 1));
                cmd.Parameters.Add(new SqlParameter("@transaction_nr", adopter.transaction_nr));
                cmd.Parameters.Add(new SqlParameter("@name", adopter.username));
                cmd.Parameters.Add(new SqlParameter("@username", adopter.username));
                cmd.Parameters.Add(new SqlParameter("@amount", adopter.amount));
                cmd.Parameters.Add(new SqlParameter("@area", adopter.area));
                cmd.Parameters.Add(new SqlParameter("@geom", SqlGeometry.STGeomFromText(new SqlChars(adopter.geom), Constants.SRID_INT)) { UdtTypeName = "Geometry" });

                cmd.ExecuteNonQuery();
                connection.Close();

                return adopter;
            }
            catch(Exception e)
            {
                return null;
            }
        }
        //TODO: Add request for adopter by username
        public Adopter AssignLand(Adopter adopter)
        {
            connection.Open();

            AssignPlotOfLand assigner = new AssignPlotOfLand();

            SqlGeometry startingSquareKm = GeometryExtensions.FromWkt("POLYGON((12390034 -32564, 12390034 -32565, 12390035 -32565, 12390035 -32564, 12390034 -32564))", Constants.SRID_INT);
            assigner.SetStartingPoint(startingSquareKm.STPointN(1));
            {
                foreach (var geom in connection.Query<string>("select top 1 geom.STAsText() from " + Constants.LandTable))
                {
                    assigner.SetOuterBoundary(SqlGeometry.STGeomFromText(new SqlChars(geom), Constants.SRID_INT));
                }
            }
            connection.Close();

            var adopters = GetAllAdopters();

            //Check if transaction does not exist, else return null
            foreach (var a in adopters)
            {
                if (a.transaction_nr == adopter.transaction_nr)
                    return null;
            }

            var assignedGeom = assigner.Assign(adopter.area, Constants.SRID_INT, adopters);
            if (assignedGeom == null)
                return null;

            adopter.geom = new string(assignedGeom.STAsText().Value);

            return adopter;
        }
        public HttpResponseMessage<Adopter> AssignLand(int transaction, string username, string name, int amount, int area, HttpRequestMessage request)
        {
            var prop = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            bool isAllowed = false;
            foreach (var ip in Constants.AllowedIps)
            {
                if (ip.Equals(prop.Address))
                    isAllowed = true;
            }

            if(!isAllowed)
                return new HttpResponseMessage<Adopter>(null) { StatusCode = HttpStatusCode.Forbidden };

            //Create and assign land
            var adopter = new Adopter { username = username, name = name, amount = amount, area = area, transaction_nr = transaction };
            adopter = _donationRepository.AssignLand(adopter);
            if(adopter == null)
                return new HttpResponseMessage<Adopter>(null) { StatusCode = HttpStatusCode.BadRequest};

            //Add to database
            adopter = _donationRepository.AddAdopter(adopter);
            if (adopter == null)
                return new HttpResponseMessage<Adopter>(null) { StatusCode = HttpStatusCode.BadRequest };

            //Return Adopter with assigned land
            return new HttpResponseMessage<Adopter>(adopter) { StatusCode = HttpStatusCode.OK };
        }