public FrayteResult SaveTradelaneTracking(TradelaneUpdateTrackingModel TM) { var Shipment = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TM.TradelaneShipmentId).FirstOrDefault(); var user = dbContext.Users.Where(a => a.UserId == Shipment.CustomerId).FirstOrDefault(); FrayteResult FR = new FrayteResult(); FR.Status = false; var Result = dbContext.TradelaneFlightDetails.Where(a => a.TradelaneFlightDetailId == TM.TradelaneFlightId).FirstOrDefault(); if (Result != null) { Result.TradelaneShipmentId = TM.TradelaneShipmentId; Result.FlightNumber = TM.FlightNo; Result.ArrivalAirportCode = TM.DestinationAirportCode; Result.DepartureAirportCode = TM.DepartureAirportCode; var Timezone = dbContext.Timezones.Where(a => a.TimezoneId == user.TimezoneId).FirstOrDefault(); TimeZoneModal TZM = new TimeZoneModal(); if (Timezone != null) { TZM.TimezoneId = Timezone.TimezoneId; TZM.Name = Timezone.Name; } Result.ArrivalDate = UtilityRepository.ConvertToUniversalTimeWitDate(TM.ArrivalTime, TM.ArrivalDate.Value, TZM); Result.DepartureDate = UtilityRepository.ConvertToUniversalTimeWitDate(TM.DepartureTime, TM.DepartureDate.Value, TZM); Result.BookingStatus = TM.BookingStatus; Result.Pieces = TM.TotalPeices; Result.TotalVolume = TM.Volume; Result.TotalWeight = TM.TotalWeight; dbContext.Entry(Result).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); FR.Status = true; } else { TradelaneFlightDetail TlST = new TradelaneFlightDetail(); TlST.TradelaneShipmentId = TM.TradelaneShipmentId; TlST.FlightNumber = TM.FlightNo; TlST.ArrivalAirportCode = TM.DestinationAirportCode; TlST.DepartureAirportCode = TM.DepartureAirportCode; var Timezone = dbContext.Timezones.Where(a => a.TimezoneId == user.TimezoneId).FirstOrDefault(); TimeZoneModal TZM = new TimeZoneModal(); if (Timezone != null) { TZM.TimezoneId = Timezone.TimezoneId; TZM.Name = Timezone.Name; } TlST.ArrivalDate = UtilityRepository.ConvertToUniversalTimeWitDate(TM.ArrivalTime, TM.ArrivalDate.Value, TZM); TlST.DepartureDate = UtilityRepository.ConvertToUniversalTimeWitDate(TM.DepartureTime, TM.DepartureDate.Value, TZM); TlST.BookingStatus = TM.BookingStatus; TlST.Pieces = TM.TotalPeices; TlST.TotalVolume = TM.Volume; TlST.TotalWeight = TM.TotalWeight; dbContext.TradelaneFlightDetails.Add(TlST); dbContext.SaveChanges(); FR.Status = true; } return(FR); }
public FratyteError SaveMawbAllocation(List <MawbAllocationModel> MAList, string FilePath, string ShipmentType) { FratyteError MAM = new FratyteError(); var TradelaneId = MAList.FirstOrDefault().TradelaneId; if (MAList.Count > 0) { var Result = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == TradelaneId).FirstOrDefault(); if (Result != null) { Result.MAWBAgentId = MAList.FirstOrDefault().AgentId; Result.MAWB = MAList.FirstOrDefault().MAWB; dbContext.Entry(Result).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); if (!string.IsNullOrEmpty(Result.MAWB)) { new TradelaneBookingRepository().SaveTradelaneMawb(Result.MAWB, Result.TradelaneShipmentId); } foreach (var MAAllocation in MAList) { var Timezone = dbContext.Timezones.Where(a => a.TimezoneId == MAAllocation.TimezoneId).FirstOrDefault(); TimeZoneModal TZM = new TimeZoneModal(); if (Timezone != null) { TZM.TimezoneId = Timezone.TimezoneId; TZM.Name = Timezone.Name; } var Res = dbContext.TradelaneShipmentAllocations.Where(a => a.TradelaneShipmentAllocationId == MAAllocation.MawbAllocationId).FirstOrDefault(); if (Res != null) { Res.TradelaneShipmentId = MAAllocation.TradelaneId; Res.AgentId = MAAllocation.AgentId; Res.AirlineId = MAAllocation.AirlineId; Res.TimezoneId = MAAllocation.TimezoneId; Res.CreatedBy = MAAllocation.CreatedBy; Res.EstimatedDateofArrival = MAAllocation.ETA != null && MAAllocation.ETA.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(MAAllocation.ETATime, MAAllocation.ETA.Value, TZM) : (DateTime?)null; Res.EstimatedDateofDelivery = MAAllocation.ETD != null && MAAllocation.ETD.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(MAAllocation.ETDTime, MAAllocation.ETD.Value, TZM) : (DateTime?)null; Res.FlightNumber = MAAllocation.FlightNumber; Res.LegNum = MAAllocation.LegNum; Res.MAWB = MAAllocation.MAWB; dbContext.Entry(Res).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); if (Res.TradelaneShipmentId > 0 && !string.IsNullOrEmpty(Res.MAWB)) { new TradelaneBookingRepository().SaveTradelaneMawb(Res.MAWB, (int)Res.TradelaneShipmentId); } } else { TradelaneShipmentAllocation TSA = new TradelaneShipmentAllocation(); TSA.TradelaneShipmentId = MAAllocation.TradelaneId; TSA.AgentId = MAAllocation.AgentId; TSA.AirlineId = MAAllocation.AirlineId; TSA.TimezoneId = MAAllocation.TimezoneId; TSA.CreatedBy = MAAllocation.CreatedBy; TSA.CreatedOnUTC = DateTime.UtcNow; TSA.EstimatedDateofArrival = MAAllocation.ETA != null && MAAllocation.ETA.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(MAAllocation.ETATime, MAAllocation.ETA.Value, TZM) : (DateTime?)null; TSA.EstimatedDateofDelivery = MAAllocation.ETD != null && MAAllocation.ETD.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(MAAllocation.ETDTime, MAAllocation.ETD.Value, TZM) : (DateTime?)null; TSA.FlightNumber = MAAllocation.FlightNumber; TSA.LegNum = MAAllocation.LegNum; TSA.MAWB = MAAllocation.MAWB; dbContext.TradelaneShipmentAllocations.Add(TSA); dbContext.SaveChanges(); if (TSA.TradelaneShipmentId > 0 && !string.IsNullOrEmpty(TSA.MAWB)) { new TradelaneBookingRepository().SaveTradelaneMawb(TSA.MAWB, (int)TSA.TradelaneShipmentId); } } } MAM.Status = true; } else { TradelaneShipment result = new TradelaneShipment(); result.MAWBAgentId = MAList.FirstOrDefault().AgentId; result.MAWB = MAList.FirstOrDefault().MAWB; dbContext.TradelaneShipments.Add(result); dbContext.SaveChanges(); foreach (var MAAllocation in MAList) { TimeZoneModal TZM = new TimeZoneModal(); var Timezone = dbContext.Timezones.Where(a => a.TimezoneId == MAAllocation.TimezoneId).FirstOrDefault(); if (Timezone != null) { TZM.TimezoneId = Timezone.TimezoneId; TZM.Name = Timezone.Name; } var Res = dbContext.TradelaneShipmentAllocations.Where(a => a.TradelaneShipmentAllocationId == MAAllocation.MawbAllocationId).FirstOrDefault(); if (Res != null) { Res.TradelaneShipmentId = MAAllocation.TradelaneId; Res.AgentId = MAAllocation.AgentId; Res.AirlineId = MAAllocation.AirlineId; Res.CreatedBy = MAAllocation.CreatedBy; Res.TimezoneId = MAAllocation.TimezoneId; Res.EstimatedDateofArrival = MAAllocation.ETA != null && MAAllocation.ETA.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(MAAllocation.ETATime, MAAllocation.ETA.Value, TZM) : (DateTime?)null; Res.EstimatedDateofDelivery = MAAllocation.ETD != null && MAAllocation.ETD.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(MAAllocation.ETDTime, MAAllocation.ETD.Value, TZM) : (DateTime?)null; Res.FlightNumber = MAAllocation.FlightNumber; Res.LegNum = MAAllocation.LegNum; Res.MAWB = MAAllocation.MAWB; dbContext.Entry(Res).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); if (Res.TradelaneShipmentId > 0 && !string.IsNullOrEmpty(Res.MAWB)) { new TradelaneBookingRepository().SaveTradelaneMawb(Res.MAWB, (int)Res.TradelaneShipmentId); } } else { TradelaneShipmentAllocation TSA = new TradelaneShipmentAllocation(); TSA.TradelaneShipmentId = MAAllocation.TradelaneId; TSA.AgentId = MAAllocation.AgentId; TSA.AirlineId = MAAllocation.AirlineId; TSA.CreatedBy = MAAllocation.CreatedBy; TSA.TimezoneId = MAAllocation.TimezoneId; TSA.CreatedOnUTC = DateTime.UtcNow; TSA.EstimatedDateofArrival = MAAllocation.ETA != null && MAAllocation.ETA.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(MAAllocation.ETATime, MAAllocation.ETA.Value, TZM) : (DateTime?)null; TSA.EstimatedDateofDelivery = MAAllocation.ETD != null && MAAllocation.ETD.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(MAAllocation.ETDTime, MAAllocation.ETD.Value, TZM) : (DateTime?)null; TSA.FlightNumber = MAAllocation.FlightNumber; TSA.LegNum = MAAllocation.LegNum; TSA.MAWB = MAAllocation.MAWB; dbContext.TradelaneShipmentAllocations.Add(TSA); dbContext.SaveChanges(); if (TSA.TradelaneShipmentId > 0 && !string.IsNullOrEmpty(TSA.MAWB)) { new TradelaneBookingRepository().SaveTradelaneMawb(TSA.MAWB, (int)TSA.TradelaneShipmentId); } } } MAM.Status = true; } if (Result.ShipmentHandlerMethodId == 5) { if (MAList.FirstOrDefault().AgentId > 0) { SendMailtoAgent(MAList.FirstOrDefault(), MAList.FirstOrDefault().AgentId, MAList.FirstOrDefault().TradelaneId, FilePath); } if (MAList.Skip(1).FirstOrDefault().AgentId > 0) { SendMailtoAgent(MAList.Skip(1).FirstOrDefault(), MAList.Skip(1).FirstOrDefault().AgentId, MAList.Skip(1).FirstOrDefault().TradelaneId, FilePath); } } else { if (MAList.FirstOrDefault().AgentId > 0) { SendMailtoAgent(MAList.FirstOrDefault(), MAList.FirstOrDefault().AgentId, MAList.FirstOrDefault().TradelaneId, FilePath); } } if (MAM.Status && ShipmentType == "Tradelane") { new TradelaneBookingRepository().SaveIsAgentMawbAllocationDocument(MAList.FirstOrDefault().TradelaneId); } return(MAM); } else { MAM.Status = false; return(MAM); } }
public FrayteResult SaveMawbDetail(TradelaneMAWBDetail mawbDetail) { FrayteResult result = new FrayteResult(); try { if (mawbDetail.List.Count > 0) { var Allocation = dbContext.TradelaneShipmentAllocations.Find(mawbDetail.List[0].MawbAllocationId); if (Allocation != null && (string.IsNullOrEmpty(Allocation.LegNum) || Allocation.LegNum == "Leg1")) { var shipment = dbContext.TradelaneShipments.Find(mawbDetail.TradelaneShipmentId); shipment.MAWB = mawbDetail.MAWB; dbContext.SaveChanges(); if (!string.IsNullOrEmpty(shipment.MAWB)) { new TradelaneBookingRepository().SaveTradelaneMawb(shipment.MAWB, shipment.TradelaneShipmentId); } } } foreach (var item in mawbDetail.List) { var Timezone = dbContext.Timezones.Where(a => a.TimezoneId == item.TimezoneId).FirstOrDefault(); TimeZoneModal TZM = new TimeZoneModal(); if (Timezone != null) { TZM.TimezoneId = Timezone.TimezoneId; TZM.Name = Timezone.Name; } var Allocation = dbContext.TradelaneShipmentAllocations.Where(a => a.TradelaneShipmentAllocationId == item.MawbAllocationId).FirstOrDefault(); if (Allocation != null) { Allocation.AirlineId = item.AirlineId; Allocation.TimezoneId = item.TimezoneId; Allocation.EstimatedDateofArrival = item.ETA != null && item.ETA.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(item.ETATime, item.ETA.Value, TZM) : (DateTime?)null; Allocation.EstimatedDateofDelivery = item.ETD != null && item.ETD.Value.Year != 1 ? UtilityRepository.ConvertToUniversalTimeWitDate(item.ETDTime, item.ETD.Value, TZM) : (DateTime?)null; Allocation.FlightNumber = item.FlightNumber; Allocation.MAWB = mawbDetail.MAWB; Allocation.CreatedBy = mawbDetail.AgentId; dbContext.Entry(Allocation).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); if (!string.IsNullOrEmpty(Allocation.MAWB)) { new TradelaneBookingRepository().SaveTradelaneMawb(Allocation.MAWB, (int)Allocation.TradelaneShipmentId); } } } result.Status = true; } catch (Exception ex) { result.Status = false; } return(result); }