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);
        }
        public IHttpActionResult SaveMAWBdetail(TradelaneMAWBDetail mawbDetail)
        {
            try
            {
                new TradelaneBookingRepository().SaveSalesOrderNumber(mawbDetail.HAWBpackages);
                var result = new MawbAllocationRepository().SaveMawbDetail(mawbDetail);

                if (result.Status)
                {
                    result = new TradelaneBookingRepository().UpdateMAWBDetail(mawbDetail);
                    new TradelaneEmailRepository().MawbUpdateMail(mawbDetail.TradelaneShipmentId);
                    return(Ok(result));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
 public IHttpActionResult UpdateMAWBDetails(TradelaneMAWBDetail mawbDetail)
 {
     return(Ok());
 }
        public IHttpActionResult MAWBDetails(string action)
        {
            try
            {
                TradelaneMAWBDetail detail = new TradelaneMAWBDetail();

                var ads = WebUtility.UrlDecode(action);

                var wsdsd = UtilityRepository.Base64UrlDecode(ads);

                var dfd = UtilityRepository.Decrypt(wsdsd, EncriptionKey.PrivateKey);

                var InitialDetail = new TradelaneBookingRepository().GetDetailsFormString(dfd);

                if (InitialDetail != null && !string.IsNullOrEmpty(InitialDetail.FrayteNumber) &&
                    InitialDetail.AgentId > 0 && InitialDetail.ShipmentMethodHandlerId > 0 &&
                    (string.IsNullOrEmpty(InitialDetail.Leg) || (!string.IsNullOrEmpty(InitialDetail.Leg) || InitialDetail.Leg == "Leg1" || InitialDetail.Leg == "Leg2")))
                {
                    int TradelaneShipmentId = new TradelaneBookingRepository().ValidateMAWBInitial(InitialDetail);

                    bool validAgent = false;
                    if (TradelaneShipmentId > 0)
                    {
                        if (InitialDetail.ShipmentMethodHandlerId != 5)
                        {
                            validAgent = new TradelaneBookingRepository().ValidateAgent(InitialDetail.AgentId, TradelaneShipmentId);
                        }
                        else
                        {
                            validAgent = new TradelaneBookingRepository().ValidateAgent(InitialDetail.AgentId, TradelaneShipmentId, InitialDetail.Leg);
                        }

                        if (validAgent)
                        {
                            bool status = new TradelaneBookingRepository().IsMAWBUploaded(TradelaneShipmentId, InitialDetail.AgentId, InitialDetail.Leg);

                            detail.FrayteNumber        = InitialDetail.FrayteNumber;
                            detail.AgentId             = InitialDetail.AgentId;
                            detail.TradelaneShipmentId = TradelaneShipmentId;
                            detail.HAWBpackages        = GetGroupedHAWBPieces(TradelaneShipmentId);
                            detail.List            = new MawbAllocationRepository().GetMawbAllocation(TradelaneShipmentId, InitialDetail.Leg);
                            detail.IsMAWBAllocated = status;
                            return(Ok(detail));
                        }
                        else
                        {
                            return(BadRequest("SessionExpired"));
                        }
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }