public object Get(string id) { GlobalModuleId moduleId = GlobalModuleId.CreateFromUuid(id); GlobalModule module = ModuleHelper.GetGlobalModules().FirstOrDefault(m => m.Name.Equals(moduleId.Name)); if (module == null) { return(NotFound()); } return(ModuleHelper.GlobalModuleToJsonModel(module)); }
public object Patch(string id, [FromBody] dynamic model) { GlobalModuleId moduleId = GlobalModuleId.CreateFromUuid(id); GlobalModule module = ModuleHelper.GetGlobalModules().FirstOrDefault(m => m.Name.Equals(moduleId.Name)); if (module == null) { return(NotFound()); } module = ModuleHelper.UpdateGlobalModule(module, model); ManagementUnit.Current.Commit(); return(ModuleHelper.GlobalModuleToJsonModel(module)); }
public void Delete(string id, [FromBody] dynamic model) { GlobalModuleId moduleId = GlobalModuleId.CreateFromUuid(id); GlobalModule module = ModuleHelper.GetGlobalModules().FirstOrDefault(m => m.Name.Equals(moduleId.Name)); if (module != null) { // Delete target global module ModuleHelper.DeleteGlobalModule(module); // Save changes ManagementUnit.Current.Commit(); } // Success Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public object Get() { // Check if the scope of the request is for site Site site = ApplicationHelper.ResolveSite(); // Cannot target the global modules from site scope or deeper if (site != null) { return(NotFound()); } List <GlobalModule> modules = ModuleHelper.GetGlobalModules(); this.Context.Response.SetItemsCount(modules.Count()); Fields fields = Context.Request.GetFields(); return(new { global_modules = modules.Select(globalModule => ModuleHelper.GlobalModuleToJsonModelRef(globalModule, fields)) }); }
public object Post([FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } if (model.modules == null || !(model.modules is JObject)) { throw new ApiArgumentException("modules"); } string modulesUuid = DynamicHelper.Value(model.modules.id); if (modulesUuid == null) { throw new ApiArgumentException("modules.id"); } // Get the feature id Module module = null; ModulesId modulesId = new ModulesId(modulesUuid); Site site = modulesId.SiteId == null ? null : SiteHelper.GetSite(modulesId.SiteId.Value); if (modulesId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NotFound; return(null); } ModuleHelper.EnsureValidScope(site, modulesId.Path); string configPath = ManagementUnit.ResolveConfigScope(model); ModulesSection section = ModuleHelper.GetModulesSection(site, modulesId.Path, configPath); // The post could either be creating a Managed module, or adding an existing // global module to the modules list. // This information is taken from the model's type value string type = DynamicHelper.Value(model.type); if (string.IsNullOrEmpty(type)) { // The module being added is a global/native module string name = DynamicHelper.Value(model.name); if (string.IsNullOrEmpty(name)) { throw new ApiArgumentException("name"); } GlobalModule existingGlobalModule = ModuleHelper.GetGlobalModules().FirstOrDefault(m => m.Name.Equals(name)); // Adding a global module to the modules list means it must already exist in global modules if (existingGlobalModule == null) { throw new NotFoundException("name"); } // Add the existing global module module = ModuleHelper.AddExistingGlobalModule(existingGlobalModule, section); ManagementUnit.Current.Commit(); } else { // Module being added to enabled modules is a managed module // Create module from model module = ModuleHelper.CreateManagedModule(model, section); // Save it ModuleHelper.AddManagedModule(module, section); ManagementUnit.Current.Commit(); } // // Create response dynamic moduleEntry = ModuleHelper.ModuleToJsonModel(module, site, modulesId.Path); return(Created(ModuleHelper.GetModuleEntryLocation(moduleEntry.id), moduleEntry)); }