Пример #1
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            // Rule must be created for a specific ip restriction section
            if (model.ip_restriction == null)
            {
                throw new ApiArgumentException("ip_restriction");
            }
            if (!(model.ip_restriction is JObject))
            {
                throw new ApiArgumentException("ip_restriction");
            }
            string ipUuid = DynamicHelper.Value(model.ip_restriction.id);

            if (ipUuid == null)
            {
                throw new ApiArgumentException("ip_restriction.id");
            }

            // Get the ip restriction feature id
            IPRestrictionId ipId = new IPRestrictionId(ipUuid);

            // Get site
            Site site = ipId.SiteId == null ? null : SiteHelper.GetSite(ipId.SiteId.Value);

            string            configPath = ManagementUnit.ResolveConfigScope(model);
            IPSecuritySection section    = IPRestrictionsHelper.GetSection(site, ipId.Path, configPath);

            // Create ip restriction rule
            Rule rule = IPRestrictionsHelper.CreateRule(model, section);

            // Add it
            IPRestrictionsHelper.AddRule(rule, section);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic r = IPRestrictionsHelper.RuleToJsonModel(rule, site, ipId.Path);

            return(Created(IPRestrictionsHelper.GetRuleLocation(r.id), r));
        }