Example #1
0
        public HttpResponseMessage UpdateKlant(string klantKey, [FromBody] string newKlantJSON) //
        {
            Debug.WriteLine("UpdateKlant");
            Debug.WriteLine("klantKey: " + klantKey);
            Debug.WriteLine("string: " + newKlantJSON);
            try
            {
                Klant newKlant = JsonConvert.DeserializeObject <Klant>(newKlantJSON);

                Debug.WriteLine("klant.naam: " + newKlant.Naam);
                Debug.WriteLine("klant.key: " + newKlant.Klant_key);
                Debug.WriteLine("klant.id: " + newKlant.Id);
                Debug.WriteLine("klant.Straat: " + newKlant.Straat);

                Klant klant = repo.GetByKey(klantKey);
                if (klant.Klant_key.ToLower() == newKlant.Klant_key.ToLower())
                {
                    newKlant.Id = klant.Id;
                    repo.SaveKlant(newKlant);
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }