Esempio n. 1
0
 public ValidationMsg Save(ExpBillOfLading model, int userId)
 {
     try
     {
         using (var tx = new TransactionScope())
         {
             using (_context)
             {
                 var bol = ConvertBol(model, userId);
                 if (model.BLID == 0)
                 {
                     _context.EXP_BillofLading.Add(bol);
                     _context.SaveChanges();
                     _mode = 1;
                 }
                 else
                 {
                     _context.SaveChanges();
                     _mode = 2;
                 }
                 if (model.Container != null)
                 {
                     foreach (var cont in model.Container)
                     {
                         var bolc = ConvertBolc(cont, bol.BLID, userId);
                         if (cont.BLCcntID == 0)
                         {
                             _context.EXP_BillofLadingContainer.Add(bolc);
                             _context.SaveChanges();
                         }
                         else
                         {
                             _context.SaveChanges();
                         }
                     }
                 }
                 tx.Complete();
                 if (_mode == 1)
                 {
                     _msg.ReturnId   = bol.BLID;
                     _msg.ReturnCode = bol.BLNo;
                     _msg.Type       = Enums.MessageType.Success;
                     _msg.Msg        = "Saved successfully.";
                 }
                 if (_mode == 2)
                 {
                     _msg.Type = Enums.MessageType.Update;
                     _msg.Msg  = "Updated successfully.";
                 }
             }
         }
     }
     catch (Exception)
     {
         _msg.Type = Enums.MessageType.Error;
         _msg.Msg  = "Failed to save.";
     }
     return(_msg);
 }
Esempio n. 2
0
        private EXP_BillofLading ConvertBol(ExpBillOfLading model, int userId)
        {
            var entity = model.BLID == 0
                ? new EXP_BillofLading()
                : (from b in _context.EXP_BillofLading.AsEnumerable()
                   where b.BLID == model.BLID
                   select b).FirstOrDefault();

            entity.BLID    = model.BLID;
            entity.BLNo    = model.BLNo ?? BillNoGenerate();
            entity.RefBLNo = model.RefBLNo;
            entity.BLDate  = model.BLDate == null ? DateTime.Now : DalCommon.SetDate(model.BLDate);
            entity.CIID    = model.CIID;
            //entity.PLID = model.PLID;
            entity.ShippedOnBoardDate = model.ShippedOnBoardDate == null
                ? DateTime.Now
                : DalCommon.SetDate(model.ShippedOnBoardDate);
            entity.ExpectedArrivalTime = model.ExpectedArrivalTime == null
                ? DateTime.Now
                : 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.RecordStatus      = model.BLID == 0
                ? "NCF"
                : _context.EXP_BillofLading.FirstOrDefault(ob => ob.BLID == model.BLID).RecordStatus;
            entity.SetBy = model.BLID == 0
                ? userId
                : _context.EXP_BillofLading.FirstOrDefault(ob => ob.BLID == model.BLID).SetBy;
            entity.SetOn = model.BLID == 0
                ? DateTime.Now
                : _context.EXP_BillofLading.FirstOrDefault(ob => ob.BLID == model.BLID).SetOn;
            entity.ModifiedBy = model.BLID == 0 ? (int?)null : userId;
            entity.ModifiedOn = model.BLID == 0 ? (DateTime?)null : DateTime.Now;
            return(entity);
        }
Esempio n. 3
0
 public ActionResult Save(ExpBillOfLading model)
 {
     _userId        = Convert.ToInt32(Session["UserID"]);
     _validationMsg = _dalExpBillOfLading.Save(model, _userId);
     return(Json(_validationMsg, JsonRequestBehavior.AllowGet));
 }