Пример #1
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            RuleId ruleId = new RuleId(id);

            Site site = ruleId.SiteId == null ? null : SiteHelper.GetSite(ruleId.SiteId.Value);

            if (ruleId.SiteId != null && site == null)
            {
                // The rule id specified a site but we couldn't find it, therefore we can't get the rule
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            var    section    = IPRestrictionsHelper.GetSection(site, ruleId.Path, configPath);
            Rule   rule       = section.IpAddressFilters.Where(r => r.IpAddress.ToString().Equals(ruleId.IpAddress)).FirstOrDefault();

            if (rule == null)
            {
                return(NotFound());
            }

            rule = IPRestrictionsHelper.SetRule(rule, model, section);

            ManagementUnit.Current.Commit();

            dynamic rle = IPRestrictionsHelper.RuleToJsonModel(rule, site, ruleId.Path);

            if (rle.id != id)
            {
                return(LocationChanged(IPRestrictionsHelper.GetRuleLocation(rle.id), rle));
            }

            return(rle);
        }