Пример #1
0
        public static Result SaveRatingHistoryEntries(IRatingHistoryEntry pRatingHistoryEntry, int[] pRatedRouteIds)
        {
            var _result = new Result(true, null);

            try {
                using (var _db = new Rbr_Db()) {
                    using (var _tx = new Transaction(_db, pRatingHistoryEntry, pRatedRouteIds)) {
                        foreach (int _routeId in pRatedRouteIds)
                        {
                            var _ratingHistoryEntry = (IRatingHistoryEntry)Cloner.Clone(pRatingHistoryEntry);
                            if (_routeId != pRatingHistoryEntry.RatedRouteId)                              //NOTE: not a leading route, set RouteId=one of the selected, and set RateInfoId=0
                            {
                                _ratingHistoryEntry.RatedRouteId = _routeId;
                                _ratingHistoryEntry.RateInfoId   = 0;
                            }

                            RatingManager.SaveRatingHistoryEntry(_db, _ratingHistoryEntry);

                            if (_routeId == pRatingHistoryEntry.RatedRouteId)                              //NOTE: this is the leading route, update sent ref on it
                            {
                                pRatingHistoryEntry = _ratingHistoryEntry;
                            }
                        }
                        _tx.Commit();
                    }
                }
            }
            catch (Exception _ex) {
                TimokLogger.Instance.LogRbr(LogSeverity.Error, "RateController.Save(2)", string.Format("Exception:\r\n{0}", _ex));
                _result = new Result(false, _ex.Message);
            }
            return(_result);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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;
                }
            }
        }