//public static RatingInfoDto[] GetRates(short pAcctId, int pCountryId, RouteType pRouteType, DateTime pDate) { // using (var _db = new Rbr_Db()) { // if (pRouteType == RouteType.Carrier) { // throw new NotImplementedException(); // } // if (pRouteType == RouteType.Wholesale) { // return getWholesaleRates(_db, pAcctId, pRouteType, pCountryId, pDate); // } // //else if (pRouteType == RouteType.Retail) { // // //TODO: // //} // throw new ArgumentException(string.Format("UNSUPPORTED Type : {0}", pRouteType), "pRouteType"); // } //} public static RatingHistoryEntry GetNewRatingHistoryEntry(int pRatedRouteId, RouteType pRouteType) { using (var _db = new Rbr_Db()) { RatedRouteDto _route = null; if (pRouteType == RouteType.Carrier) { _route = CarrierRouteManager.Get(_db, pRatedRouteId); } else if (pRouteType == RouteType.Wholesale) { _route = CustomerRouteManager.Get(_db, pRatedRouteId); } else if (pRouteType == RouteType.Retail) { } if (_route != null) { var _ratingInfo = _route.DefaultRatingInfo.Clone(); if (_ratingInfo != null) { var _ratingHistoryEntry = new RatingHistoryEntry(pRouteType, pRatedRouteId, DateTime.Today, Configuration.Instance.Db.SqlSmallDateTimeMaxValue, _ratingInfo.Clone()); _ratingHistoryEntry.HasChanged = true; return(_ratingHistoryEntry); } } return(null); } }
public static Result UpdateRatingHistoryEntry(IRatingHistoryEntry pRatingHistoryEntry, RouteType pRouteType) { Result _result = new Result(true, null); try { using (Rbr_Db _db = new Rbr_Db()) { using (Transaction _tx = new Transaction(_db, pRatingHistoryEntry)) { RatingHistoryEntry[] _ratingHistoryEntries = RatingManager.GetRatingHistoryEntries(_db, pRatingHistoryEntry.RatedRouteId, pRouteType); if (_ratingHistoryEntries == null || _ratingHistoryEntries.Length == 0) { return(new Result(false, "Error saving Rates, no RatingHistoryEntries found.")); } RatingHistoryEntry _ratingHistoryEntry = null; foreach (RatingHistoryEntry _rate in _ratingHistoryEntries) { if (_rate.RateInfoId == pRatingHistoryEntry.RateInfoId) { _ratingHistoryEntry = _rate; break; } } if (_ratingHistoryEntry == null) { return(new Result(false, "Error saving Rates, matching RatingHistoryEntry not found.")); } if (pRatingHistoryEntry.RatingInfo.RegularDayRateEntry != null) { _ratingHistoryEntry.RatingInfo.RegularDayRateEntry = pRatingHistoryEntry.RatingInfo.RegularDayRateEntry; _ratingHistoryEntry.FirstDate = pRatingHistoryEntry.FirstDate; _ratingHistoryEntry.LastDate = pRatingHistoryEntry.LastDate; } if (pRatingHistoryEntry.RatingInfo.WeekendRateEntry != null) { _ratingHistoryEntry.RatingInfo.WeekendRateEntry = pRatingHistoryEntry.RatingInfo.WeekendRateEntry; _ratingHistoryEntry.FirstDate = pRatingHistoryEntry.FirstDate; _ratingHistoryEntry.LastDate = pRatingHistoryEntry.LastDate; } if (pRatingHistoryEntry.RatingInfo.HolidayRateEntry != null) { _ratingHistoryEntry.RatingInfo.HolidayRateEntry = pRatingHistoryEntry.RatingInfo.HolidayRateEntry; _ratingHistoryEntry.FirstDate = pRatingHistoryEntry.FirstDate; _ratingHistoryEntry.LastDate = pRatingHistoryEntry.LastDate; } _ratingHistoryEntry.RateInfoId = 0; RatingManager.SaveRatingHistoryEntry(_db, _ratingHistoryEntry); _tx.Commit(); } } } catch (Exception _ex) { TimokLogger.Instance.LogRbr(LogSeverity.Error, "RateController.Save(1)", string.Format("Exception:\r\n{0}", _ex)); _result = new Result(false, _ex.Message); } return(_result); }
void importRouteRates(RouteRecord pRouteRecord) //}, int pCallingPlanId, short pId, RouteType pRouteType, int pRoutingPlanId) { { if (pRouteRecord.RatingInfo == null) { throw new Exception(string.Format("ERROR: No Rating Info found for Route={0}", pRouteRecord.FullName)); } reportStatus(LogSeverity.Status, "DialPlanImporter.importRouteRates", string.Format("Importing Route={0}", pRouteRecord.FullName)); using (var _db = new Rbr_Db()) { _db.BeginTransaction(); try { //-- get base RouteRow var _routeRow = RoutingManager.GetByName(_db, args.CallingPlanId, pRouteRecord.FullName); if (_routeRow == null) { reportStatus(LogSeverity.Status, "DialPlanImporter.importRouteRates", string.Format("SKIPPING: Route={0}, doesn't exists in CallingPlan={1}.", pRouteRecord.FullName, args.CallingPlanId)); return; } var _routeType = getRouteType(); int _rateRouteId = getBaseRouteId(_db, _routeType, args.AccountId, args.RoutingPlanId, _routeRow.Route_id); //-- Expects that imported file has records for Routes whose rates are changing only. //-- If the rate import record for existing Route is missing; Route is skipped //-- If the route record is not found we create a new record and add rates to it //-- Add/Update ratingHistory: default time period today, maxTime used var _ratingHistoryEntry = new RatingHistoryEntry(_routeType, _rateRouteId, args.From, args.To, pRouteRecord.RatingInfo); RatingManager.SaveRatingHistoryEntry(_db, _ratingHistoryEntry); _db.CommitTransaction(); } catch (Exception _ex) { _db.RollbackTransaction(); reportStatus(LogSeverity.Error, "DialPlanImporter.importRouteRates", _ex.Message); throw; } } }