Ejemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] SetPolicyDTO policy, ApiVersion version)
        {
            //if (policy == null) return BadRequest();  //not needed as middleware only calls this action when policy is deserialized (possibly default); otherwise, it sends 400 (Bad Request) on its own (e.g. if malformed JSON payload).
            var svcRslt = await _policyService.AddAsync(policy);

            if (!svcRslt.Success)
            {
                return(BadRequest(svcRslt.Message));
            }
            return(CreatedAtRoute("GetPolicyById", new { id = svcRslt.Value.Id, version = version.ToString() }, svcRslt.Value));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Replace(string id, [FromBody] SetPolicyDTO policy)
        {
            //if (id == null) return BadRequest();  //not needed as middleware only calls this action if id is present; otherwise, it will try a different route, e.g. causing 405 (Method Not Allowed) if PUT request w/o id.
            //if (policy == null) return BadRequest();  //not needed as middleware only calls this action when policy is deserialized (possibly default); otherwise, it sends 400 (Bad Request) on its own (e.g. if malformed JSON payload).
            var svcRslt = await _policyService.ReplaceAsync(id, policy);

            if (!svcRslt.Success)
            {
                return(NotFound());
            }
            return(NoContent());
        }