コード例 #1
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var preConditionId = new PreConditionId(id);

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

            if (preConditionId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            OutboundRulesSection section      = OutboundRulesHelper.GetSection(site, preConditionId.Path);
            PreCondition         precondition = section.PreConditions.FirstOrDefault(pc => pc.Name.Equals(preConditionId.Name, StringComparison.OrdinalIgnoreCase));

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

            OutboundRulesHelper.UpdatePreCondition(model, precondition, section);

            ManagementUnit.Current.Commit();

            dynamic updatedPreCondition = OutboundRulesHelper.PreConditionToJsonModel(precondition, site, preConditionId.Path, Context.Request.GetFields(), true);

            if (updatedPreCondition.id != id)
            {
                return(LocationChanged(OutboundRulesHelper.GetPreConditionLocation(updatedPreCondition.id), updatedPreCondition));
            }

            return(updatedPreCondition);
        }