0
I have a job that closes a back door. Like any input process when registering the note I have the manual registration of each item of the note and when closing the note I need to update the stock of each item of this note.
I’ve done the following in my service:
public class EstoqueEntradaService : BaseService<SAR_ENTRADA>
{
public void FecharEntrada(SAR_ENTRADA model)
{
model.Status = 'F';
foreach (var item in model.Entradas)
{
var estoque = item.Material.Estoque.Where(m => m.Almoxarifado == item.Almoxarifado).SingleOrDefault();
if (estoque != null)
{
estoque.Quantidade += item.Quantidade;
}
else
{
item.Material.Estoque.Add(new Estoque()
{
Almoxarifado = item.Almoxarifado,
Material = item.Material,
Quantidade = item.Quantidade
});
}
item.Material.CustoMedio = (item.Material.CustoMedio + item.ValorUnitario) / 2;
item.Material.UltimoValorCompra = item.ValorUnitario;
item.Material.UltimaDataCompra = DateTime.Now;
item.Material.Fornecedor = model.Credor;
}
this.Edit(model);
}
}
In the process of closing the entry I change the status to closed and make a listing of each item of this entry updating the stock, if there is or inserting a new record in my stock for that product, by stockroom.
My question is: Should I keep this part of stock update within a service that refers to the entry and not the items of the stock or should in this entry service call the stock service in a method for example: Stock update, which receives the ID of the warehouse and material and then yes update the stock there?
Vlw!