private void SaveShipment() { try { string boxstring = cbbBoxId.Text.Trim(); int count = 0; BoxInforEntity boxEntity = _boxInforServices.GetByBoxId(cbbBoxId.Text.Trim()); if (boxEntity == null) { boxEntity = new BoxInforEntity(); boxEntity.BoxId = boxstring; boxEntity.DateCreated = DateTime.Now; boxEntity.EmployeeId = currentEmployee.Id; boxEntity.ShipmentQuantity = 0; //manifestList.Where(t => t.BoxID == boxstring).Count(); boxEntity.MasterBillId = currentMasterBillId; currentBoxIdInt = _boxInforServices.CreateBoxInfor(boxEntity); boxEntity.Id = currentBoxIdInt; currentBoxId = boxEntity.BoxId; } else { currentBoxIdInt = boxEntity.Id; currentBoxId = boxEntity.BoxId; } if (_repositoryShipment.ShipmentExistByBoxId(boxEntity.Id)) { return; } List <ManifestEntity> listManifest = new List <ManifestEntity>(); listManifest = _repositoryShipment.GetManifestByBoxId(boxstring); listManifest = listManifest.GroupBy(t => t.ShipmentNo).Select(p => p.First()).ToList(); if (listManifest != null && listManifest.Count > 0) { List <ShipmentEntity> listShipment = new List <ShipmentEntity>(); foreach (var item in listManifest) { if (_repositoryShipment.ShipmentExist(item.ShipmentNo)) { continue; } ShipmentEntity shipment = new ShipmentEntity(); shipment.Mawb = item.MasterAirWayBill; shipment.ShipmentId = item.ShipmentNo; shipment.BoxId = currentBoxIdInt; shipment.DateCreated = DateTime.Now; shipment.EmployeeId = currentEmployee.Id; shipment.WarehouseId = FormLogin.mWarehouse.Id; shipment.Address = item.Address; shipment.BoxIdString = item.BoxID; shipment.Content = item.Content; shipment.Country = item.Country; shipment.DeclarationNo = item.DeclarationNo; shipment.Destination = item.Destination; shipment.NumberPackage = 1; shipment.Sender = item.CompanyName; shipment.Consignee = item.Destination; shipment.Receiver = item.ContactName; shipment.Weight = Math.Round(item.Weight, 3); shipment.ReceiverTel = item.Tel; listShipment.Add(shipment); } count += _shipmentServices.CreateOrUpdate(listShipment); } MessageBox.Show("Đã lưu xác nhận đến thành công!\nTổng số đơn hàng là " + count, "Lưu xác nhận đến", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { } }