Ejemplo n.º 1
0
        public FrayteResult SaveTradelaneShipmentTracking(TradelaneOperationslTrackingModel TM)
        {
            FrayteResult FR = new FrayteResult();

            FR.Status = false;
            var Result = dbContext.TradelaneShipmentTrackings.Where(a => a.TradelaneShipmentTrackingId == TM.TradelaneShipmentTrackingId).FirstOrDefault();

            if (Result != null)
            {
                Result.TradlaneShipmentId  = TM.TradelaneShipmentId;
                Result.TrackingDescription = TM.TrackingDescription;
                Result.TrackingCode        = TM.TrackingCode;
                Result.CreatedOnUtc        = TM.CreatedOnUtc;
                Result.FlightNumber        = TM.FlightNo;
                Result.CreatedBy           = TM.CreatedBy;
                Result.Weight                 = TM.Weight;
                Result.Pieces                 = TM.Pieces;
                Result.AirportCode            = TM.AirportCode;
                dbContext.Entry(Result).State = System.Data.Entity.EntityState.Modified;
                dbContext.SaveChanges();
                //if(Result.TrackingCode == "DLV")
                //{
                //    var res = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TM.TradelaneShipmentId).FirstOrDefault();
                //    if(res != null)
                //    {
                //        res.ShipmentStatusId = 35;
                //        dbContext.Entry(res).State = System.Data.Entity.EntityState.Modified;
                //        dbContext.SaveChanges();
                //    }
                //}

                FR.Status = true;
            }
            else
            {
                TradelaneShipmentTracking TlST = new TradelaneShipmentTracking();
                TlST.TradlaneShipmentId  = TM.TradelaneShipmentId;
                TlST.TrackingDescription = TM.TrackingDescription;
                TlST.TrackingCode        = TM.TrackingCode;
                TlST.FlightNumber        = TM.FlightNo;
                TlST.CreatedOnUtc        = DateTime.UtcNow;
                TlST.CreatedBy           = TM.CreatedBy;
                TlST.AirportCode         = TM.AirportCode;
                TlST.Weight = TM.Weight;
                TlST.Pieces = TM.Pieces;
                dbContext.TradelaneShipmentTrackings.Add(TlST);
                dbContext.SaveChanges();
                if (TM.TrackingCode == "DEP")
                {
                    var res = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TM.TradelaneShipmentId).FirstOrDefault();
                    if (res != null)
                    {
                        res.ShipmentStatusId = 30;
                        //res.ShipmentStatusId = 31;
                        res.IsMawbCorrection       = false;
                        dbContext.Entry(res).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                    }
                }
                if (TM.TrackingCode == "INT")
                {
                    var res = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TM.TradelaneShipmentId).FirstOrDefault();
                    if (res != null)
                    {
                        res.ShipmentStatusId       = 31;
                        res.IsMawbCorrection       = false;
                        dbContext.Entry(res).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                    }
                }
                if (TM.TrackingCode == "ARV")
                {
                    var res = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TM.TradelaneShipmentId).FirstOrDefault();
                    if (res != null)
                    {
                        res.ShipmentStatusId = 32;
                        //res.ShipmentStatusId = 31;
                        res.IsMawbCorrection       = false;
                        dbContext.Entry(res).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                    }
                }
                if (TM.TrackingCode == "DLV")
                {
                    var res = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TM.TradelaneShipmentId).FirstOrDefault();
                    if (res != null)
                    {
                        res.ShipmentStatusId       = 35;
                        res.IsMawbCorrection       = false;
                        dbContext.Entry(res).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                    }

                    // Update Express AWB status if status is delivered

                    new ExpressManifestRepository().UpdateExpressAWbStatus(TM.TradelaneShipmentId);
                }
                FR.Status = true;
                //send mail of add tracking
                if (FR.Status)
                {
                    var Res = new TradelaneEmailRepository().SendUpdateTrackingEmail(TM);
                    if (Res.Status == false)
                    {
                        //FR.Errors = new List<string>();
                        //FR.Errors.Add("Email does not exist for this Operational Status in tracking configuration");
                        //DeleteTradelaneOperationalTracking(TlST.TradelaneShipmentTrackingId);
                    }
                }
            }
            return(FR);
        }
Ejemplo n.º 2
0
        public TradelaneTrackingModel GetTradelaneShipmentTracking(int TradelaneShipmentId)
        {
            TradelaneTrackingModel TTM = new TradelaneTrackingModel();

            TTM.TradelaneOperationalDetail = new List <TradelaneOperationslTrackingModel>();
            TTM.ShipmentDetail             = new TradelanePublicDetail();
            TTM.TradelaneStatus            = new List <TradelaneTrackingShipmentStatus>();
            try
            {
                TTM.TradelaneStatus = GetShipmentTrackingStatus(TradelaneShipmentId);

                var TB = new TradelaneBookingRepository().GetTradelaneBookingDetails(TradelaneShipmentId, "TradelaneShipmentBooking");

                var Res = dbContext.TradelaneShipmentDetails.Where(a => a.TradelaneShipmentId == TradelaneShipmentId).ToList();
                //var ShipmentDetail = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TradelaneShipmentId).FirstOrDefault();
                if (TB != null)
                {
                    TTM.ShipmentDetail.CurrentStatus          = dbContext.ShipmentStatus.Where(a => a.ShipmentStatusId == TB.ShipmentStatusId).FirstOrDefault().DisplayStatusName;
                    TTM.ShipmentDetail.DepartureAirportCode   = TB.DepartureAirport.AirportCode;
                    TTM.ShipmentDetail.DestinationAirportCode = TB.DestinationAirport.AirportCode;
                    TTM.ShipmentDetail.EstimatedWeight        = Res.Sum(a => a.Weight);
                    TTM.ShipmentDetail.FrayteNumber           = TB.FrayteNumber;
                    TTM.ShipmentDetail.Mawb        = TB.AirlinePreference.AilineCode + " " + TB.MAWB.Substring(0, 4) + " " + TB.MAWB.Substring(4, 4) ?? "";
                    TTM.ShipmentDetail.TotalPieces = Res.Count;
                    TTM.ShipmentDetail.TotalVolume = TB.PakageCalculatonType == FraytePakageCalculationType.kgtoCms ? Math.Round((Res.Sum(p => p.Length * p.Weight * p.Height)) / (100 * 100 * 100), 2) : Math.Round((Res.Sum(p => p.Length * p.Weight * p.Height)) / (39.37M * 39.37M * 39.37M), 2);
                }

                var Result = dbContext.TradelaneShipmentTrackings.Where(a => a.TradlaneShipmentId == TradelaneShipmentId).ToList();

                if (Result != null && Result.Count > 0)
                {
                    foreach (var TM in Result)
                    {
                        TradelaneOperationslTrackingModel TlST = new TradelaneOperationslTrackingModel();
                        TlST.TradelaneShipmentTrackingId = TM.TradelaneShipmentTrackingId;
                        TlST.TradelaneShipmentId         = TM.TradlaneShipmentId;
                        TlST.Weight = TM.Weight != null ? TM.Weight.Value : 0;
                        TlST.Pieces = TM.Pieces != null ? TM.Pieces.Value : 0;
                        TlST.TrackingDescription = TM.TrackingDescription;
                        TlST.FlightNo            = TM.FlightNumber;
                        TlST.TrackingCode        = TM.TrackingCode;
                        TlST.CreatedOnUtc        = TM.CreatedOnUtc;
                        TlST.CreatedBy           = TM.CreatedBy;
                        TlST.AirportCode         = TM.AirportCode;
                        TTM.TradelaneOperationalDetail.Add(TlST);
                    }
                }
                else
                {
                }

                TTM.TradelaneTrackingDetail = new List <TradelaneUpdateTrackingModel>();

                TTM.TradelaneTrackingDetail = (from TS in dbContext.TradelaneFlightDetails
                                               where TS.TradelaneShipmentId == TradelaneShipmentId
                                               select new TradelaneUpdateTrackingModel
                {
                    TradelaneFlightId = TS.TradelaneFlightDetailId,
                    TradelaneShipmentId = TS.TradelaneShipmentId.Value,
                    FlightNo = TS.FlightNumber != null ? TS.FlightNumber : "",
                    DepartureDate = TS.DepartureDate,
                    DepartureTime = TS.DepartureDate != null ? TS.DepartureDate.Value.ToString() : "",
                    ArrivalDate = TS.ArrivalDate.Value,
                    ArrivalTime = TS.ArrivalDate != null ? TS.ArrivalDate.Value.ToString() : "",
                    BookingStatus = TS.BookingStatus,
                    DepartureAirportCode = TS.DepartureAirportCode,
                    DestinationAirportCode = TS.ArrivalAirportCode,
                    TotalPeices = TS.Pieces.Value,
                    TotalWeight = TS.TotalWeight.Value,
                    Volume = TS.TotalVolume.Value
                }).ToList();

                var Shipment = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TradelaneShipmentId).FirstOrDefault();
                if (Shipment != null)
                {
                    var          user     = dbContext.Users.Where(a => a.UserId == Shipment.CustomerId).FirstOrDefault();
                    var          Timezone = dbContext.Timezones.Where(a => a.TimezoneId == user.TimezoneId).FirstOrDefault();
                    TimeZoneInfo TZM      = TimeZoneInfo.FindSystemTimeZoneById(Timezone.Name);

                    for (int i = 0; i < TTM.TradelaneTrackingDetail.Count; i++)
                    {
                        if (TTM.TradelaneTrackingDetail[i].DepartureDate != null)
                        {
                            TTM.TradelaneTrackingDetail[i].DepartureTime = UtilityRepository.UtcDateToOtherTimezone(TTM.TradelaneTrackingDetail[i].DepartureDate.Value, TTM.TradelaneTrackingDetail[i].DepartureDate.Value.TimeOfDay, TZM).Item2;
                            TTM.TradelaneTrackingDetail[i].DepartureDate = UtilityRepository.UtcDateToOtherTimezone(TTM.TradelaneTrackingDetail[i].DepartureDate.Value, TTM.TradelaneTrackingDetail[i].DepartureDate.Value.TimeOfDay, TZM).Item1;
                        }
                        if (TTM.TradelaneTrackingDetail[i].ArrivalDate != null)
                        {
                            TTM.TradelaneTrackingDetail[i].ArrivalTime = UtilityRepository.UtcDateToOtherTimezone(TTM.TradelaneTrackingDetail[i].ArrivalDate.Value, TTM.TradelaneTrackingDetail[i].ArrivalDate.Value.TimeOfDay, TZM).Item2;
                            TTM.TradelaneTrackingDetail[i].ArrivalDate = UtilityRepository.UtcDateToOtherTimezone(TTM.TradelaneTrackingDetail[i].ArrivalDate.Value, TTM.TradelaneTrackingDetail[i].ArrivalDate.Value.TimeOfDay, TZM).Item1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(TTM);
        }
        public IHttpActionResult SaveTradelaneShipmentOperationalTracking(TradelaneOperationslTrackingModel TrackingList)
        {
            var res = new UpdateTradelaneTrackingRepository().SaveTradelaneShipmentTracking(TrackingList);

            return(Ok(res));
        }