public async Task <IHttpActionResult> DeleteVenda(int id)
        {
            Venda venda = await db.Vendas.FindAsync(id);

            if (venda == null)
            {
                return(NotFound());
            }

            foreach (var item in venda.Itens)
            {
                if (item.MovimentoEstoque != null)
                {
                    estoqueService.RemoverMovimento(item.MovimentoEstoque);
                }
            }
            db.Vendas.Remove(venda);
            await db.SaveChangesAsync();

            return(Ok(venda));
        }
Example #2
0
        public async Task <IHttpActionResult> DeleteMovimentoEstoque(int id)
        {
            MovimentoEstoque movimentoEstoque = await db.MovimentosEstoque.FindAsync(id);

            if (movimentoEstoque == null)
            {
                return(NotFound());
            }

            try
            {
                service.RemoverMovimento(movimentoEstoque);
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError,
                                                                            "Esse movimento foi gerado por uma venda e não pode ser excluído."));
            }

            return(Ok(movimentoEstoque));
        }