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); }
public List <shipmentHistory> getLastTwoShipment(int customerId, string state) { var list = new List <shipmentHistory>(); shipmentHistory shipment_h; try { using (var ctx = new transshipEntities()) { var query = (from s in ctx.shipments join st in ctx.service_types on s.service_typeId equals st.service_typeId where s.customerId == customerId && s.state == state && s.status == "D" select new { shipmentId = s.shipmentId, customerId = s.customerId, serviceTypeId = s.service_typeId, purcharse_order = s.purcharse_order, consignee_name = s.consignee_name, shipment_date = s.shipment_date, description = st.descripcion, state = s.state, status = s.status }).OrderByDescending(x => x.shipment_date).Take(2).ToList(); foreach (var p in query) { shipment_h = new shipmentHistory(); shipment_h.shipmentId = p.shipmentId; shipment_h.customerId = p.customerId; shipment_h.serviceTypeId = p.serviceTypeId; shipment_h.purcharse_order = p.purcharse_order; shipment_h.consignee_name = p.consignee_name; shipment_h.shipment_date = p.shipment_date; shipment_h.description = p.description; shipment_h.state = p.state; shipment_h.status = p.status; list.Add(shipment_h); } return(list); } } catch (Exception e) { LogBook.TextLog.Info(string.Format("{0} {1}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty)); throw e; } }