I'm having a hard time making a method to check 2 lists. This method will receive a list that is the list that was added to the order and the purchase requisition ID to which that order was associated. The method calls another method that returns the list of items in the purchase requisition from the bank. So, at this point I have 2 lists: one received as a parameter with the items that are being added to the request, and another one that I searched the database for the requisition items.
I need to check if the items that are in the order are in the request, ie check if the items in the list that I received as a parameter are in the items in the list that came from the bank. If so, I need to check if this item has already been purchased (I have a Boolean property for this), and if it was not purchased I need to mark this property as true
and let this item pass to be registered.
I also need to check if these items do not have any items that were not requested in the purchase requisition, ie the buyer can not buy without a requisition for this item.
All items that should not be in the order, either because it was already purchased or because it was not ordered, should be removed by the system. After registering the request, I have to display the list of items that were removed by the system.
I know it got really big because it's a complex process but if anyone can help me with it, I tried it all day today, but there's always a loophole for errors.
Method Code
public ControlePedidoRCM ControlePedidoRCM(int IdRCM, List<MaterialPedido> IdMaterial)
{
RCMDal rd = new RCMDal();
ControlePedidoRCM Controle = new ViewModel.ControlePedidoRCM();
List<int> Comprados = new List<int>();
List<int> Fora = new List<int>();
List<MaterialRCM> itens = rd.ListarItens(IdRCM).ToList();
foreach(var item in itens)
{
for(int i = 0; i < IdMaterial.Count; i++)
{
//se o material estiver na lista de RCM
if(item.MaterialID == IdMaterial[i].MaterialID)
{
if(item.Comprado == true)
{
//ja foi comprado
Comprados.Add(item.MaterialID);
}
}
else
{
//não está na RCM
Fora.Add(item.MaterialID);
}
}
}
Controle.Comprado = Comprados;
Controle.Fora = Fora;
return Controle;
}