Example #1
0
        internal static void UpdateService(Rbr_Db pDb, ServiceDto pService)
        {
            if (pService.IsRatingEnabled)
            {
                //Update Service's Default RatingInfo
                //NOTE: DefaultRatingInfo is always created on Add, no metter is RatingEnabled or not
                RatingManager.UpdateRatingInfo(pDb, pService.DefaultRatingInfo);

                //check RatingInfo for all others WholesaleRoutes, if they have no RatingInfo - create it
                //if WholesaleRoute already have Rates, just leave it as is
                WholesaleRouteRow[] _wholesaleRouteRows = pDb.WholesaleRouteCollection.GetByService_id(pService.ServiceId);
                foreach (WholesaleRouteRow _wholesaleRouteRow in _wholesaleRouteRows)
                {
                    WholesaleRateHistoryRow[] _wholesaleRateHistoryRows = pDb.WholesaleRateHistoryCollection.GetByWholesale_route_id(_wholesaleRouteRow.Wholesale_route_id);
                    if (_wholesaleRateHistoryRows.Length == 0)
                    {
                        //route has no rates, create them using Default
                        RatingManager.AddDefaultRatingInfo(pDb, _wholesaleRouteRow.Wholesale_route_id, pService.DefaultRatingInfo, RouteType.Wholesale);
                    }
                }

                if (pService.PayphoneSurcharge != null)
                {
                    if (pService.PayphoneSurcharge.PayphoneSurchargeId == 0)
                    {
                        pService.PayphoneSurcharge.PayphoneSurchargeId = RetailAccountManager.AddPayphoneSurcharge(pDb, pService.PayphoneSurcharge);
                    }
                    else
                    {
                        RetailAccountManager.UpdatePayphoneSurcharge(pDb, pService);
                    }
                }
            }
            CustomerRouteManager.Update(pDb, pService.DefaultRoute);

            ServiceRow _serviceRow = mapToServiceRow(pService);

            Update(pDb, _serviceRow);
            //pDb.AddChangedObject(new ServiceKey(TxType.Delete, pService.ServiceId));

            ServiceRow _originalServiceRow = Get(pDb, pService.ServiceId);

            if (pService.PayphoneSurcharge == null && !_originalServiceRow.IsPayphone_surcharge_idNull)
            {
                pDb.PayphoneSurchargeCollection.DeleteByPrimaryKey(_originalServiceRow.Payphone_surcharge_id);
            }
        }