Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [FromBody] CarrinhoDeCompraResource carrinhoDeCompraResource)
        {
            try
            {
                var carrinhoDeCompra = await _unitOfWork.CarrinhoDeCompras.GetByIdAsync(id);

                if (ModelState.IsValid)
                {
                    carrinhoDeCompra = CarrinhoDeCompraMapper.ResourceToModel(carrinhoDeCompraResource, carrinhoDeCompra);
                    await _unitOfWork.CompleteAsync();

                    CarrinhoDeCompraMapper.ModelToResource(carrinhoDeCompra);
                }
                return(Ok(carrinhoDeCompra));
            }
            catch (Exception e)
            {
                LogError.LogErrorWithSentry(e);
                return(BadRequest(ModelState));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Create([FromBody] CarrinhoDeCompraResource carrinhoDeCompraResource)
        {
            if (carrinhoDeCompraResource == null)
            {
                return(NotFound());
            }
            try
            {
                var carrinhoDeCompra = new CarrinhoDeCompra();
                if (ModelState.IsValid)
                {
                    carrinhoDeCompra = CarrinhoDeCompraMapper.ResourceToModel(carrinhoDeCompraResource, carrinhoDeCompra);
                }
                _unitOfWork.CarrinhoDeCompras.Add(carrinhoDeCompra);
                await _unitOfWork.CompleteAsync();

                return(Ok(carrinhoDeCompra));
            }
            catch (Exception exception)
            {
                LogError.LogErrorWithSentry(exception);
                return(BadRequest());
            }
        }