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;
        }
        internal static object GlobalModuleToJsonModel(GlobalModule globalModule, Fields fields = null, bool full = true)
        {
            if (globalModule == null)
            {
                return(null);
            }

            if (fields == null)
            {
                fields = Fields.All;
            }

            dynamic obj = new ExpandoObject();

            //
            // name
            if (fields.Exists("name"))
            {
                obj.name = globalModule.Name;
            }

            //
            // id
            obj.id = GlobalModuleId.CreateFromName(globalModule.Name).Uuid;

            //
            // image
            if (fields.Exists("image"))
            {
                obj.image = globalModule.Image;
            }

            //
            // precondition
            if (fields.Exists("precondition"))
            {
                obj.precondition = globalModule.PreCondition;
            }

            return(Core.Environment.Hal.Apply(Defines.GlobalModulesResource.Guid, obj, full));
        }