From a0a797f9b859198af09531f6dbeacf6800385392 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 26 Jul 2016 16:29:20 +0300 Subject: [PATCH] Ticket 37. The switch case construction for changePolicy checking added in the ProcessNewMonth() function. --- projects/stargazer/user_impl.cpp | 42 +++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 5d505307..afd70b60 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -1181,7 +1181,47 @@ if (nextTariff.ConstData() != "") WriteServLog("Cannot change tariff for user %s. Tariff %s not exist.", login.c_str(), property.tariffName.Get().c_str()); else - property.tariffName.Set(nextTariff, sysAdmin, login, store); + { + switch (tariff->GetChangePolicy()) + { + case TARIFF::ALLOW: + { + property.tariffName.Set(nextTariff, sysAdmin, login, store); + break; + } + case TARIFF::TO_CHEAP: + { + if (nt->GetFee() < tariff->GetFee()) + property.tariffName.Set(nextTariff, sysAdmin, login, store); + else + WriteServLog("Tariff change is prohibited for user %s due to the policy %s. Current tariff %s is more cheap than new tariff %s.", + login.c_str(), + TARIFF::ChangePolicyToString(tariff->GetChangePolicy()).c_str(), + property.tariffName.Get().c_str(), + property.nextTariff.Get().c_str()); + break; + } + case TARIFF::TO_EXPENSIVE: + { + if (nt->GetFee() > tariff->GetFee()) + property.tariffName.Set(nextTariff, sysAdmin, login, store); + else + WriteServLog("Tariff change is prohibited for user %s due to the policy %s. Current tariff %s is more expensive than new tariff %s.", + login.c_str(), + TARIFF::ChangePolicyToString(tariff->GetChangePolicy()).c_str(), + property.tariffName.Get().c_str(), + property.nextTariff.Get().c_str()); + break; + } + case TARIFF::DENY: + { + WriteServLog("Tariff change is prohibited for user %s. Tariff %s.", + login.c_str(), + property.tariffName.Get().c_str()); + break; + } + } + } ResetNextTariff(); WriteConf(); } -- 2.43.2