Stock quantity management


Personal I'm trying to do a stock control, my idea is when I consume a product it changes in the table.


Produto / Quant
Caneta /5
Papel / 10
Lapis / 20

But when I separate these items for some segments in the company

Segmento | Produto | Quant
RH       | Caneta  | 1
TI       | Caneta  | 2
Vendas   | Lapis   | 5

And then the stock table has this amount of items taken out without me needing to go straight into the Stock table and manually change

I tried searching for some examples, but I did not find anything

asked by anonymous 28.09.2017 / 21:37

1 answer


I do not understand nHibernate but see if it helps:

One tip would be for you to review the relationship of your tables, I see no need to have a foreign key for quantity and another for the name of the product in purchase. You can only have the Id of the product of the inventory in the compra table, then when you make a purchase it would only query on estoque for the id of the purchased product.

Another thing: I noticed that your estoqueDAO does not have a method to update data similar to public void Update(Compra compra) of purchase. So you can not update inventory table data, just create new ones with public void Adiciona(Estoque estoque) .

Create a method to update data similar to that of class compraDAo in estoqueDao , then you can do the following during your purchase logic:

/*Aqui voce pega uma lista de todos produtos*/
var listaDeProdutos = estoqueDao.Lista();

/*Aqui voce pega apenas o produto que está sendo tratado em compra*/
var produto = listaDeProdutos.Where(p => p.Produto == compra.NomeProduto);

/*Aqui voce altera a quantidade*/
produto.Quantidade -= compra.Quant;

/*Aqui atualiza o registro no banco com a nova quantidade*/

I tried to do based on what you posted, ideally it would be a EstoqueDao method that searches for the product id, then it would not need Where . I hope this helps you.

02.10.2017 / 19:53