public ValidationMsg Save(LcmBillOfLadingVM model, int userId, string url) { try { using (var tx = new TransactionScope()) { using (_context) { var billOfLading = BillOfLadingModelConverter(model, userId, url); if (model.Blid == 0) { _context.LCM_BillofLading.Add(billOfLading); _context.SaveChanges(); _mode = 1; } else { _context.SaveChanges(); _mode = 2; } if (model.Containers != null) { foreach (var container in model.Containers) { var billOfLadingContainer = BillOfLadingContainerModelConverter(container, userId, billOfLading.BLID); if (container.BlcCntId == 0) { _context.LCM_BillofLadingContainer.Add(billOfLadingContainer); _context.SaveChanges(); } else { _context.SaveChanges(); } } } tx.Complete(); if (_mode == 1) { _validationMsg.ReturnId = billOfLading.BLID; _validationMsg.ReturnCode = billOfLading.BLNo; _validationMsg.Type = Enums.MessageType.Success; _validationMsg.Msg = "Saved successfully"; } if (_mode == 2) { _validationMsg.Type = Enums.MessageType.Update; _validationMsg.Msg = "Updated successfully"; } } } } catch { _validationMsg.Type = Enums.MessageType.Error; _validationMsg.Msg = "Failed to save"; } return(_validationMsg); }
public ActionResult Save(LcmBillOfLadingVM model) { _userId = Convert.ToInt32(Session["UserID"]); _validationMsg = _dalLcmBillOfLading.Save(model, _userId, "BillOfLading/BillOfLading"); return(Json(_validationMsg, JsonRequestBehavior.AllowGet)); }
private LCM_BillofLading BillOfLadingModelConverter(LcmBillOfLadingVM model, int userId, string url) { var entity = model.Blid == 0 ? new LCM_BillofLading() : (from b in _context.LCM_BillofLading.AsEnumerable() where b.BLID == model.Blid select b).FirstOrDefault(); entity.BLID = model.Blid; entity.BLNo = model.BlNo; entity.BLDate = DalCommon.SetDate(model.BlDate); entity.CIID = model.CIID; entity.CINo = model.CINo; entity.LCID = model.Lcid; entity.LCNo = model.LcNo; entity.ShippedOnBoardDate = DalCommon.SetDate(model.ShippedOnBoardDate); entity.ExpectedArrivalTime = DalCommon.SetDate(model.ExpectedArrivalTime); entity.Shipper = model.Shipper; entity.ShipmentMode = model.ShipmentMode; entity.VesselName = model.VesselName; entity.VoyageNo = model.VoyageNo; entity.TransShipmentPort = model.TransShipmentPort; entity.ShipmentPort = model.ShipmentPort; entity.BLNote = model.BlNote; if (model.Blid == 0) { entity.RecordStatus = "NCF"; entity.SetBy = userId; entity.SetOn = DateTime.Now; } else { entity.ModifiedBy = userId; entity.ModifiedOn = DateTime.Now; } return(entity); }
public ActionResult GetBillOfLadingById(int blid) { var blEntity = _unit.BillOfLadingRepository.GetByID(blid); var blModel = new LcmBillOfLadingVM(); blModel.Blid = blEntity.BLID; blModel.BlNo = blEntity.BLNo; blModel.BlDate = string.Format("{0:dd/MM/yyyy}", blEntity.BLDate); blModel.Lcid = blEntity.LCID; blModel.LcNo = blEntity.LCNo; blModel.CIID = blEntity.CIID; blModel.CINo = blEntity.CINo; blModel.ShippedOnBoardDate = string.Format("{0:dd/MM/yyyy}", blEntity.ShippedOnBoardDate); blModel.ExpectedArrivalTime = string.Format("{0:dd/MM/yyyy}", blEntity.ExpectedArrivalTime); blModel.Shipper = blEntity.Shipper; blModel.ShipmentMode = blEntity.ShipmentMode; blModel.VesselName = blEntity.VesselName; blModel.VoyageNo = blEntity.VoyageNo; blModel.TransShipmentPort = blEntity.TransShipmentPort; blModel.ShipmentPort = blEntity.ShipmentPort; blModel.RecordStatus = blEntity.RecordStatus; blModel.Containers = new List <LcmBillOfLadingContainerVM>(); if (blEntity.LCID != null) { blModel.PiNo = _unit.LCOpeningRepository.GetByID(blEntity.LCID).PINo; } if (blEntity.Shipper != null) { blModel.ShipperName = _unit.SysBuyerRepository.GetByID(blEntity.Shipper).BuyerName; } if (blEntity.TransShipmentPort != null) { blModel.TransShipmentPortName = _unit.SysPortRepository.GetByID(blEntity.TransShipmentPort).PortName; } if (blEntity.ShipmentPort != null) { blModel.ShipmentPortName = _unit.SysPortRepository.GetByID(blEntity.ShipmentPort).PortName; } var blcEntity = _unit.BillOfLadingContainerRepository.Get().Where(ob => ob.BLID == blid).ToList(); foreach (var entity in blcEntity) { var blcModel = new LcmBillOfLadingContainerVM(); blcModel.BlcCntId = entity.BLCcntID; blcModel.Blid = entity.BLID; blcModel.ContainerNo = entity.ContainerNo; blcModel.ContainerType = entity.ContainerType; blcModel.SealNo = entity.SealNo; blcModel.PackageQty = entity.PackageQty; blcModel.GrossWeight = entity.GrossWeight; blcModel.WeightUnit = entity.WeightUnit; if (entity.WeightUnit != null) { blcModel.WeightUnitName = _unit.SysUnitRepository.GetByID(entity.WeightUnit).UnitName; } blModel.Containers.Add(blcModel); } return(Json(blModel, JsonRequestBehavior.AllowGet)); }