Пример #1
0
        public object Get()
        {
            string ipRestrictionUuid = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(ipRestrictionUuid))
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            IPRestrictionId ipId = new IPRestrictionId(ipRestrictionUuid);

            // Get site rule is for if applicable
            Site site = ipId.SiteId == null ? null : SiteHelper.GetSite(ipId.SiteId.Value);

            List <Rule> rules = IPRestrictionsHelper.GetRules(site, ipId.Path);

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(rules.Count());

            Fields fields = Context.Request.GetFields();

            return(new {
                entries = rules.Select(rule => IPRestrictionsHelper.RuleToJsonModelRef(rule, site, ipId.Path, fields))
            });
        }
Пример #2
0
        public void Delete(string id)
        {
            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
                Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return;
            }

            Rule rule = IPRestrictionsHelper.GetRules(site, ruleId.Path).Where(r => r.IpAddress.ToString().Equals(ruleId.IpAddress)).FirstOrDefault();

            if (rule != null)
            {
                var section = IPRestrictionsHelper.GetSection(site, ruleId.Path, ManagementUnit.ResolveConfigScope());

                IPRestrictionsHelper.DeleteRule(rule, section);

                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
Пример #3
0
        public object Get(string id)
        {
            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());
            }

            Rule rule = IPRestrictionsHelper.GetRules(site, ruleId.Path).Where(r => r.IpAddress.ToString().Equals(ruleId.IpAddress)).FirstOrDefault();

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

            return(IPRestrictionsHelper.RuleToJsonModel(rule, site, ruleId.Path));
        }