Quantity Inventory Management

Asked

Viewed 329 times

0

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

Ex:

Estoque:
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 have that amount of items removed without I need to go straight to the Stock table and change manually

I tried looking for some examples, but found nothing

  • what is wrong?

  • have little information there, you want to update the table estoque? and return the amount of products purchased to the form that is loaded in your action? if so, use the Return View() that is commented to return the ViewModel with the fields updated to the View something like return View(compra), and in the View use razor to display, something like @Html.DisplayFor(), and before that consult the product in estoque for NomeProdutoId which I imagine is a foreign key to the product in stock, change the quantity by subtracting the quantity purchased and save.

  • I intend when I make the purchase of a specific product, it make the change in the quantity of the stock, where the quantity of the purchase table, go to the stock table only for that stock product, an example would be - if I bought 10 pencils and registered in the purchase form this amount of 10 pencils already goes into the stock records, without I have to change automatically

  • and what is your difficulty in doing this? could put the prints of the models.

  • What I want to do is this, I don’t have a very broad understanding of c#, I only know the basics and what I need to do is add the purchase amount in stock, as if I automatically do an update adding.

  • then you want to update the table estoque, you can already query and save data in the bank? this dao.Adiciona(compra); is adding the purchase in the BD table?

  • @Vinicius exactly, the complete crud I can do but I wanted when I registered a quantity in the table to buy the same value to be for the stock table

  • I’m not sure if the relationship between the purchase and stock tables is correct, you can consult the product that had the quantity changed in the table estoque? if yes, I see that can be the way to make the product query change the quantity and save (update) the registration in the BD, inside the purchase controller?

  • @Vinicius can not, to make the relationship right, I would have to pull the purchase to stock? And if so, if so, I wanted to kind of like when I was going to set a value for a product that he registers on that product and not create a duplicate

  • Only one addendum, you don’t need Else since the if block has a Return.

  • Are you following any tutorial? can you write in the bank? consult something in the bank, save something in the bank and etc? as you said above you can already do CRUD, so if you refer(select) in the table estoque for the desired product, and then update(Update) the same one will not create another, but update the fields in the database, assuming that you can already make a query in the database

  • @Vinicius yes I can do the select and then change it, the point is that I want to do it from another form, that when registering the data in a table that would be the Purchase, change the data of the stock table, the problem is that it does not change

  • that dao you use to write on the table compra right? would you be able to put all the controller code? including how do you declare this dao?

  • @Vinicius I can for yes

Show 9 more comments

1 answer

0

I don’t know about nhibernate but see if it helps you:

a tip would be you review the relationship of your tables, I see no need to have a foreign key for quantity and another for product name to purchase. You can have just the Id Stock product in table compra, Then when you made a purchase would only consult on estoque by the id of the product purchased.

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

create a method to update the data similar to the class compraDAo in estoqueDao, ai 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*/
estoqueDao.Update(produto);

I tried to do based on what you posted, the ideal would be a method in EstoqueDao looking for the product id, you wouldn’t need the Where. I hope it helps you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.