private static string validateShipment(OrderShipmentLine model) { decimal totalQty = model.ThisShipQuantity; OrderDetailModel orderDetail = OrderHelper.GetSingleOrderDetail(model.LineId); List <Shipment> shiped = new List <Shipment>(); if (model.Id > 0) { shiped = service.GetAllByLineId(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, model.LineId) .Where(rec => rec.Id < model.Id).ToList(); } else { shiped = service.GetAllByLineId(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, model.LineId).ToList(); } if (shiped != null && shiped.Count() > 0) { totalQty += shiped.Sum(rec => rec.Quantity); } if (totalQty > orderDetail.Quantity) { return("Quantity is exceeding than order!"); } string lotAndSerialValidation = checkLotandSerials(model); if (!string.IsNullOrEmpty(lotAndSerialValidation)) { return(lotAndSerialValidation); } //Other validations if any.. OrderShipmentModel orderShipment = SessionHelper.Shipment; if (model.Id > 0) { orderShipment.OrderShipments.First(x => x.LineId == model.LineId).BalanceQuantity = orderDetail.Quantity - (shiped.Sum(rec => rec.Quantity) + model.ThisShipQuantity); orderShipment.OrderShipments.First(x => x.LineId == model.LineId).Id = model.Id; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).LocatorId = model.LocatorId; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).LotNoId = model.LotNoId; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).OrderQuantity = orderDetail.Quantity; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).SerialNo = model.SerialNo; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).ShipedQuantity = shiped.Sum(rec => rec.Quantity); orderShipment.OrderShipments.First(x => x.LineId == model.LineId).ThisShipQuantity = model.ThisShipQuantity; } else { if (orderShipment.OrderShipments.Any(x => x.LineId == model.LineId)) { orderShipment.OrderShipments.First(x => x.LineId == model.LineId).BalanceQuantity = orderDetail.Quantity - (shiped.Sum(rec => rec.Quantity) + model.ThisShipQuantity); orderShipment.OrderShipments.First(x => x.LineId == model.LineId).Id = model.Id; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).LocatorId = model.LocatorId; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).LotNoId = model.LotNoId; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).OrderQuantity = orderDetail.Quantity; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).SerialNo = model.SerialNo; orderShipment.OrderShipments.First(x => x.LineId == model.LineId).ShipedQuantity = shiped.Sum(rec => rec.Quantity); orderShipment.OrderShipments.First(x => x.LineId == model.LineId).ThisShipQuantity = model.ThisShipQuantity; } else { //Never be in this case.. orderShipment.OrderShipments.Add(new OrderShipmentLine { BalanceQuantity = orderDetail.Quantity - (shiped.Sum(rec => rec.Quantity) + model.ThisShipQuantity), Id = model.Id, ItemName = model.ItemName, LineId = model.LineId, LocatorId = model.LocatorId, LotNoId = model.LotNoId, OrderQuantity = orderDetail.Quantity, SerialNo = model.SerialNo, ShipedQuantity = shiped.Sum(rec => rec.Quantity), ThisShipQuantity = model.ThisShipQuantity }); } } return(""); }