public HttpResponseMessage Put(ClientModel model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors());
            }

            var item = this.config.Clients.All.SingleOrDefault(X => X.ClientId == model.ClientId);
            if (item == null)
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }

            if (config.Clients.All.Any(x => x.Name == model.Name && x.ClientId != model.ClientId))
            {
                ModelState.AddModelError("", "That Name is already in use.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors());
            }

            item.Name = model.Name;
            item.Flow = model.Flow;
            item.AllowRefreshToken = model.AllowRefreshToken;
            item.RequireConsent = model.RequireConsent;
            item.Enabled = model.Enabled;
            item.SetSharedSecret(model.ClientSecret);

            this.config.SaveChanges();

            return Request.CreateResponse(HttpStatusCode.NoContent);
        }
        public HttpResponseMessage Put(ClientModel model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            var item = this.config.Clients.All.SingleOrDefault(X => X.ClientId == model.ClientId);
            if (item == null)
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }

            if (!String.IsNullOrEmpty(model.ClientSecret))
            {
                item.ClientSecret = model.ClientSecret;
            }
            item.Name = model.Name;
            item.Flow = model.Flow;
            item.AllowRefreshToken = model.AllowRefreshToken;
            item.RequireConsent = model.RequireConsent;
            item.Enabled = model.Enabled;

            this.config.SaveChanges();

            return Request.CreateResponse(HttpStatusCode.NoContent);
        }
        public HttpResponseMessage Post(ClientModel model)
        {
            if (String.IsNullOrEmpty(model.ClientSecret))
            {
                ModelState.AddModelError("model.ClientSecret", "ClientSecret is required");
            }

            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors());
            }

            if (config.Clients.All.Any(x => x.ClientId == model.ClientId))
            {
                ModelState.AddModelError("", "That Client ID is already in use.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors());
            }
            if (config.Clients.All.Any(x => x.Name == model.Name))
            {
                ModelState.AddModelError("", "That Name is already in use.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors());
            }

            var item = new Client();
            item.ClientId = model.ClientId;
            item.Name = model.Name;
            item.Flow = model.Flow;
            item.AllowRefreshToken = model.AllowRefreshToken;
            item.RequireConsent = model.RequireConsent;
            item.Enabled = model.Enabled;
            item.SetSharedSecret(model.ClientSecret);
            
            this.config.Clients.Add(item);
            this.config.SaveChanges();

            var response = Request.CreateResponse(HttpStatusCode.OK, item);
            var url = Url.Link("Admin-Endpoints", new { controller = "Clients", id = item.ClientId });
            response.Headers.Location = new Uri(url);
            return response;
        }