public ActionResult Save(PackingListVM model) { _userId = Convert.ToInt32(Session["UserID"]); _validationMsg = _dalLcmPackingList.Save(model, _userId, "PackingList/PackingList"); return(Json(_validationMsg, JsonRequestBehavior.AllowGet)); }
private LCM_PackingList ModelConversionPackingList(PackingListVM model, int userId, string url) { var entity = model.Plid == 0 ? new LCM_PackingList() : (from b in _context.LCM_PackingList.AsEnumerable() where b.PLID == model.Plid select b).FirstOrDefault(); entity.PLID = model.Plid; entity.PLNo = model.Plid == 0 ? DalCommon.GetPreDefineNextCodeByUrl(url) : model.PlNo; entity.PLDate = DalCommon.SetDate(model.PlDate); entity.LCID = model.Lcid; entity.LCNo = model.LcNo; entity.CIID = model.Ciid; entity.CINo = model.CiNo; entity.PLNetWeight = model.NetWeight; entity.NetWeightUnit = model.NetWeightUnit; entity.PLGrossWeight = model.GrossWeight; entity.GrossWeightUnit = model.GrossWeightUnit; entity.PLNote = model.PlNote; entity.RecordStatus = model.Plid == 0 ? "NCF" : model.RecordStatus; entity.SetOn = model.Plid == 0 ? DateTime.Now : _unit.PackingListRepository.GetByID(model.Plid).SetOn; entity.SetBy = model.Plid == 0 ? userId : _unit.PackingListRepository.GetByID(model.Plid).SetBy; entity.ModifiedBy = model.Plid == 0 ? (int?)null : userId; entity.ModifiedOn = model.Plid == 0 ? (DateTime?)null : DateTime.Now; return(entity); }
public PackingListVM GetPackingList() { var PackingList = new PackingListVM(); PackingList.Container = new TmpContainersController().GetCurrentContainer(); PackingList.Container.ContainerItems = PackingList.Container.ContainerItems.OrderBy(ci => ci.BuyerID).ToList(); PackingList.InvoiceItems = new InvoicesController().GetInvoices(PackingList.Container); return(PackingList); }
public ValidationMsg Save(PackingListVM model, int userId, string url) { try { using (var tx = new TransactionScope()) { using (_context) { var packingList = ModelConversionPackingList(model, userId, url); if (model.Plid == 0) { //_unit.PackingListRepository.Insert(packingList); _context.LCM_PackingList.Add(packingList); _context.SaveChanges(); _mode = 1; } else { //_unit.PackingListRepository.Update(packingList); _context.SaveChanges(); _mode = 2; } if (model.packingListItem != null) { foreach (var item in model.packingListItem) { var packingItemList = ModelConversionPackingListItem(item, userId, packingList.PLID); if (item.PlItemID == 0) { //_unit.PackingListItemRepository.Insert(packingItemList); _context.LCM_PackingListItem.Add(packingItemList); } else { //_unit.PackingListItemRepository.Update(packingItemList); //_context.SaveChanges(); } } _context.SaveChanges(); } if (model.packingListPacks != null) { foreach (var pack in model.packingListPacks) { var packList = ModelConversionPackingListPacks(pack, userId, packingList.PLID); if (pack.PlPackID == 0) { //_unit.PackingListPacksRepository.Insert(packList); _context.LCM_PackingListPacks.Add(packList); //_context.SaveChanges(); } else { //_unit.PackingListPacksRepository.Update(packList); //_context.SaveChanges(); } } _context.SaveChanges(); } tx.Complete(); if (_mode == 1) { _validationMsg.ReturnId = packingList.PLID; _validationMsg.ReturnCode = packingList.PLNo; _validationMsg.Type = Enums.MessageType.Success; _validationMsg.Msg = "Saved successfully"; } if (_mode == 2) { _validationMsg.ReturnId = packingList.PLID; _validationMsg.Type = Enums.MessageType.Update; _validationMsg.Msg = "Updated successfully"; } } } } catch (Exception e) { _validationMsg.Type = Enums.MessageType.Error; _validationMsg.Msg = "Failed to save"; } return(_validationMsg); }
public ActionResult GetPackingListById(int plid) { var packingList = _unit.PackingListRepository.GetByID(plid); var result = new PackingListVM { Plid = packingList.PLID, PlNo = packingList.PLNo, PlDate = string.Format("{0:dd/MM/yyyy}", packingList.PLDate), Lcid = packingList.LCID, LcNo = packingList.LCNo, Ciid = packingList.CIID, CiNo = packingList.CINo, NetWeight = packingList.PLNetWeight, NetWeightUnit = packingList.NetWeightUnit, GrossWeight = packingList.PLGrossWeight, GrossWeightUnit = packingList.GrossWeightUnit, PlNote = packingList.PLNote, RecordStatus = packingList.RecordStatus, packingListItem = new List <PackingListItemVM>(), packingListPacks = new List <PackingListPacksVM>() }; if (packingList.LCID != null) { result.LcDate = _unit.LCOpeningRepository.GetByID(packingList.LCID).LCDate.ToString("dd/MM/yyyy"); } if (packingList.CIID != null) { result.CiDate = string.Format("{0:dd/MM/yyyy}", _unit.CommercialInvoiceRepository.GetByID(packingList.CIID).CIDate); } var packingListItems = _unit.PackingListItemRepository.Get().Where(ob => ob.PLID == plid).ToList(); if (packingListItems.Count > 0) { foreach (var item in packingListItems) { var packingListItem = new PackingListItemVM(); packingListItem.PlItemID = item.PLItemID; packingListItem.Plid = item.PLID; packingListItem.ItemID = item.ItemID; if (item.ItemID != null) { packingListItem.ItemName = _unit.SysChemicalItemRepository.GetByID(item.ItemID).ItemName; packingListItem.HsCode = _unit.SysChemicalItemRepository.GetByID(item.ItemID).HSCode; } packingListItem.PackSize = item.PackSize; if (item.PackSize != null) { packingListItem.PackSizeName = _unit.SysSizeRepository.GetByID(item.PackSize).SizeName; } packingListItem.SizeUnit = item.SizeUnit; if (item.SizeUnit != null) { packingListItem.SizeUnitName = _unit.SysUnitRepository.GetByID(item.SizeUnit).UnitName; } packingListItem.PackQty = item.PackQty; packingListItem.PlQty = item.PLQty; packingListItem.PlUnit = item.PLUnit; if (item.PLUnit != null) { packingListItem.PlUnitName = _unit.SysUnitRepository.GetByID(item.PLUnit).UnitName; } packingListItem.SupplierID = item.SupplierID; if (item.SupplierID != null) { packingListItem.SupplierName = _unit.SysSupplierRepository.GetByID(item.SupplierID).SupplierName; } packingListItem.ManufacturerID = item.ManufacturerID; if (item.ManufacturerID != null) { packingListItem.ManufacturerName = _unit.SysSupplierRepository.GetByID(item.ManufacturerID).SupplierName; } result.packingListItem.Add(packingListItem); } } var packingListPacks = _unit.PackingListPacksRepository.Get().Where(ob => ob.PLID == plid).ToList(); if (packingListPacks.Count > 0) { foreach (var pack in packingListPacks) { var packingListPack = new PackingListPacksVM(); packingListPack.PlPackID = pack.PLPackID; packingListPack.Plid = pack.PLID; packingListPack.PackUnit = pack.PackUnit; if (pack.PackUnit != null) { packingListPack.PackUnitName = _unit.SysUnitRepository.GetByID(pack.PackUnit).UnitName; } packingListPack.PackQty = pack.PackQty; result.packingListPacks.Add(packingListPack); } } return(Json(result, JsonRequestBehavior.AllowGet)); }