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

            if (!svcRslt.Success)
            {
                return(BadRequest(svcRslt.Message));
            }
            return(CreatedAtRoute("GetSaleById", new { id = svcRslt.Value.Id, version = version.ToString() }, svcRslt.Value));
        }
Example #2
0
        public async Task <IActionResult> Replace(string id, [FromBody] SetSaleDTO sale)
        {
            //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 (sale == null) return BadRequest();  //not needed as middleware only calls this action when sale is deserialized (possibly default); otherwise, it sends 400 (Bad Request) on its own (e.g. if malformed JSON payload).
            var svcRslt = await _saleService.ReplaceAsync(id, sale);

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