public HttpResponseMessage Post(ApplicationModel model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } var app = new Application(); app.Name = model.Name; app.Description = model.Description; app.LogoUrl = model.LogoUrl; app.Namespace = model.Namespace; app.Audience = model.Audience; app.TokenLifetime = model.TokenLifetime; app.AllowRefreshToken = model.AllowRefreshToken; app.RequireConsent = model.RequireConsent; app.RememberConsentDecision = model.RememberConsentDecision; app.SigningKey = config.Keys.All.Single(x => x.ID == model.SigningKeyID); app.Enabled = model.Enabled; config.Applications.Add(app); config.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, new { ID = app.ID }); }
public HttpResponseMessage Put(int id, ApplicationModel model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } var app = config.Applications.All.SingleOrDefault(x => x.ID == id); if (app == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } app.Name = model.Name; app.Description = model.Description; app.LogoUrl = model.LogoUrl; app.Namespace = model.Namespace; app.Audience = model.Audience; app.TokenLifetime = model.TokenLifetime; app.AllowRefreshToken = model.AllowRefreshToken; app.RequireConsent = model.RequireConsent; app.RememberConsentDecision = model.RememberConsentDecision; app.SigningKey = config.Keys.All.Single(x => x.ID == model.SigningKeyID); app.Enabled = model.Enabled; ; config.SaveChanges(); return Request.CreateResponse(HttpStatusCode.NoContent); }
public HttpResponseMessage Put(int id, ApplicationModel model) { if (!ModelState.IsValid) { return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors()); } var app = config.Applications.All.SingleOrDefault(x => x.ID == id); if (app == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } if (this.config.Applications.All.Any(x => x.Namespace == model.Namespace && x.ID != id)) { ModelState.AddModelError("", "That Namespace is already in use."); return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors()); } if (this.config.Applications.All.Any(x => x.Audience == model.Audience && x.ID != id)) { ModelState.AddModelError("", "That Audience is already in use."); return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors()); } app.Name = model.Name; app.Description = model.Description; app.LogoUrl = model.LogoUrl; app.Namespace = model.Namespace; app.Audience = model.Audience; app.TokenLifetime = model.TokenLifetime; app.AllowRefreshToken = model.AllowRefreshToken; app.RequireConsent = model.RequireConsent; app.AllowRememberConsentDecision = model.RememberConsentDecision; app.AllowSlidingRefreshTokenExpiration = model.SlidingRefreshTokenExpiration; app.SigningKey = config.Keys.All.Single(x => x.ID == model.SigningKeyID); app.Enabled = model.Enabled; ; config.SaveChanges(); return Request.CreateResponse(HttpStatusCode.NoContent); }
public HttpResponseMessage Post(ApplicationModel model) { if (!ModelState.IsValid) { return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors()); } if (this.config.Applications.All.Any(x => x.Namespace == model.Namespace)) { ModelState.AddModelError("", "That Namespace is already in use."); return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors()); } if (this.config.Applications.All.Any(x => x.Audience == model.Audience)) { ModelState.AddModelError("", "That Audience is already in use."); return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors()); } var app = new Application(); app.Name = model.Name; app.Description = model.Description; app.LogoUrl = model.LogoUrl; app.Namespace = model.Namespace; app.Audience = model.Audience; app.TokenLifetime = model.TokenLifetime; app.AllowRefreshToken = model.AllowRefreshToken; app.RequireConsent = model.RequireConsent; app.AllowRememberConsentDecision = model.RememberConsentDecision; app.AllowSlidingRefreshTokenExpiration = model.SlidingRefreshTokenExpiration; app.SigningKey = config.Keys.All.Single(x => x.ID == model.SigningKeyID); app.Enabled = model.Enabled; config.Applications.Add(app); config.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, new { ID = app.ID }); }