public int SaveMileStone(TrackingMileStoneModel TMSM) { var result = dbContext.TrackingMileStones.Where(a => a.TrackingMileStoneId == TMSM.TrackingMileStoneId).FirstOrDefault(); var ShipHandelCount = dbContext.TrackingMileStones.Where(a => a.ShipmentHandlerMethodId == TMSM.ShipmentHandlerMethodId).ToList(); if (result == null) { TrackingMileStone TMS = new TrackingMileStone(); TMS.MileStoneKey = TMSM.MileStoneKey; TMS.Description = TMSM.Description; TMS.OrderNumber = TMSM.OrderNumber; TMS.ShipmentHandlerMethodId = TMSM.ShipmentHandlerMethodId; TMS.CreatedBy = TMSM.CreatedBy; TMS.CreatedOnUtc = DateTime.UtcNow; TMS.UpdatedBy = TMSM.UpdatedBy; TMS.UpdatedOnUtc = DateTime.UtcNow; dbContext.TrackingMileStones.Add(TMS); dbContext.SaveChanges(); SetOrderAddEdit(TMS); return(TMS.TrackingMileStoneId); } else { result.MileStoneKey = TMSM.MileStoneKey; result.Description = TMSM.Description; result.OrderNumber = TMSM.OrderNumber; result.ShipmentHandlerMethodId = TMSM.ShipmentHandlerMethodId; result.UpdatedBy = TMSM.UpdatedBy; result.UpdatedOnUtc = DateTime.UtcNow; dbContext.Entry(result).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); SetOrderAddEdit(result); return(result.TrackingMileStoneId); } }
public FrayteResult DeleteSystemAlert(int systemAlertId) { FrayteResult result = new FrayteResult(); try { var systemAlert = dbContext.SystemAlerts.Find(systemAlertId); if (systemAlert != null) { systemAlert.IsActive = false; dbContext.Entry(systemAlert).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); result.Status = true; } else { result.Status = false; } } catch (Exception ex) { result.Status = false; } return(result); }
private void WorkingWeekDay(FrayteWeekDays frayteWeekDay) { WorkingWeekDay weekday; if (frayteWeekDay.WorkingWeekDayId > 0) { weekday = dbContext.WorkingWeekDays.Where(p => p.WorkingWeekDayId == frayteWeekDay.WorkingWeekDayId).FirstOrDefault(); if (weekday != null) { weekday.Description = frayteWeekDay.Description; if (frayteWeekDay.IsDefault) { var weekDays = dbContext.WorkingWeekDays.Where(p => p.IsDefault == true).ToList(); foreach (var data in weekDays) { data.IsDefault = false; dbContext.Entry(data).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } weekday.IsDefault = frayteWeekDay.IsDefault; dbContext.SaveChanges(); frayteWeekDay.WorkingWeekDayId = weekday.WorkingWeekDayId; } } else { weekday = new WorkingWeekDay(); weekday.Description = frayteWeekDay.Description; if (frayteWeekDay.IsDefault) { var weekDays = dbContext.WorkingWeekDays.Where(p => p.IsDefault == true).ToList(); foreach (var data in weekDays) { data.IsDefault = false; dbContext.Entry(data).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } weekday.IsDefault = frayteWeekDay.IsDefault; dbContext.WorkingWeekDays.Add(weekday); if (weekday != null) { dbContext.SaveChanges(); } frayteWeekDay.WorkingWeekDayId = weekday.WorkingWeekDayId; } }
public FrayteResult SetShipmentHSCode(int eCommerceShipmentDetailid, string HSCode) { FrayteResult result = new FrayteResult(); try { if (eCommerceShipmentDetailid > 0) { var data = dbContext.eCommerceShipmentDetails.Find(eCommerceShipmentDetailid); if (data != null) { data.HSCode = HSCode; dbContext.Entry(data).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); result.Status = true; } else { result.Status = false; } try { var shipDetail = dbContext.eCommerceShipmentDetails .Where(p => p.eCommerceShipmentId == data.eCommerceShipmentId && !string.IsNullOrEmpty(p.HSCode)).ToList(); if (shipDetail == null || (shipDetail != null || shipDetail.Count == 0)) { var ship = dbContext.eCommerceShipments.Find(data.eCommerceShipmentId); if (ship != null) { ship.MappedOn = DateTime.UtcNow; dbContext.Entry(ship).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } } catch (Exception ex) { } } } catch (Exception ex) { result.Status = false; } return(result); }
public void UpdateReportSettingDate(int CustomerPODSettingId, DateTime lastrun) { try { var rs = dbContext.CustomerSettings.Where(p => p.CustomerSettingId == CustomerPODSettingId).FirstOrDefault(); if (rs != null && rs.CustomerSettingId > 0) { rs.UpdatedOn = lastrun; dbContext.Entry(rs).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } catch (Exception ex) { } }
public FrayteResult AddEditHSCodeSetting(eCommerceSettingModel HSCodeDetail) { FrayteResult FR = new FrayteResult(); HSCode HSC = new HSCode(); var Result = dbContext.HSCodes.Where(a => a.HSCodeId == HSCodeDetail.HsCodeId).FirstOrDefault(); if (Result == null) { Mapper.CreateMap <eCommerceSettingModel, HSCode>(); AutoMapper.Mapper.Map(HSCodeDetail, HSC); dbContext.HSCodes.Add(HSC); dbContext.SaveChanges(); FR.Status = true; } else { Mapper.CreateMap <eCommerceSettingModel, HSCode>(); AutoMapper.Mapper.Map(HSCodeDetail, Result); dbContext.Entry(Result).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); FR.Status = true; } return(FR); }
public void EditThirPartyMatrix(List <FrayteThirdPartyMatrix> _party) { try { LogisticServiceThirdPartyMatrix tpm; if (_party != null && _party.Count > 0) { foreach (var pr in _party) { tpm = dbContext.LogisticServiceThirdPartyMatrices.Where(x => x.LogisticServiceThirdPartyMatrixId == pr.ThirdPartyMatrixId).FirstOrDefault(); if (tpm != null) { tpm.FromLogisticServiceZoneId = pr.FromZone.ZoneId; tpm.ToLogisticServiceZoneId = pr.ToZone.ZoneId; tpm.ApplyLogisticServiceZoneId = pr.ApplyZone.ZoneId; tpm.OperationZoneId = pr.OperationZone.OperationZoneId; dbContext.Entry(tpm).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } } } catch (Exception ex) { } }
public FrayteResult UpdateRates(System.Data.DataTable exceldata) { FrayteResult result = new FrayteResult(); try { int k = 0; foreach (DataRow shipmentdetail in exceldata.Rows) { if (k > 0) { for (int i = 0; i < exceldata.Columns.Count; i++) { var id = exceldata.Columns[i].ColumnName; var weightid = int.Parse(shipmentdetail.ItemArray[0].ToString()); if (i > 2) { var zoneid = int.Parse(id.ToString()); var dbRate = dbContext.LogisticServiceBaseRateCards.Where(p => p.LogisticServiceZoneId == zoneid && p.LogisticServiceWeightId == weightid).FirstOrDefault(); if (dbRate != null) { dbRate.LogisticRate = decimal.Parse(shipmentdetail.ItemArray[i].ToString()); dbContext.Entry(dbRate).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } else { LogisticServiceBaseRateCard rate = new LogisticServiceBaseRateCard(); rate.OperationZoneId = 2; rate.LogisticServiceZoneId = zoneid; rate.LogisticServiceWeightId = weightid; rate.LogisticServiceShipmentTypeId = 48; rate.LogisticServiceDimensionId = 0; rate.LogisticServiceCourierAccountId = 95; rate.LogisticRate = decimal.Parse(shipmentdetail.ItemArray[i].ToString()); rate.LogisticCurrency = "GBP"; rate.ModuleType = "DirectBooking"; dbContext.LogisticServiceBaseRateCards.Add(rate); if (rate != null) { dbContext.SaveChanges(); } } } } } k++; } result.Status = true; return(result); } catch (Exception ex) { result.Status = false; return(result); } }
public FrayteResult MawbCorrection(TradelaneClaimShipmentModel CorrectionModel) { FrayteResult FR = new FrayteResult(); FR.Status = false; var Res = new TradelaneEmailRepository().TradelaneEmailObj(CorrectionModel.TradelaneShipmentId); var MAList = dbContext.TradelaneShipmentAllocations.Where(a => a.TradelaneShipmentId == CorrectionModel.TradelaneShipmentId).ToList(); var File = GetLatestMawbDocuments(CorrectionModel.TradelaneShipmentId); if (Res.ShipmentDetail.ShipmentHandlerMethod.ShipmentHandlerMethodId == 5) { if (MAList.FirstOrDefault().AgentId > 0) { new TradelaneEmailRepository().SendMawbCorrectionShipment(MAList.FirstOrDefault(), CorrectionModel, File.FilePath); } if (MAList.Skip(1).FirstOrDefault().AgentId > 0) { new TradelaneEmailRepository().SendMawbCorrectionShipment(MAList.Skip(1).FirstOrDefault(), CorrectionModel, File.FilePath); } FR.Status = true; } else { if (MAList.FirstOrDefault().AgentId > 0) { new TradelaneEmailRepository().SendMawbCorrectionShipment(MAList.FirstOrDefault(), CorrectionModel, File.FilePath); } FR.Status = true; } if (FR.Status == true) { var Result = dbContext.TradelaneShipments.Where(a => a.TradelaneShipmentId == CorrectionModel.TradelaneShipmentId).FirstOrDefault(); if (Result != null) { Result.IsMawbCorrection = true; dbContext.Entry(Result).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } return(FR); }
public FrayteResult UpdateFuelSurCharge(List <FrayteFuelSurcharge> fuelSurCharge) { FrayteResult result = new FrayteResult(); try { if (fuelSurCharge != null && fuelSurCharge.Count > 0) { foreach (var data in fuelSurCharge) { foreach (var type in data.Type) { foreach (var month in type.MonthYear) { if (month.IsChange) { var fuel = dbcontext.FuelSurCharges.Find(month.FuelSurchargeId); if (fuel != null) { fuel.FrayteFuelPercent = month.FrayteFuelPercent; fuel.ExpryesFuelPercent = month.FrayteFuelPercent; fuel.DomesticFuelPercent = month.FrayteFuelPercent; fuel.RoadFuelSurcharge = month.FrayteFuelPercent; fuel.IsUpdated = true; fuel.UpdatedOn = DateTime.UtcNow; fuel.UpdatedBy = data.UpdatedBy; dbcontext.Entry(fuel).State = System.Data.Entity.EntityState.Modified; dbcontext.SaveChanges(); } } } } } result.Status = true; } } catch (Exception ex) { result.Status = false; } return(result); }
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); }
private ErrorMessage SetManifestStatus(string manifestBarcodeNumber) { ErrorMessage message = new ErrorMessage(); message.Values = new List <string>(); var manifestDetail = dbContext.Manifests.Where(p => p.BarCodeNumber == manifestBarcodeNumber).FirstOrDefault(); if (manifestDetail != null) { manifestDetail.Status = eCommerceAppManifestTracking.Tracking1; dbContext.Entry(manifestDetail).State = EntityState.Modified; dbContext.SaveChanges(); } else { message.Key = manifestBarcodeNumber; message.Values.Add(eCommerceAppErrorMessage.InvalidBarcode); } return(message); }
public FrayteResult RemoveAssociateCustomer(int CustomerStaffDetailId) { FrayteResult result = new FrayteResult(); try { var detail = dbContext.CustomerStaffs.Where(p => p.CustomerStaffDetailId == CustomerStaffDetailId).FirstOrDefault(); if (detail != null) { detail.IsActive = false; dbContext.Entry(detail).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); result.Status = true; } return(result); } catch (Exception ex) { result.Status = false; return(result); } }
public FrayteResult SaveManifestTracking(List <ManifestTrackingModel> MTM) { FrayteResult FR = new FrayteResult(); try { foreach (var MT in MTM) { var EMT = dbContext.eCommerceTrackings.Where(a => a.eCommerceShipmentId == MT.eCommerceShipmentId).FirstOrDefault(); if (EMT == null) { eCommerceTracking EMTNew = new eCommerceTracking(); EMTNew.eCommerceShipmentId = MT.eCommerceShipmentId; EMTNew.FrayteNumber = MT.FrayteNo; EMTNew.TrackingDescription = MT.TrackingDescription; EMTNew.TrackingMode = MT.TrackingMode; EMTNew.TrackingNumber = MT.TrackingNo; EMTNew.TrackingDescriptionCode = MT.TrackingDescriptionCode; EMTNew.CreatedBy = MT.CreatedBy; EMTNew.CreatedOnUtc = MT.CreatedOnUtc; EMTNew.CreatedBy = MT.UserId; dbContext.eCommerceTrackings.Add(EMTNew); dbContext.SaveChanges(); } else { EMT.eCommerceShipmentId = MT.eCommerceShipmentId; EMT.FrayteNumber = MT.FrayteNo; EMT.TrackingDescription = MT.TrackingDescription; EMT.TrackingMode = MT.TrackingDescription; EMT.TrackingNumber = MT.TrackingNo; EMT.TrackingDescriptionCode = MT.TrackingDescriptionCode; EMT.CreatedBy = MT.CreatedBy; EMT.CreatedBy = MT.UserId; EMT.CreatedOnUtc = MT.CreatedOnUtc; dbContext.Entry(EMT).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } FR.Status = true; } catch (Exception e) { FR.Status = false; } return(FR); }
public FrayteResult SavePermissionToRole(AccessRoleModule accessRoleModule) { FrayteResult result = new FrayteResult(); try { if (accessRoleModule != null && accessRoleModule.ModuleLeveLId > 0) { List <RoleModule> list = new List <RoleModule>(); if (accessRoleModule.UpdateCase == ModuleLevelUpdateCase.RoleModuleLevel) { list = dbContext.RoleModules.Where(p => p.ModuleLevelId == accessRoleModule.ModuleLeveLId && p.RoleId == accessRoleModule.RoleId).ToList(); } else if (accessRoleModule.UpdateCase == ModuleLevelUpdateCase.RoleModuleDetailLevel) { list = dbContext.RoleModules.Where(p => p.ModuleLevelId == accessRoleModule.ModuleLeveLId && p.ModuleLevelDetailId == accessRoleModule.ModuleLeveLDetailId && p.RoleId == accessRoleModule.RoleId).ToList(); } if (list != null && list.Count > 0) { foreach (var data in list) { data.IsActive = accessRoleModule.IsActive; dbContext.Entry(data).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); result.Status = true; } } else { result.Status = false; } } else { result.Status = false; } } catch (Exception ex) { result.Status = false; } return(result); }
//public SkyPostalResponseModel CreateShipment(SkyPostalRequestModel skyPostalRequest, int DirectShipmentDraftId) //{ // SkyPostalResponseModel respone = new SkyPostalResponseModel(); // var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.SKYPOSTAL); // string result = string.Empty; // #region SKYPOSTaL API Login // skyPostalRequest.Key = logisticIntegration.InetgrationKey; // var skyPostalJson = Newtonsoft.Json.JsonConvert.SerializeObject(skyPostalRequest); // result = SkyPostalWebApi(logisticIntegration, skyPostalJson); // respone = Newtonsoft.Json.JsonConvert.DeserializeObject<SkyPostalResponseModel>(result); // respone.Rawrequest = skyPostalJson; // respone.Rawresponse = result; // if (respone.success > 0) // { // return respone; // } // else // { // var j1 = JObject.Parse(result); // var diff = j1["response"].ToList(); // respone.Error = new FratyteError(); // respone.Error.Service = new List<string>(); // string err = string.Empty; // foreach (var error1 in diff) // { // err = error1.ToString(); // var err1 = err.Replace("{", ""); // var err2 = err1.Replace("}", ""); // respone.Error.Service.Add(err2); // } // respone.Error.Status = false; // //Error Recorded // SaveDirectShipmentObject(skyPostalJson, respone.Error.Service.ToString(), DirectShipmentDraftId); // return respone; // } // #endregion //} private void SaveDirectShipmentObject(string ShipmetObject, string ShipmetErrorObject, int ShipmentDraftId) { try { var detail = dbContext.DirectShipmentDrafts.Find(ShipmentDraftId); if (detail != null) { detail.EasyPostOrderObject = ShipmetObject; detail.EasyPostErrorObject = ShipmetErrorObject; detail.LastUpdated = DateTime.UtcNow; dbContext.Entry(detail).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(ShipmetObject)); Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } }
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); }
public FrayteResult SetShipmentHSCode(int eCommerceShipmentDetailid, string hSCode, string Description, int HsCodeId) { FrayteResult result = new FrayteResult(); try { if (eCommerceShipmentDetailid > 0) { var data = dbContext.eCommerceShipmentDetails.Find(eCommerceShipmentDetailid); if (data != null) { data.HSCode = hSCode; //data.PiecesContent = Description; dbContext.Entry(data).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); result.Status = true; } else { result.Status = false; } var HscodeData = dbContext.HSCodes.Where(a => a.HSCodeId == HsCodeId).FirstOrDefault(); if (HscodeData != null) { HscodeData.Description = HscodeData.Description + ',' + data.PiecesContent; //data.PiecesContent = Description; dbContext.Entry(HscodeData).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); //result.Status = true; } //else //{ // result.Status = false; //} try { var shipDetail = dbContext.eCommerceShipmentDetails .Where(p => p.eCommerceShipmentId == data.eCommerceShipmentId && string.IsNullOrEmpty(p.HSCode)).ToList(); if (shipDetail == null || (shipDetail != null && shipDetail.Count == 0)) { var ship = dbContext.eCommerceShipments.Find(data.eCommerceShipmentId); if (ship != null) { ship.MappedOn = DateTime.UtcNow; dbContext.Entry(ship).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } } } catch (Exception ex) { result.Status = false; } return(result); }
public void SaveExchangeRate(List <FrayteExchangeRate> exchangeRate) { try { OperationZoneExchangeRate exRate; if (exchangeRate != null && exchangeRate.Count > 0) { foreach (var rr in exchangeRate) { if (rr.OperationZoneExchangeRateId > 0) { exRate = dbContext.OperationZoneExchangeRates.Find(rr.OperationZoneExchangeRateId); if (exRate != null) { exRate.OperationZoneId = rr.OperationZone.OperationZoneId; if (rr.IsActive) { exRate.ExchangeRate = rr.ExchangeRate; } else { exRate.ExchangeRate = 0; } exRate.IsActive = rr.IsActive; dbContext.Entry(exRate).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } //Insert ExchangeRate In History OperationZoneExchangeRateHistory hrate = new OperationZoneExchangeRateHistory(); hrate.OperationZoneId = rr.OperationZone.OperationZoneId; hrate.CurrencyCode = rr.CurrencyDetail.CurrencyCode; hrate.ExchangeRate = rr.ExchangeRate; hrate.ExchangeType = rr.ExchangeType; hrate.StartDate = DateTime.UtcNow.AddDays(-1); hrate.FinishDate = DateTime.UtcNow; dbContext.OperationZoneExchangeRateHistories.Add(hrate); dbContext.SaveChanges(); } else { exRate = dbContext.OperationZoneExchangeRates.Where(p => p.OperationZoneId == rr.OperationZone.OperationZoneId && p.CurrencyCode == rr.CurrencyDetail.CurrencyCode).FirstOrDefault(); if (exRate != null) { exRate.ExchangeRate = rr.IsActive ? rr.ExchangeRate : 0; exRate.IsActive = rr.IsActive; dbContext.SaveChanges(); } else if (rr.IsActive) { exRate = new OperationZoneExchangeRate(); exRate.OperationZoneId = rr.OperationZone.OperationZoneId; exRate.CurrencyCode = rr.CurrencyDetail.CurrencyCode; exRate.ExchangeRate = rr.ExchangeRate; exRate.ExchangeType = rr.ExchangeType; exRate.IsActive = true; dbContext.OperationZoneExchangeRates.Add(exRate); dbContext.SaveChanges(); } } } } } catch (Exception ex) { } }
public void AddCountryZone(FrayteZoneCountry zone) { try { if (zone != null) { //Step 1: Get the list of all the countries related to the zone from db. var list = (from zoneCount in dbContext.LogisticServiceZoneCountries where zoneCount.LogisticServiceZoneId == zone.ZoneId select zoneCount).ToList(); //Step 2: Remove Countries, for this need to find the country which is in db list but not in UI list var result = list.Where(p => !zone.Fraytezonezountry.Any(p2 => p2.CountryId == p.CountryId)).ToList(); foreach (var removeObj in result) { LogisticServiceZoneCountry removeData = dbContext.LogisticServiceZoneCountries.Where(p => p.CountryId == removeObj.CountryId && p.LogisticServiceZoneId == removeObj.LogisticServiceZoneId).FirstOrDefault(); if (removeData != null) { dbContext.LogisticServiceZoneCountries.Remove(removeData); dbContext.SaveChanges(); } } //Step 3: Add Countries, for this need to find the countries which is in UI list but not in db list var result1 = zone.Fraytezonezountry.Where(p => !list.Any(p2 => p2.CountryId == p.CountryId)).ToList(); foreach (var addObj in result1) { LogisticServiceZoneCountry newZoneCountry = new LogisticServiceZoneCountry(); newZoneCountry.LogisticServiceZoneId = zone.ZoneId; newZoneCountry.CountryId = addObj.CountryId; newZoneCountry.OperationZoneId = zone.OperationZoneId; newZoneCountry.TransitTime = addObj.TransitTime; dbContext.LogisticServiceZoneCountries.Add(newZoneCountry); dbContext.SaveChanges(); } //Step 4: Update Transit Time For Zone Country var transitlist = (from zoneCount in dbContext.LogisticServiceZoneCountries where zoneCount.LogisticServiceZoneId == zone.ZoneId select zoneCount).ToList(); if (transitlist.Count > 0) { int j = 0; foreach (var ll in transitlist) { if (ll.LogisticZoneCountryId > 0) { var transit = dbContext.LogisticServiceZoneCountries.Where(p => p.LogisticZoneCountryId == ll.LogisticZoneCountryId).FirstOrDefault(); if (transit != null) { transit.LogisticZoneCountryId = ll.LogisticZoneCountryId; transit.TransitTime = zone.Fraytezonezountry[j].TransitTime; dbContext.Entry(transit).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } j++; } } } } } catch (DbEntityValidationException ex) { foreach (var entityValidationErrors in ex.EntityValidationErrors) { foreach (var validationError in entityValidationErrors.ValidationErrors) { string ss = "Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage; } } } }
public FrayteResult AddZoneCountryPostCode(FrayteZoneCountryPostCode zonepostcode) { FrayteResult result = new FrayteResult(); try { if (zonepostcode != null) { int countryId = dbContext.Countries.Where(p => p.CountryName == zonepostcode.CountryName).Select(p => p.CountryId).FirstOrDefault(); if (countryId > 0) { if (zonepostcode.LogisticZoneCountryPostCodeId > 0) { var postcode = dbContext.LogisticZoneCountryPostCodes.Where(p => p.LogisticZoneCountryPostCodeId == zonepostcode.LogisticZoneCountryPostCodeId).FirstOrDefault(); if (postcode != null) { if (UtilityRepository.LogisticZoneCountryId(zonepostcode.OperationZoneId, countryId, zonepostcode.LogisticCompany, zonepostcode.LogisticType, zonepostcode.RateType, zonepostcode.Zone) > 0) { postcode.LogisticZoneCountryId = UtilityRepository.LogisticZoneCountryId(zonepostcode.OperationZoneId, countryId, zonepostcode.LogisticCompany, zonepostcode.LogisticType, zonepostcode.RateType, zonepostcode.Zone); postcode.FromPostCode = zonepostcode.FromPostCode; postcode.ToPostCode = zonepostcode.ToPostCode; dbContext.Entry(postcode).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); result.Status = true; } else { if (postcode.FromPostCode == zonepostcode.FromPostCode && postcode.ToPostCode == zonepostcode.ToPostCode) { result.Status = false; } else { var servicezone = (from ls in dbContext.LogisticServices join lsz in dbContext.LogisticServiceZones on ls.LogisticServiceId equals lsz.LogisticServiceId where ls.OperationZoneId == zonepostcode.OperationZoneId && ls.LogisticCompany == zonepostcode.LogisticCompany && ls.LogisticType == zonepostcode.LogisticType && ls.RateType == (zonepostcode.RateType == null ? null : zonepostcode.RateType) && lsz.ZoneName == zonepostcode.Zone select new { lsz.LogisticServiceZoneId }).FirstOrDefault(); LogisticServiceZoneCountry lszc = new LogisticServiceZoneCountry(); lszc.OperationZoneId = zonepostcode.OperationZoneId; lszc.LogisticServiceZoneId = servicezone.LogisticServiceZoneId; lszc.CountryId = countryId; dbContext.LogisticServiceZoneCountries.Add(lszc); if (lszc != null) { dbContext.SaveChanges(); } LogisticZoneCountryPostCode lzcpc = new LogisticZoneCountryPostCode(); lzcpc.LogisticZoneCountryId = lszc.LogisticZoneCountryId; lzcpc.FromPostCode = zonepostcode.FromPostCode; lzcpc.ToPostCode = zonepostcode.ToPostCode; dbContext.LogisticZoneCountryPostCodes.Add(lzcpc); if (lzcpc != null) { dbContext.SaveChanges(); } result.Status = true; } } } } else { var servicezone = (from ls in dbContext.LogisticServices join lsz in dbContext.LogisticServiceZones on ls.LogisticServiceId equals lsz.LogisticServiceId join lszc in dbContext.LogisticServiceZoneCountries on lsz.LogisticServiceZoneId equals lszc.LogisticServiceZoneId where ls.OperationZoneId == zonepostcode.OperationZoneId && ls.LogisticCompany == zonepostcode.LogisticCompany && ls.LogisticType == zonepostcode.LogisticType && ls.RateType == (zonepostcode.RateType == null ? null : zonepostcode.RateType) && lsz.ZoneName == zonepostcode.Zone && lszc.CountryId == countryId select new { lszc.LogisticZoneCountryId }).FirstOrDefault(); if (servicezone != null) { LogisticZoneCountryPostCode lzcpc = new LogisticZoneCountryPostCode(); lzcpc.LogisticZoneCountryId = servicezone.LogisticZoneCountryId; lzcpc.FromPostCode = zonepostcode.FromPostCode; lzcpc.ToPostCode = zonepostcode.ToPostCode; dbContext.LogisticZoneCountryPostCodes.Add(lzcpc); if (lzcpc != null) { dbContext.SaveChanges(); } result.Status = true; } else { LogisticServiceZoneCountry lszc = new LogisticServiceZoneCountry(); lszc.OperationZoneId = zonepostcode.OperationZoneId; lszc.LogisticServiceZoneId = UtilityRepository.LogisticServiceZoneId(zonepostcode.OperationZoneId, zonepostcode.LogisticCompany, zonepostcode.LogisticType, zonepostcode.RateType, zonepostcode.Zone); lszc.CountryId = countryId; dbContext.LogisticServiceZoneCountries.Add(lszc); if (lszc != null) { dbContext.SaveChanges(); } LogisticZoneCountryPostCode lzcpc = new LogisticZoneCountryPostCode(); lzcpc.LogisticZoneCountryId = lszc.LogisticZoneCountryId; lzcpc.FromPostCode = zonepostcode.FromPostCode; lzcpc.ToPostCode = zonepostcode.ToPostCode; dbContext.LogisticZoneCountryPostCodes.Add(lzcpc); if (lzcpc != null) { dbContext.SaveChanges(); } result.Status = true; } } } } return(result); } catch (Exception ex) { return(result); } }
public void GetMainfestData(DateTime ShipmentDate, TimeSpan FromTime, TimeSpan ToTime) { var GetCustomer = (from ECS in dbContext.eCommerceShipments where ECS.EstimatedDateofDelivery <= ShipmentDate && ECS.EstimatedTimeofDelivery <= FromTime && (ECS.IsManifested != true || ECS.IsManifested == null) select new { ECS.CustomerId, ECS.EstimatedDateofDelivery }).ToList(); var getCustomer = GetCustomer.Distinct(); var TimeZoneDetail = new TimeZoneModal(); foreach (var res in getCustomer) { TimeZoneDetail = (from ECS in dbContext.Users join Tmz in dbContext.Timezones on ECS.TimezoneId equals Tmz.TimezoneId where ECS.UserId == res.CustomerId select new TimeZoneModal { TimezoneId = Tmz.TimezoneId, Name = Tmz.Name, Offset = Tmz.Offset, OffsetShort = Tmz.OffsetShort }).FirstOrDefault(); } Logger _log = Get_Log(); var FromDateBeforeDayLightTime = new DateTime(2017, 03, 10, 07, 00, 00, DateTimeKind.Utc); var FromDateAfterDaylightTime = new DateTime(2017, 04, 14, 07, 00, 00, DateTimeKind.Utc); var zzzz = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").GetUtcOffset(FromDateBeforeDayLightTime).TotalHours; var zzzz1 = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time").GetUtcOffset(FromDateBeforeDayLightTime).TotalHours; var GetTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); _log.Info("Error due to fuel sur charge and exchange rate"); var ServerTimeHour = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").GetUtcOffset(FromDateAfterDaylightTime).TotalHours; var OffsetTimeHour = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time").GetUtcOffset(FromDateAfterDaylightTime).TotalHours; // Daylight saving time in USA with TimezoneInfo Class var TimeZoneInformationHongKong = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time"); var TimeZoneInformationNewYork = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); var TimeZoneInformationHK = TimeZoneInfo.ConvertTime(FromDateBeforeDayLightTime, TimeZoneInformationHongKong); var DatebyUTCtoSelectedTimezone = TimeZoneInfo.ConvertTime(FromDateBeforeDayLightTime, TimeZoneInformationNewYork); var DatebyUTCtoSelectedTimezone1 = TimeZoneInfo.ConvertTime(FromDateAfterDaylightTime, TimeZoneInformationNewYork); var TimeZoneInformationHKinfo = TimeZoneInfo.ConvertTimeFromUtc(FromDateBeforeDayLightTime, TimeZoneInformationHongKong); var TimeZoneInformationHKinfoz = TimeZoneInfo.ConvertTimeFromUtc(FromDateAfterDaylightTime, TimeZoneInformationHongKong); var TimeZoneInformationNyinfo = TimeZoneInfo.ConvertTimeFromUtc(FromDateBeforeDayLightTime, TimeZoneInformationNewYork); var TimeZoneInformationNyinfoz = TimeZoneInfo.ConvertTimeFromUtc(FromDateAfterDaylightTime, TimeZoneInformationNewYork); _log.Info("Error due to fuel sur charge and exchange rate"); //_log.Error("From Date is" + FromDateAfterDaylightTime + " Us Time after daylight saving time adjustment" + AddHoursToServerTimeZone1); _log.Info("Error due to fuel sur charge and exchange rate"); _log.Error(FromTime.ToString()); _log.Info("Error due to fuel sur charge and exchange rate"); _log.Error(ToTime.ToString()); var Fromtime = new DateTime(2017, 01, 01, FromTime.Hours, FromTime.Minutes, FromTime.Seconds).ToUniversalTime().TimeOfDay; var Totime = new DateTime(2017, 01, 01, ToTime.Hours, ToTime.Minutes, ToTime.Seconds).ToUniversalTime().TimeOfDay; //Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(Fromtime.ToString())); //Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(Totime.ToString())); _log.Info("Error due to fuel sur charge and exchange rate"); _log.Error(Fromtime.ToString()); _log.Info("Error due to fuel sur charge and exchange rate"); _log.Error(Totime.ToString()); //var TmDetail = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(), TimeZoneInfo.Local); var ManifestData = (from ECS in dbContext.eCommerceShipments join EADF in dbContext.eCommerceShipmentAddresses on ECS.FromAddressId equals EADF.eCommerceShipmentAddressId join EADT in dbContext.eCommerceShipmentAddresses on ECS.ToAddressId equals EADT.eCommerceShipmentAddressId join PDD in dbContext.eCommerceShipmentDetails on ECS.eCommerceShipmentId equals PDD.eCommerceShipmentId join TN in dbContext.eCommercePackageTrackingDetails on PDD.eCommerceShipmentDetailId equals TN.eCommerceShipmentDetailId join TD in dbContext.eCommercePackageTrackingDetails on PDD.eCommerceShipmentDetailId equals TD.eCommerceShipmentDetailId join Cur in dbContext.CurrencyTypes on ECS.CurrencyCode equals Cur.CurrencyCode join Cun in dbContext.Countries on EADF.CountryId equals Cun.CountryId where ECS.EstimatedDateofDelivery.Value <= ShipmentDate && ECS.EstimatedTimeofDelivery.Value <= Fromtime && (ECS.IsManifested != true || ECS.IsManifested == null) select new FrayteManifestOnExcel { ECommerceShipmentId = ECS.eCommerceShipmentId, TrackingNumber = TN.TrackingNo, Reference = ECS.Reference1, InternalAccountNumber = PDD.eCommerceShipmentDetailId, ShipperName = EADF.ContactFirstName + " " + EADF.ContactLastName, ShipperAddress1 = EADF.Address1, ShipperAddress2 = EADF.Address2, ShipperCity = EADF.City, ShipperZip = EADF.Zip, ShipperState = EADF.State, ShipperPhoneNo = EADF.PhoneNo, ShipperEmail = EADF.Email, ShipperCountryCode = Cun.CountryName, ConsigneeName = EADT.ContactFirstName + " " + EADT.ContactLastName, ConsigneeAddress1 = EADT.Address1, ConsigneeAddress2 = EADT.Address2, ConsigneeCity = EADT.City, ConsigneeZip = EADT.Zip, ConsigneeState = EADT.State, ConsigneePhoneNo = EADT.PhoneNo, ConsigneeEmail = EADT.Email, ConsigneeCountryCode = Cun.CountryName, WeightUOM = ECS.PackageCaculatonType, Currency = Cur.CurrencyDescription, Pieces = PDD.CartoonValue, TotalWeight = PDD.Weight * PDD.CartoonValue, TotalValue = PDD.CartoonValue * PDD.DeclaredValue, Incoterms = "DDP", ItemDescription = ECS.ContentDescription, ItemHScodes = PDD.HSCode, ItemValue = PDD.DeclaredValue, EstimatedDateofArrival = ECS.EstimatedDateofArrival, EstimatedTimeofArrival = ECS.EstimatedTimeofArrival, EstimatedDateofDelivery = ECS.EstimatedDateofDelivery, EstimatedTimeofDelivery = ECS.EstimatedTimeofDelivery }).ToList(); if (ManifestData.Count > 0) { // Send Mail before Creating Manifest var res = ManifestExcelWrite(ManifestData); // Send Mail before Creating Manifest // Make IsManifested Flag True if (res.Message == "True") { foreach (var a in ManifestData) { var result = dbContext.eCommerceShipments.Where(p => p.eCommerceShipmentId == a.ECommerceShipmentId).FirstOrDefault(); if (result != null) { result.IsManifested = true; dbContext.Entry(result).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } } } } else { Console.Write("There is no record to create custom manifest."); } //return ManifestData; }
public void SaveZonePostCode(FraytePostCodeUK _postcode) { try { LogisticServiceZonePostCode zpc; if (_postcode != null) { var result = dbContext.LogisticServiceZones.Where(a => a.LogisticServiceZoneId == _postcode.LogisticServiceZoneId).FirstOrDefault(); if (result != null) { result.TransitTime = _postcode.TransitTime; dbContext.Entry(result).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } if (_postcode.FrayteZonePostCodeList != null && _postcode.FrayteZonePostCodeList.Count > 0) { foreach (var code in _postcode.FrayteZonePostCodeList) { if (code.IsActive) { zpc = dbContext.LogisticServiceZonePostCodes.Where(x => x.LogisticServiceZonePostCodeId == code.ZonePostCodeId).FirstOrDefault(); if (zpc != null) { zpc = new LogisticServiceZonePostCode(); if (code.LogisticCompany == FrayteLogisticServiceType.DHL) { zpc.DHLLogisticServiceZoneId = code.PostCodeZone.ZoneId; } else if (code.LogisticCompany == FrayteLogisticServiceType.UkMail) { zpc.UKMailLogisticServiceZoneId = code.PostCodeZone.ZoneId; } else if (code.LogisticCompany == FrayteLogisticServiceType.Hermes) { zpc.HermesLogisticServiceZoneId = code.PostCodeZone.ZoneId; } else if (code.LogisticCompany == FrayteLogisticServiceType.Yodel) { zpc.YodelLogisticServiceZoneId = code.PostCodeZone.ZoneId; } zpc.PostCode = code.PostCode; dbContext.Entry(code).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } else { zpc = new LogisticServiceZonePostCode(); if (code.LogisticCompany == FrayteLogisticServiceType.DHL) { zpc.DHLLogisticServiceZoneId = code.PostCodeZone.ZoneId; } else if (code.LogisticCompany == FrayteLogisticServiceType.UkMail) { zpc.UKMailLogisticServiceZoneId = code.PostCodeZone.ZoneId; } else if (code.LogisticCompany == FrayteLogisticServiceType.Hermes) { zpc.HermesLogisticServiceZoneId = code.PostCodeZone.ZoneId; } else if (code.LogisticCompany == FrayteLogisticServiceType.Yodel) { zpc.YodelLogisticServiceZoneId = code.PostCodeZone.ZoneId; } zpc.PostCode = code.PostCode; dbContext.LogisticServiceZonePostCodes.Add(zpc); dbContext.SaveChanges(); } } else { zpc = dbContext.LogisticServiceZonePostCodes.Where(p => p.PostCode == code.PostCode).FirstOrDefault(); if (zpc != null) { dbContext.LogisticServiceZonePostCodes.Remove(zpc); dbContext.SaveChanges(); } } } } } } catch (DbEntityValidationException ex) { foreach (var entityValidationErrors in ex.EntityValidationErrors) { foreach (var validationError in entityValidationErrors.ValidationErrors) { string ss = "Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage; } } } }