public ActionResult <RClientOutput> PostClient([FromBody] RClientInput client)
        {
            try
            {
                if (client == null)
                {
                    throw new RestException("Er moet een client zijn om te posten");
                }

                int id = manager.AddClient(Mapper.ToClient(client));
                return(CreatedAtAction(nameof(GetClient), new { id }, Mapper.ToRClientOutput(manager.GetClient(id))));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult <RClientOutput> PutClient(int id, [FromBody] RClientInput client)
        {
            try
            {
                if (client == null)
                {
                    throw new RestException("Er moet een client zijn om te putten");
                }

                if (id != client.Id)
                {
                    throw new RestException("De id in de url en in de body komen niet overeen.");
                }
                manager.UpdateClient(id, Mapper.ToClient(client));
                return(Ok(Mapper.ToRClientOutput(manager.GetClient(id))));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Transforms a RClientInput object into a Client object.
 /// </summary>
 /// <param name="rClient">RCLient to transfrom.</param>
 /// <returns>The new Client object.</returns>
 public static Client ToClient(RClientInput rClient)
 {
     return(new Client(rClient.Name, rClient.Addres));
 }