Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] SaleAddClientModel saleAddDto)
        {
            var result = await _saleService.AddAsync(saleAddDto);

            if (result.IsError)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Create(SaleViewModel sale)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(sale));
                }

                await _saleService.AddAsync(_mapper.Map <SaleDTO>(sale)).ConfigureAwait(false);

                return(RedirectToAction("Index"));
            }
            catch (Exception exception)
            {
                ViewBag.Error = exception.Message;

                return(View());
            }
        }