Exemple #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);
        }
Exemple #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);
        }
Exemple #3
0
        public static Result DeleteRatingHistoryEntry(IRatingHistoryEntry pRatingHistoryEntry)
        {
            Result _result = new Result(true, null);

            try {
                using (Rbr_Db _db = new Rbr_Db()) {
                    using (Transaction _tx = new Transaction(_db, pRatingHistoryEntry)) {
                        //NOTE: NO physical DELETE, just set Rates to 0
                        pRatingHistoryEntry.RatingInfo.ClearRates();
                        RatingManager.UpdateRatingInfo(_db, pRatingHistoryEntry.RatingInfo);
                        _tx.Commit();
                    }
                }
            }
            catch (Exception _ex) {
                TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RatingController.Delete", string.Format("Exception:\r\n{0}", _ex));
                _result = new Result(false, _ex.Message);
            }
            return(_result);
        }