Пример #1
0
        public async Task <IActionResult> GetAll()
        {
            try
            {
                var carrinhoDeCompras = await _unitOfWork.CarrinhoDeCompras.GetAllWithProdutosAsync();

                List <CarrinhoDeCompraResource> carrinhoDeCompraResource = new List <CarrinhoDeCompraResource>();

                if (carrinhoDeCompras == null)
                {
                    return(NoContent());
                }

                foreach (var carrinhoDeCompra in carrinhoDeCompras)
                {
                    if (carrinhoDeCompra.IsAtivo)
                    {
                        carrinhoDeCompraResource.Add(CarrinhoDeCompraMapper.ModelToResource(carrinhoDeCompra));
                    }
                }

                return(Ok(carrinhoDeCompraResource));
            }
            catch (Exception exception)
            {
                LogError.LogErrorWithSentry(exception);
                return(BadRequest());
            }
        }
Пример #2
0
        public async Task <IActionResult> Get(int id)
        {
            var carrinhoDeCompra = await _unitOfWork.CarrinhoDeCompras.GetByIdWithProdutosAsync(id);

            if (carrinhoDeCompra.IsAtivo)
            {
                return(Ok(CarrinhoDeCompraMapper.ModelToResource(carrinhoDeCompra)));
            }

            return(NoContent());
        }
Пример #3
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));
            }
        }