public static void AddDialCode(DialCodeDto pDialCode) { using (var _db = new Rbr_Db()) { using (var _tx = new Transaction(_db, pDialCode)) { CallingPlanManager.AddDialCode(_db, pDialCode); _tx.Commit(); } } }
void importRouteDialCodes(RouteRecord pRouteRecord) { Host.ReportStatus(string.Format("Importing Dial Codes for Route: {0}", pRouteRecord.FullName)); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { int _countryId = getCountryId(_db, pRouteRecord.CountryName, pRouteRecord.CountryCode); int _routeId = getRouteId(_db, _countryId, pRouteRecord); int _indexDialCode = 0; foreach (long _dialCode in pRouteRecord.DialCodes.Values) { if (Host.CancellationPending) { throw new Exception("Import canceled"); } if (!_dialCode.ToString().StartsWith(pRouteRecord.CountryCode.ToString())) { throw new Exception(string.Format("Invalid Dial Code={0}, CCode={1}", _dialCode, pRouteRecord.CountryCode)); } var _dialCodeDto = new DialCodeDto(); _dialCodeDto.Code = _dialCode; _dialCodeDto.BaseRouteId = _routeId; _dialCodeDto.CallingPlanId = args.CallingPlanId; _dialCodeDto.Version = 0; try { CallingPlanManager.AddDialCode(_db, _dialCodeDto); } catch (Exception _ex) { TimokLogger.Instance.LogRbr(LogSeverity.Debug, "", string.Format("Error inserting dial code: {0}\r\n{1}", _dialCodeDto.Code, _ex)); } if (++_indexDialCode % 10 == 0) { Host.ReportProgress(_indexDialCode * 100 / pRouteRecord.DialCodes.Values.Count); } } Host.ReportStatus(string.Format("Imported total of {0} Dial Codes for Route: {1}", pRouteRecord.DialCodes.Values.Count, pRouteRecord.FullName)); _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); reportStatus(LogSeverity.Error, "DialPlanImporter.importRouteDialCodes", _ex.Message); throw; } } }