コード例 #1
0
        public FratyteError SendMawbAllocationMail(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)
                {
                    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);
                        }
                    }
                }
                else
                {
                    TradelaneShipment result = new TradelaneShipment();
                    result.MAWBAgentId = MAList.FirstOrDefault().AgentId;
                    result.MAWB        = MAList.FirstOrDefault().MAWB;
                    dbContext.TradelaneShipments.Add(result);
                    dbContext.SaveChanges();
                    MAM.Status = true;
                }
                return(MAM);
            }
            else
            {
                MAM.Status = false;
                return(MAM);
            }
        }
コード例 #2
0
        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);
            }
        }