public List <shipmentHistory> getLastTwoShipment(int customerId, string state) { var history = new List <shipmentHistory>(); List <ShipServiceCost> shipServ = new List <ShipServiceCost>(); List <ShipCosts> shipCost = new List <ShipCosts>(); decimal totalS = 0; decimal?totalC = 0; decimal?total; int c = 0; shipmentHistory shipH = new shipmentHistory(); history = shipment.getLastTwoShipment(customerId, state); foreach (var i in history) { shipServ = approve.getCostsServicesByShipmentId(Convert.ToInt32(i.shipmentId)); foreach (var ss in shipServ) { totalS = totalS + ss.totalServices; } shipCost = approve.getCostsByShipmentId(Convert.ToInt32(i.shipmentId)); foreach (var sc in shipCost) { totalC = totalC + sc.totalCosts; } total = totalC + totalS; history[c].total = Convert.ToDecimal(total); c++; totalC = 0; totalS = 0; } //for (int i = 0; i < shipServ.Count; i++) { // history[i].total = shipServ[i].totalServices; //} return(history); }