Dependence on services

0

I have a service that closes an entry in stock. Like all entry process to register the note I have the manual register of each item of the note and when closing the note I need to update the inventory of each item of this note.

I've done the following method 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 I make a list of each item of this entry updating the stock, if it exists or inserting a new record in my stock for that product, by warehouse.

My question is: Should I keep this inventory update part within a service that refers to the input and not the inventory items or should I in that input service call the inventory service in a method for example: UpdateStack, which receives the ID of the warehouse and the material and then yes update the inventory there?

Vlw!

    
asked by anonymous 20.08.2014 / 22:34

1 answer

0

I think the idea of having another service update inventory can unnecessarily complicate the solution, unless the new AtualizaEstoque method is used by other parts of your code, then the separation is pertinent.

    
20.08.2014 / 22:38