public object Post([FromBody] dynamic model) { // Create Site Site site = SiteHelper.CreateSite(model, _fileProvider); // Check if site with name already exists if (ManagementUnit.ServerManager.Sites.Any(s => s.Name.Equals(site.Name, StringComparison.OrdinalIgnoreCase))) { throw new AlreadyExistsException("name"); } // Save it ManagementUnit.ServerManager.Sites.Add(site); ManagementUnit.Current.Commit(); // Refresh site = SiteHelper.GetSite(site.Id); WaitForSiteStatusResolve(site); // // Create response dynamic website = (dynamic)SiteHelper.ToJsonModel(site, Context.Request.GetFields()); return(Created((string)SiteHelper.GetLocation(website.id), website)); }
public object Get(string id) { Site site = SiteHelper.GetSite(new SiteId(id).Id); if (site == null) { return(NotFound()); } return(SiteHelper.ToJsonModel(site, Context.Request.GetFields())); }
public void Delete(string id) { Site site = SiteHelper.GetSite(new SiteId(id).Id); if (site != null) { SiteHelper.DeleteSite(site); ManagementUnit.Current.Commit(); } // Success Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public static Site ResolveSite(dynamic model = null) { Site site = null; string scope = null; string siteUuid = null; // Resolve from model if (model != null) { // // website.id if (model.website != null) { if (!(model.website is JObject)) { throw new ApiArgumentException("website"); } siteUuid = DynamicHelper.Value(model.website.id); } // // scope if (model.scope != null) { scope = DynamicHelper.Value(model.scope); } } var context = HttpHelper.Current; // // Resolve {site_id} from query string if (siteUuid == null) { siteUuid = context.Request.Query[Defines.IDENTIFIER]; } if (!string.IsNullOrEmpty(siteUuid)) { SiteId siteId = new SiteId(siteUuid); site = SiteHelper.GetSite(new SiteId(siteUuid).Id); if (site == null) { throw new NotFoundException("site"); } return(site); } // // Resolve {scope} from query string if (scope == null) { scope = context.Request.Query[SCOPE_KEY]; } if (!string.IsNullOrEmpty(scope)) { int index = scope.IndexOf('/'); string siteName = index >= 0 ? scope.Substring(0, index) : scope; site = ManagementUnit.Current.ServerManager.Sites.FirstOrDefault(s => s.Name.Equals(siteName, StringComparison.OrdinalIgnoreCase)); // Scope points to non existant site if (site == null) { throw new ScopeNotFoundException(scope); } } return(site); }